Verse Library verse

01 Fragment

Demonstrates updating a mutable health variable inside a trigger enter event for educational purposes.

verse-library/basics-of-writing-code-3-storing-and-using-information-in-verse/01-fragment.verse

# This is a comment. It helps us remember what the code does.

# We define a function that runs when the trigger is entered.
OnTriggerEnter := func(other_actor: Actor):
    # 'other_actor' is the player who walked in.

    # Let's find the player's health.
    # Note: In real UEFN, you might use a specific Health Component.
    # For this example, we will simulate a health variable.

    # Create a variable called 'current_health'.
    # It starts at 100. This is a mutable value.
    current_health := 100

    # Let's say the player gains 25 health.
    # We add 25 to the current health.
    current_health := current_health + 25

    # Now, 'current_health' holds 125.
    # In a real game, you would update the player's actual health here.
    # For now, we just print it to the screen to see it work.
    print("Player health is now: ", current_health)

Comments

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