# This is a comment. Verse ignores lines starting with #. # Think of it as a sticky note for yourself. using { /Fortnite.com/Devices } using { /Fortnite.com/Game } using { /Verse.org/Simulation } using { /Verse.org/Random } using { /UnrealEngine.com/Temporary/Diagnostics } # We create a "Script" which is the container for our logic. # It's like creating a new folder for our island's brain. score_script := class(creative_device): # DEVICE REFERENCES: Wire these up in the UEFN Details panel. # ChaosButton is a button_device placed on the map. @editable ChaosButton : button_device = button_device{} # ScoreDisplay is a hud_message_device used to show the score. @editable ScoreDisplay : hud_message_device = hud_message_device{} # VARIABLES: These are our "containers." # var score : int means "score" is a mutable box that holds whole numbers. # It starts at 0. var score : int = 0 # OnBegin runs automatically when the game starts. # This is where we connect our events (plug in the wires). OnBegin() : void = # EVENTS: This connects our function to the real world. # We "subscribe" OnButtonClicked to the Button's InteractedWithEvent. # Think of this as plugging a wire from the Button to our Code. ChaosButton.InteractedWithEvent.Subscribe(OnButtonClicked) # FUNCTIONS: This is the "logic" for when the button is clicked. # button_device events pass the interacting agent as a parameter. OnButtonClicked(Agent : agent) : void = # This line is the magic. # We take the current score, add 1, and put it back in the box. set score = score + 1 # We need to update the visual display. # hud_message_device shows a message to all players. # note: hud_message_device has no SetText; we use Show() after # setting the message text in the Details panel, or print to log. Print("Score: {score}") # Optional: Let's make it fun! # If the score hits 5, let's trigger a random prop effect. if (score >= 5): SpawnRandomProp() # Helper Function: Triggers a random effect when score is 5+ SpawnRandomProp() : void = # We use a random integer in the range 0..99 RandomVal := GetRandomInt(0, 99) # If the random number is low, activate the chaos button's # visual pulse as a stand-in effect (device-side feedback). # note: actual runtime prop spawning requires a spawner_device # wired in the Details panel; use prop_spawner_device.Activate() # on an @editable prop_spawner_device for a real implementation. if (RandomVal < 20): ChaosButton.Enable()