Help with Verse Code

the following code is adapted from a great tutorial by Graeme Bull, although in his tutorial he only goes as far as the first function ‘OnLootBoxButton’… the and the custom loot box work fine in this regard.

When I tried to duplicate the loot box, I added ‘OnLootBoxButton2’ … for some reason when I trigger the first loot box the second one also triggers, despite being in a different location. If I try to go to the second loot box without triggering the first loot box I don’t even get the option to interact with the second loot box.

I am hoping that someone can help with this and explain to me what I am doing wrong…

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }

GameManager := class(creative_device):
@editable
PS1:player_spawner_device = player_spawner_device{}

@editable
LootBoxButton: button_device = button_device{}

@editable
LootBoxLid: creative_prop = creative_prop{}

@editable
LootGranter: item_granter_device = item_granter_device{}

@editable
VFX: vfx_spawner_device = vfx_spawner_device{}

@editable
LootBoxButton2: button_device = button_device{}

@editable
LootBoxLid2: creative_prop = creative_prop{}

@editable
LootGranter2: item_granter_device = item_granter_device{}

@editable
VFX2: vfx_spawner_device = vfx_spawner_device{}

OnBegin<override>()<suspends>:void=
    
    LootBoxButton.InteractedWithEvent.Subscribe(OnLootBoxButton)
    LootBoxButton2.InteractedWithEvent.Subscribe(OnLootBoxButton2)

OnLootBoxButton(Agent: agent): void=
    spawn:
        RotateBoxLid(Agent)
RotateBoxLid(Agent: agent)<suspends>:void=
    #disable the button
    LootBoxButton.Disable()
    loop: 
        LidTransform:transform = LootBoxLid.GetTransform()
        Rotation:rotation=LidTransform.Rotation
        LootBoxLid.MoveTo(LidTransform.Translation, Rotation.ApplyLocalRotationY(1.0), 0.5)
        NewRotation:rotation=LidTransform.Rotation
        YPR:= NewRotation.GetYawPitchRollDegrees()
        if(YPR[0] >= -90.0):
            LootGranter.GrantItem(Agent)
            VFX.Disable()
            break

OnLootBoxButton2(Agent: agent): void=
    spawn:
        RotateBoxLid2(Agent)
RotateBoxLid2(Agent: agent)<suspends>:void=
    #disable the button
    LootBoxButton2.Disable()
    loop: 
        LidTransform:transform = LootBoxLid2.GetTransform()
        Rotation:rotation=LidTransform.Rotation
        LootBoxLid2.MoveTo(LidTransform.Translation, Rotation.ApplyLocalRotationY(1.0), 0.5)
        NewRotation:rotation=LidTransform.Rotation
        YPR:= NewRotation.GetYawPitchRollDegrees()
        if(YPR[0] >= -90.0):
            LootGranter2.GrantItem(Agent)
            VFX.Disable()
            break

The problem is you are referencing (that is, getting) the Transform from the first box. You have to create new variable names because you are operating from a different location and everything is set to the Transform position, meaning it is relative to its own position. You have to do something like this. When you press the second button, it is probably merging instantly into the first. Try something like this;

OnLootBoxButton1(Agent1: agent): void=
spawn:
RotateBoxLid1(Agent1)

    RotateBoxLid1(Agent:agent)<suspends>:void=
                #disable the button
                Print("Button 2 pressed")
        loop: 
            LidTransform1:transform = LootBoxLid1.GetTransform()
            Rotation1:rotation=LidTransform1.Rotation
            LootBoxLid1.MoveTo(LidTransform1.Translation, Rotation1.ApplyWorldRotationY(1.0), 0.5)
            NewRotation1:rotation=LidTransform1.Rotation
            YPR1:= NewRotation1.GetYawPitchRollDegrees()
            if(YPR1[0] >= -90.0):
                Print("Success")
                       
            break

Thank you so much. I will give it a go. Your advice and help is very much appreciated.

I set it up exactly with the code you provided, and was stumped too. I didn’t use a loot box, just a platform. I didn’t figure out the issue until I saw the second platform jumping to the position of the first every time I pressed Button 2. Then I realized it had to do with the second platform reading the transform values of the first.