Browse Search Popular Register Upload Rules User list Login:
Search:
Keyed Momentary On Switch

Image:
screenshot of the scene

Author: s_noonan

Group: Technical

Filesize: 31.72 kB

Date added: 2018-01-08

Rating: 5.6

Downloads: 404

Views: 360

Comments: 8

Ratings: 2

Times favored: 0

Made with: Algodoo v2.1.0

Tags:

Scene tag

Keyed Momentary On Switch

Benefits:

1. The switch can display the name of the function of the switch (for example, like "roar" in wild bill's raptor scene).
2. The switch displays the key that is used to do the function.
3. The switch displays the state of the switch.
4. The switch separates the states from the control logic. You can put code in the states without regard or caring about the logic.
5. The switch initiates state1 once, preventing multiple restarts of state1 even though the key is held down.
6. The switch sets the state to zero once upon release. This prevents constant resetting of the zero state and allows the state of the item being controlled to be set by the last key pressed.

Rev A: _state0() is initiated only once upon key release.
RevB: Uses code from JakubKubo's Key input detector.
Last edited at 2018/01/14 14:06:42 by s_noonan
Please log in to rate this scene
edit
Similar scenes
Title: Keyed Toggle Switch
Rating: 5.625
Filesize: 31.86 kB
Downloads: 341
Comments: 4
Ratings: 2
Date added: 2018/01/08 22:21:34
Made with: Algodoo v2.1.0
Rating: rated 5.6
download
Title: Switches !
Rating: 5
Filesize: 66.18 kB
Downloads: 707
Comments: 1
Ratings: 1
Date added: 2020/10/25 19:08:52
Made with: Algodoo before v1.8.5
Rating: rated 5
download
Title: Nintendo Switch
Rating: 5.125
Filesize: 77.59 kB
Downloads: 869
Comments: 0
Ratings: 2
Date added: 2018/04/05 02:40:33
Made with: Algodoo v2.1.0
Rating: rated 5.1
download
Title: Train Guide-Rail switch
Rating: 5
Filesize: 37.74 kB
Downloads: 1399
Comments: 0
Ratings: 1
Date added: 2013/10/28 15:16:21
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Laser Position switch v2
Rating: 5
Filesize: 47.41 kB
Downloads: 455
Comments: 0
Ratings: 1
Date added: 2012/08/18 16:57:39
Made with: Algodoo v2.0.2
Rating: rated 5
download
Title: Scrapped FCG
Rating: 5
Filesize: 36.05 kB
Downloads: 422
Comments: 0
Ratings: 1
Date added: 2024/09/16 12:40:00
Made with: Algodoo v2.1.0
Rating: rated 5
download
I had no idea what post step was for but I see now, thanks.
s_noonan,
Please explain how this is any better (it certainly is more complex) than just using keysIsDown() by itself in each of the three control boxes? I don't get it. :huh:
I'd rather you use onKey event for that. Much simpler handling.
Last edited at 2018/01/09 22:17:17 by Kilinich
Xray,

Q: Please explain how this is any better (it certainly is more complex) than just using keysIsDown() by itself in each of the three control boxes?
A: Benefits:

1. It can display the name of the function of the switch (for example, like "roar" in wild bill's raptor scene).
2. It displays the key that is used to do the function.
3. It displays the state of the switch.
4. It separates the states from the control logic. You can put code in the states without regard or caring about the logic.
5. It initiates state1 once, preventing multiple restarts of state1 even though the key is held down.
6. It sets the state to zero in a short time window after release of the key. This prevents constant resetting of the zero state and allows the state of the item being controlled to be set by the last key pressed.

If your point is that everything can be put into the keysIsDown() structure, then I agree with you. If you think that the logic structure can be simplified, then please show me how.

Kilinich,

The problem I have with

onKey := (e)=>{
keys.isDown(_key) ? {
_state1()
} : {
_state0()
}
};

is that _state1() will happen when the specific _key is pressed, but _state0() will happen when any keyboard key is released. This means that all the _state0()s will fire within the time of 1/sim.frequency in whatever order Algodoo decides. Please correct me if I am wrong.

And another thing, if you use the onKey event, and you are not in Algodoo play-mode, and you press a key that is also a short cut key, then the onKey event doesn't see the first press of your key. This doesn't happen when you put the code in the postStep event.
Last edited at 2018/01/10 01:47:08 by s_noonan
Is there a way how to lock shortcut key? so it will work always like in play-mode
Q: Is there a way how to lock shortcut key? so it will work always like in play-mode.
A: Yes, put key control code in the update event.
s_noonan,
I think JakubKubo was asking how to lock out the shortcut keys in order to prevent them from being active. And of course the answer to that would be, by placing: app.gui.playMode = sim.running in any update event.
Xray,
I agree. Thanks for clarifying that.