using { /Fortnite.com/Devices } using { /UnrealEngine.com/Temporary/Symbols } # This is our "Component" definition. # It tells the engine what data this script needs. ChaosButtonComponent := component ( # We need a reference to the world to spawn things World: world, # We need a reference to the transform (position/rotation) of this component Transform: transform, # A simple flag to know if the button was pressed ButtonPressed: bool = false ) # This is the main function. Think of it as the "Brain" of the component. # It runs every time the game checks in (or when we tell it to). main := func (component: ChaosButtonComponent) -> void: # Check if the button has been pressed # In a real device, we'd link this to an event, but for this demo, # we'll simulate a press via a simple trigger logic below. # If the button is pressed, we spawn a prop if component.ButtonPressed == true: # 1. Get the current position of the button CurrentLocation := component.Transform.GetLocation() # 2. Move it up by 200 units (so it doesn't spawn inside the button) SpawnLocation := CurrentLocation + vec(0, 0, 200) # 3. Pick a random prop type (Barrel, Crate, or Turret) # We use a random number generator to pick an index RandomChoice := rand(3) # 4. Based on the random choice, we "spawn" a simple visual block # Note: In a full game, you'd use SpawnActor, but for this simple # component demo, we'll just log it to the console to prove it works. # Real Verse requires more complex spawning logic, so let's keep it # simple: We'll just print a message. if RandomChoice == 0: print("Spawned a Barrel!") else if RandomChoice == 1: print("Spawned a Crate!") else: print("Spawned a Turret!") # Reset the flag so it doesn't spam forever component.ButtonPressed = false # This function is called when the button is physically pressed by a player. # This is the "Event" that connects to the device in the editor. OnButtonPressedEvent := func (event: button_pressed_event) -> void: # Find the component attached to this device # (In a real scenario, you'd pass the component reference here) # For this standalone example, we assume the component is active. # Set our variable to true # This tells the 'main' function to run the spawn logic next tick # Note: In actual UEFN, you'd use 'SetComponent' or similar APIs. # Here we demonstrate the concept of state change. print("Button Pressed! Chaos incoming...")