Verse Library verse

01 Functions And Function Calls

Demonstrates declaring mutable variables, generating random numbers, performing arithmetic, and printing values to the log.

extracted-snippets/documentation/en-us/uefn/learn-code-basics-5-writing-reusable-code-in-verse/01-functions-and-function-calls.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/learn-code-basics-5-writing-reusable-code-in-verse
# Local doc:  epic-docs/documentation/en-us/uefn/learn-code-basics-5-writing-reusable-code-in-verse.md
# Section:    Functions and Function Calls
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Random }

OnBegin<override>()<suspends> : void =
    # Initialize Coins to 500. Because it is a var, you can change it later.
    var Coins : int = 500

    # Initialize CoinsPerMousetrap with a random integer between 1 and 100
    CoinsPerMousetrap : int = GetRandomInt(1, 100)
    
    # Print the current value of Coins (500) to the log.
    Print("Coins starts at {Coins}.")

    # Decrease Coins by CoinsPerMousetrap, and print the new value to the log.
    set Coins = Coins - CoinsPerMousetrap
    Print("After buying one mousetrap, Coins is {Coins}.")
Copy full snippet

Comments

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