VerseIsland
FeedLearnLeaderboardGuidesReferenceExploreSearchDocsVerse Library
Sign in
Feed Learn 📖 Codex Leaderboard Guides Reference Explore Search Docs Verse Library
Browse UEFN›Verse Language·Up to UEFN · Verse Language·61 of 123 in Verse Language

The Option Type In Verse

Option

The option type can contain one value or can be empty.

The option type can contain one value or can be empty.

In the following example, MaybeANumber is an optional integer ?int that contains no value. A new value for MaybeANumber is then set to 42.



|  | var MaybeANumber : ?int = false # unset optional value |
| --- | --- |
|  | set MaybeANumber := option{42} # assigned the value 42 |

Copy full snippet

Creating an option variable in Verse

| | | MaybeANumber : ?int = option{42} # initialized as 42 | | --- | --- | | | | | | MaybeAnotherNumber : ?int = false # unset optional value | Copy full snippet | Creating an option: You can initialize an option with one of the following: * No value: Assign false to the option to mark it as unset. * Initial value: Use the keyword option followed by {}, and an expression between the {}. If the expression fails, the option will be unset and have the value false. Specify the type by adding ? before the type of value expected to be stored in the option. For example ?int. | | --- | --- | --- | --- | --- | --- | --- | --- | | | | if (Number := MaybeANumber?): | | --- | --- | | | Number # if MaybeANumber is not empty, then its value is stored in Number for you to use. | Copy full snippet | Accessing an element in an option: Use the query operator ? with the option, such as MaybeANumber?. Accessing the value stored in an option is a failable expression because there might not be a value in the option, and so must be used in a failure context. |

You're reading a preview

The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.

Sign in with Discord — free for members Read the original at Epic Games documentation

Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.

Guided course

Add this to your free study plan — we’ll suggest related material and stitch it into one compile-checked lesson.

Keep exploring
More in Verse Language · 61 of 123
Prev
operators in verse
Next
parametric types in verse
Browse all files in this folder (A–Z)

Source

Epic Games documentation

View original

Last updated 2024-12-05T00:00:00+00:00

VerseIsland· an archipelago of Verse & UEFN knowledge
🗺️ Island atlasLearnGuidesHistoryAbout & PressSources & LicensingPrivacy PolicyTermsStatus

Not affiliated with Epic Games. Fortnite, UEFN, Unreal Engine, and Verse are trademarks of Epic Games, Inc. Content is attributed to its source — see Sources & Licensing.

🦜

Scout · your island guide

The Isle of Verse