Author Topic: How do I make an event turn on and off via a key-press like a toggle switch?  (Read 1108 times)

0 Members and 1 Guest are viewing this topic.

Offline Light

  • 24
How do I make an event turn on and off via a key-press like a toggle switch?
Is there a way to make an event toggle on and off via a key-press. That is I have one event that occurs via a key-press that is the ON event and a second event that occurs via another key-press is the OFF event. I can get them to cycle one time only. What I want is for the key-presses to reset so that I can cycle it on/off as many times as I want.

As a simple test example I can make my ship change from a Hercules Mk1 into a Hercules Mk2 by pressing the 1 key. I can then make it change from a Hercules Mk2 back into a Hercules Mk1 by pressing Shift-1. However it will only do that once. What I want is for it the reset so that if I press the 1 key again if will change again and likewise when Shift-1 is pressed. The events repeating upon key-press in perpetuity.

Any idea as to how to go about doing this?

I have attached the Class Change Test.fs2 file to the post that contains my above example.     

[attachment deleted by ninja]

  

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: How do I make an event turn on and off via a key-press like a toggle switch?
the 1 key is buggy. use alt-x
you can use the same key for both. It's stupid to use two keys when you can use one. Key combinations are at a premium, especially ones that work with toggle, and don't do anything else in singleplayer.

Shift-1 is used for strafing. (Slide, like Shivan fighters).

I'd only use 1,2,3,4 and Alt-X. (and maybe D, but I bind that to either Zoom, or Press To Glide)

Code: [Select]
$Formula: ( every-time
   ( key-pressed "Alt-X" 0 )
   ( if-then-else
      ( = @SwapStatus[0] 0 )
      ( when
         ( true )
         ( change-ship-class
            "GTF Hercules Mark II"
            "Alpha 1"
         )
         ( modify-variable @SwapStatus[0] 1 )
      )
      ( when
         ( true )
         ( change-ship-class
            "GTF Hercules"
            "Alpha 1"
         )
         ( modify-variable @SwapStatus[0] 0 )
      )
   )
   ( key-reset-multiple "Alt-X" )
)
+Name: SwapToggle
+Repeat Count: 1
+Interval: 1

EZ.
*based off the the cloaking toggle one (which just uses change-ship-class), minus all the extra fluff since you don't need delays/transitions :P) thanks to mjnmixael

if you're ADAMANT on using the 1 key you're going to need something like

Code: [Select]
   ( and
      ( key-pressed "1" 0 )
      ( > ( mission-time-msecs ) @ZWait[-1] )
   )
   ( modify-variable
      @ZWait[-1]
      ( + ( mission-time-msecs ) 500 )
   )

instead of just the key-pressed check, in combination with this event

Code: [Select]
$Formula: ( every-time
   ( key-pressed "1" 0 )
   ( key-reset-multiple "1" )
)
+Name: ResetKey
+Repeat Count: 1
+Interval: 1

to make sure the1 key actually resets.

I am not sure about shift-1, since I actually fly ships with strafe and hence would never use it to toggle events.
« Last Edit: September 04, 2011, 07:21:38 pm by Droid803 »
(´・ω・`)
=============================================================