@ Johnathon
I will attempt to explain it step by step.
Quote: "last_spacekey=spacekey()"
Mr. Tank put this at the end but it can be at the front.
This stores the "old" spacekey state for comparison later.
Quote: "if spacekey() > last_spacekey"
This statement is very clever as it is basically the same as
Quote: "If Spacekey() = 1"
except if SPACE already being pressed [Spacekey()=1] it will return a 0 [if 1 > 1 = false]. In other words this statement will only be true if space has been released beforehand, this means there will be no repetition.
Quote: "spacekeytoggle=1-spacekeytoggle"
This is a simple toggle, if the variable is 0 it will become 1, if it is 1 it will become 0.
I've edited and commented the code to make it easier to follow.
sync on : backdrop on
do
last_spacekey=spacekey() : `store old spacebar state for later
if spacekey() > last_spacekey : `if old spacebar state is 0 allow toggle if spacebar is pressed
spacekeytoggle=1-spacekeytoggle : `toggle switch on/off
endif
text 0,0,"SPACE switch state: " + str$(spacekeytoggle) : `prints the current state of the trip switch
sync
loop
[EDIT]
oops, I forgot to reposition the SYNC command. Here is the same code with the SYNC repositioned. Can you figure out why this version works and the other doesn't?
sync on : backdrop on
do
last_spacekey=spacekey() : `store old spacebar state for later
sync
if spacekey() > last_spacekey : `if old spacebar state is 0 allow toggle if spacebar is pressed
spacekeytoggle=1-spacekeytoggle : `toggle switch on/off
endif
text 0,0,"SPACE switch state: " + str$(spacekeytoggle) : `prints the current state of the trip switch
loop
Great code Mr. Tank
I am king of the noobs!