Doc Error] Variable Shadowing and undeclared identifier in Event Subscription example

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}

  1. Variable Shadowing: The line using := incorrectly creates a new local constant named ButtonSubscription, which shadows the existing class variable var ButtonSubscription:?cancelable = false.

  2. Undeclared Identifier: The subsequent set statement attempts to use a variable named Subscription, 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!