いろいろ条件付きのドア

要件

  1. ボタンの仕掛けを2つ設置する(A, B)
  2. ボタンAは3回押すとボタンAが無効になる
  3. ボタンBは2回起動するとボタンBが無効になる
  4. ボリュームの仕掛けを設置する
  5. ドア付きの壁をフォートナイトのギャラリーから見つけて設置する
  6. ドアにくっ付くようにロックの仕掛けを設置する
    • ロックの仕掛けの中央部分が青く光ればドアとロックの仕掛けが紐づいている証拠!
  7. 「ボタンAを3回押した」かつ「ボタンBを2回押した」場合のみボリュームに入るとロックが解除される

必要なモノ

  1. ボタンの仕掛け(x2)
  2. ボリュームの仕掛け(x1)
  3. ドア付きの壁(x1)
  4. ロックの仕掛け(x1)

ヒント

今回は工程が多いので、上から順番に進めてみましょう。まずは、ボタンを3回押したら無効にさせるには…?

また、Print機能を活用して、現在の押した回数や、どこで処理が失敗しているか確認しながら進めるのもおすすめです!

回答

回答を見る
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

conditional_lock_device := class(creative_device):
    @editable
    ButtonDeviceA:button_device = button_device{}
    @editable
    ButtonDeviceB:button_device = button_device{}

    @editable
    VolumeDevice:volume_device = volume_device{}
    @editable
    LockDevice:lock_device = lock_device{}

    var ButtonAPressCount:int = 0
    var ButtonBPressCount:int = 0

    OnBegin<override>()<suspends>:void=
        ButtonDeviceA.InteractedWithEvent.Subscribe(OnInteractA)
        ButtonDeviceB.InteractedWithEvent.Subscribe(OnInteractB)

        VolumeDevice.AgentEntersEvent.Subscribe(OnEnter)

    OnInteractA(Agent:agent):void=
        set ButtonAPressCount += 1
        if(ButtonAPressCount = 3):
            ButtonDeviceA.Disable()

    OnInteractB(Agent:agent):void=
        set ButtonBPressCount += 1
        if(ButtonBPressCount = 2):
            ButtonDeviceB.Disable()

    OnEnter(Agent:agent):void=
        if(ButtonAPressCount = 3, ButtonBPressCount = 2):
            LockDevice.Unlock(Agent)