Hi everyone,
While going through the official documentation for Coding Device Interactions in Verse, I noticed a logic and syntax error in the provided code snippet that will throw a compilation error and might confuse newcomers to the language.
Page URL: Coding Device Interactions in Verse | Fortnite Documentation | Epic Developer Community
The issue: In the spawner_button example, the subscription block contains two problems:
Extrait de code
OnBegin<override>()<suspends>:void=
ButtonSubscription := Button.InteractedWithEvent.Subscribe(OnButtonInteractedWith)
# Définir le résultat annulable comme valeur de la variable d'option.
set ButtonSubscription = option{Subscription}
-
Variable Shadowing: The line using
:=incorrectly creates a new local constant namedButtonSubscription, which shadows the existing class variablevar ButtonSubscription:?cancelable = false. -
Undeclared Identifier: The subsequent
setstatement attempts to use a variable namedSubscription, which has never been declared anywhere in the scope.
Suggested Fix: To keep the code clean and highly readable, the subscription logic should be explicitly split. First, store the event in a local constant, then assign it to the optional class variable using set:
Extrait de code
OnBegin<override>()<suspends>:void=
Subscription := Button.InteractedWithEvent.Subscribe(OnButtonInteractedWith)
set ButtonSubscription = option{Subscription}
Print("Subscribed to the Button's InteractedWithEvent and assigned the subscription to ButtonSubscription!")
Hope this helps get the docs updated!