Results 1 to 6 of 6

Thread: If / else on sound effects

  1. #1

    Default If / else on sound effects

    G'day folks.

    I have a sliding gate that can be operated manually via "trigger_use" or automatically via either a scripted switch or button.
    It all works perfectly fine except for the sound effects always play when using the scripted switch whether the gate is already opened or closed.

    My question is how do I write an "If" / "else" statement so that the sound is only played if the gate is actually in the correct (open/closed) position to move?
    I'm looking for the correct method of saying "gate1 is open" or "gate1 is closed"
    Then the call "If gate1 is open".....
    Else it should skip the playsound line and continue with the rest of the thread.
    No need to close a gate that is already closed, right?

    I've looked at other scripts with the if / else statements but none are jumping at me as an obvious solution for my gates.

    Help in this would be much appreciated, thanks.

  2. #2
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Would you be able to post a part of your code. I'm more of a visual person so I might be able to assist if I have something to work with.

  3. #3

    Default

    G'day James,
    Yeah sure. Sorry I didn't stick around, I had visitors. :/

    Code:
    closecage1:
    	$cage1_close nottriggerable
    	$cage1 playsound shutgate
    	$cage1 moveto $closed1
    	$cage1 time 2
    	$cage1 waitmove
    	$cage1_trig triggerable
    end
    
    closecage2:
    	$cage2_close nottriggerable
    	$cage2 playsound shutgate
    	$cage2 moveto $closed2
    	$cage2 time 2
    	$cage2 waitmove
    	$cage2_trig triggerable
    end
    
    opencage1:
    	$cage1_trig nottriggerable
    	$cage1 playsound opengate
    	$cage1 moveto $opened1
    	$cage1 time 2
    	$cage1 waitmove
    	$cage1_close triggerable
    end
    
    opencage2:
    	$cage2_trig nottriggerable
    	$cage2 playsound opengate
    	$cage2 moveto $opened2
    	$cage2 time 2
    	$cage2 waitmove
    	$cage2_close triggerable
    end
    It's all part of an elevator that has the old fashion cage gate on each level and an automatic elevator door (which is bound to the lift) yet only the gate can be manually opened or closed.
    Both cage and door close automatically with the triggered buttons and the door opens automatically when the level is reached... but not the cage. I'd like to keep it like this.

    Thank you.

  4. #4

    Default

    Oops sorry, That's not where I will be putting it as they are the manual operations.

    Code:
    godown:
    	$down_trig nottriggerable
    	$cage1_trig nottriggerable
    	$cage2_close nottriggerable
    	$call1_trig nottriggerable
    	$cage2 playsound shutgate
    	$cage2 moveto $closed2
    	$cage2 time 2
    	$cage2 waitmove
    	$liftdoor playsound slidedoor
    	$liftdoor moveto $lvl2shut
    	$liftdoor time 2
    	$liftdoor waitmove
    	$liftdoor bind $lift
    	wait 1
    	$lift playsound elevator3
    	$lift moveto $level1
    	$lift time 3
    	$lift waitmove
    	$liftdoor unbind $lift
    	wait 1
    	$liftdoor playsound slidedoor
    	$liftdoor moveto $lvl1open
    	$liftdoor time 2
    	$liftdoor waitmove
    	$cage1_trig triggerable
    	$cage2_trig triggerable
    	$up_trig triggerable
    	$call2_trig triggerable
    end
    
    goup:
    	$up_trig nottriggerable
    	$cage2_trig nottriggerable
    	$cage1_close nottriggerable
    	$call2_trig nottriggerable
    	$basementswitch playsound alarm_switch
    	$basementswitch anim turnon
    	wait 1
    	$cage1 playsound shutgate
    	$cage1 moveto $closed1
    	$cage1 time 2
    	$cage1 waitmove
    	$liftdoor playsound slidedoor
    	$liftdoor moveto $lvl1shut
    	$liftdoor time 2
    	$liftdoor waitmove
    	$liftdoor bind $lift
    	wait 1
    	$lift playsound elevator3
    	$lift moveto $level2
    	$lift time 3
    	$lift waitmove
    	$liftdoor unbind $lift
    	wait 1
    	$liftdoor playsound slidedoor
    	$liftdoor moveto $lvl2open
    	$liftdoor time 2
    	$liftdoor waitmove
    	wait 1
    	$basementswitch playsound alarm_switch
    	$basementswitch anim turnoff
    	$cage2_trig triggerable
    	$down_trig triggerable
    	$cage1_trig triggerable
    	$call1_trig triggerable
    end

  5. #5

    Default

    You could assign a custom '.open' property to the gate entity


    $gate.open = 1;


    and then check that property to open/close the gate


    if ($gate.open) {
    // code to close the gate
    $gate.open = 0;
    } else {
    // code to open the gate
    $gate.open = 1;
    }

  6. #6

    Default

    Cheers mate, that's exactly what I was after and was going to write it as such but thought I'd blow up the PC or something if i attempted it. lol

    Much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •