Verse Library verse

01 Standalone

Links a button press to change a light prop color for interactive visual feedback.

verse-library/build-the-effect/01-standalone.verse

# This is our main script. It connects the button and light.
# We use 'transacts' because we will change the light's color.
# Changing a color is an effect we can undo.
MyScript := class():
    # This is our button. We find it by name.
    button: ButtonDevice = ButtonDevice.Find("MyButton")
    
    # This is our light prop. We find it by name.
    light: Prop = Prop.Find("MyLight")

    # This function runs when the button is pressed.
    # It has 'transacts' because it changes the light.
    OnButtonPressed := function():
        # We change the light's color to bright red.
        # This is the effect! The world changes.
        light.SetColor(RedColor)

# We listen for the button press.
# When the button is pressed, we run our function.
button.PressedEvent += function():
    MyScript.OnButtonPressed()

Comments

    Sign in to vote, comment, or suggest an edit. Sign in