0
$\begingroup$

I am having difficulty changing states with the same keyboard sensor. The bricks are simple. One keyboard sensor activated by tapping "1" connected to the actuator that will change to state number 2. Then on state number 2 the above keyboard sensor with no changes, connect to the actuator that will change to state number 1.

The initial state is number 1. It manages to change to number 2 but then it does not "come back" to state 1 if I press "1" again. Any ideas why?

$\endgroup$

2 Answers 2

1
$\begingroup$

You do not need such setting at all. The default (no level trigger, no Level, no Tap, no Invert) will do it's job as is.

How does it work?

State A)

When you press the key the state actuator to State B gets activated. The state changes to State B)

enter image description here

State B)

When you release the key ... nothing happens. When you press the key the state actuator to State A gets activated. The state changes to State A)

enter image description here

What happens with Tap?

Tap means that the next frame the sensor evaluates False even if the measured event is still present (Tap makes the sensor lie). Evaluating False results in a deactivation of the actuators. The state actuator runs one frame only ... and ignores deactivation completely.

Therefore it works the same way as without Tap.

What happens with Level?

Level means the sensor triggers the controller on state change (additionally to the evaluation changes true/false false/true).

This is problematic. When you press the key it is unlikely you release it within the 1/60s. This means when entering a state the sensor will trigger the controller (with true) and activate the state actuator which switches to the other state.

This way you get constant state changes until you release the key. So you are playing random generator. If that is you goal ... well done. If not ... better disable Level.

What happens with True Level Triggering? This makes the sensor triggering the controllers when evaluating True all the time. This forces the actuators to get activated as long as the key is pressed. This results in constant state switching.

In difference to Level, you can delay the switching by setting the Frequency parameter (Freq:) to a value greater than zero.

What happens with False Level Triggering? This makes the sensor triggering the controllers when evaluating False all the time. This forces the actuators to get deactivated as long as the key is not pressed. As deactivation gets ignored .. it just wastes some processing time.

Usually this is not necessary.

$\endgroup$
5
  • $\begingroup$ In your screenshot you used "Set state". I used "Change state" in my actuator. Your method works without "level", and mine works with "level". Do you know the difference between "set" and "change" ,if yes can you add it to your elaborated answer so I can also mark it? $\endgroup$
    – Lev
    Aug 17, 2015 at 11:24
  • $\begingroup$ @Lev you should use set state, it usually cleaner and less faulty for the computer (I have no idea why) $\endgroup$
    – ruckus
    Aug 17, 2015 at 15:51
  • $\begingroup$ @RadishoftheOpera thanks for the info. Do you know the difference between them 2 by any chance? $\endgroup$
    – Lev
    Aug 17, 2015 at 18:12
  • $\begingroup$ no... sorry about that. $\endgroup$
    – ruckus
    Aug 17, 2015 at 18:36
  • $\begingroup$ "Set" explicitly sets the states as provided by the actuator. "Change" toggles the states set in the actuator. Toggle = if active it will become inactive, if inactive it becomes active. So it depends on the current state. In my eyes "set" is the be cleanest mode to implement a state machine. $\endgroup$
    – Monster
    Aug 18, 2015 at 5:48
0
$\begingroup$

I fixed my problem by enabling "level" in the keyboard sensor instead of "tap".

"Tap" seemed more logical to me, so if someone knows why it did not work, let me know.

So if you want to change states with the same keyboard sensor activate "level".

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .