Arrays (list button activate List props)

Hi @Starkiller9229
Thank you for your help

I changed the code to

OnBegin<override>()<suspends>:void=
        for (Index -> Button : ButtonList):
            Button.InteractedWithEvent.SubscribeAgent(OnButton, Index)

    OnButton(Agent : agent, ButtonIndex : int) : void=
        Prop := ItemList[ButtonIndex]
        spawn:
            SmoothRotate(Prop)

Then I got 2 errors:

Unknown member SubscribeAgent in listenable(agent).

This invocation calls a function that has the ‘decides’ effect, which is not allowed by its context. The ‘decides’ effect indicates that the invocation calls a function that might fail, and so must occur in a failure context that will handle the failure. Some examples of failure contexts are the condition clause of an ‘if’, the left operand of ‘or’, or the clause of the ‘logic’ macro.
spawn:
SmoothRotate(Prop)

i get error:
Unknown member SubscribeAgent in listenable(agent).

All Code:

itens_rotator := class(creative_device):
    @editable var Time : float = 3.0

    @editable var ItemList : []creative_prop = array{}

    @editable var ButtonList : []button_device = array{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        for (Index -> Button : ButtonList):
            Button.InteractedWithEvent.SubscribeAgent(OnButton, Index)

    OnButton(Agent : agent, ButtonIndex : int) : void=
        Prop := ItemList[ButtonIndex]
        spawn:
            SmoothRotate(Prop)

    SmoothRotate<private>(Prop: creative_prop)<suspends> : void=

        Transform := Prop.GetTransform()
        Position := Transform.Translation
        Rotation := Transform.Rotation
        NewRotation := Rotation.ApplyYaw(180.0)
        MoveResult := Prop.MoveTo(Position, NewRotation, Time)
        #suspende por 3 segundos
        if (MoveResult = move_to_result.DestinationReached):
            SmoothRotate(Prop)
1 Like