game logic for key behavior

Hello!

I think I need some examples for game logic.

If I press a key one time something should appear in the scene, and if I press the same key a second time it should disappear again. Pressing a third time should start again, as if pressing the first time.

It would be nice, if this works with the edit object-actuator as well.

I learned already to achive appearing and disappearing, if using two different keys, and I too know, how to use the visibility-actuator in a way, which shows objects just as long as I press one key.

Are there some examples out there, through which I could study some advance key-logic for logic-bricks?

Thanks, Ingo

Well, you can simply use a property acuator, ahve it so when you press a key it makes the propert a certain number like 1 and then the object appears, then you press the key again when the property is 1 and it sets it back to 0 and thus makes the object dissapear.

Pooba

when you press a key it makes the propert a certain number like 1 and then the object appears, then you press the key again when the property is 1 and it sets it back to 0 and thus makes the object dissapear.

I played already a while with the property actuator, but had no working idea, how to use all the possible combinations, to set the property back with a second click.

Example:
I just try to make something appear or disappear with the visibility actuator, when pressing V.

  1. I use keyboard sensor connected to property actuator which changes the state of an integer property from 0 to 1. (maybe this is already wrong, but actually it works)
  2. I use property sensor to watch the state combined with the visibility actuator. (This realises the property change and makes the object appear, if before the property was 0.)
  3. So now I have to press a second time changing everything back. Ok, I can watch the property, but in truth, I have to define a different action for pressing the same key. How?

In property actuator I used assign. Maybe I should use add or copy, but it doesn’t seem to be the right one? Or something different in property sensor, for now I just used equal, but there’s also changed? Maybe I have to combine one output with more actuators, or I should use more sensors for one output?

Thanks, Ingo

ps: I’m quite new to all the property stuff and even the game engine itself.

I usually just put two key sensors for the same key and put the appear-actuator on the first one and the dissapear-actuator on the second one. This works for me, even though I can’t tell you exactly why…

just put two key sensors for the same key and put the appear-actuator on the first one and the dissapear-actuator on the second one.

Hmm, I tried quickly, but it doesn’t seem to work here (using publisher 2.25, it only disappears, but doesn’t appear again.)

Ingo

If interested, here you find my current test-file:
http://www.pt.rwth-aachen.de/~kappler/

Thanx, Ingo

Ok, I’ve made a small example file for you. When you hit V it dissapears, and when you hit V again it appears again. The only thing that might not make sense is the PRESS property, but without it it would switch between the things every frame you had the key pressed (so it would appear as if it were flashing). It just makes it so when you hit V it changes press to 1, and when you release V it changes it back to 0, and the V key won’t work unless you release the key.

www.gratisweb.com/pooba/switcheroo.blend

it’s 36k

Pooba

Hi, Pooba !

Thanks a lot for the example. I’m quite happy to see what is possible, nice work. :smiley:

(so it would appear as if it were flashing). It just makes it so when you hit V it changes press to 1, and when you release V it changes it back to 0, and the V key won’t work unless you release the key.

Ok, I know what you mean here. But looking on the logic you have done, I’m not quickly able to discover how this all really works, because there seem to happen many things at the same time. But ok, the result does convince. :wink: So I will try to build something like that in my own test file, hoping, that with some time I can discover what really happens within blender.

I think your example is not easy, and I hope you think the same, because how would logic be, if this would be considered to be easy? :-? Maybe an explicit sensor or keyboard sensor function would be useful, to make using the same key twice could be implemented quicker?

So thanks again, and probably we will hear from each other again. If you have some hints how to read (understand) the logic in your example, I would be pleased, but it is up to your time, so I don’t like to expect anything.

best wishes
Ingo

okay i told this huge way to do it so u prees it it appears then press again and it disapears well my comp froze and i lost my hole thing but i’ll just show u my ex. i made also. just check it out it’s pretty simple

http://www22.brinkster.com/iceduck/triggerdemo.blend

Hi, snowy_duck!

It’s really a lot simpler and it even works with the edit object actuator. But there’s still something on the logic that confuses me, so I will try to tell you what.
If I press the V-key one time, it seems that the puls/pulses sent out by the keyboard actuator are going to ALL actuators on the right site. And there are property actuators which add the value 1 and substract the value -1 at the same time.

There are some small effects, I suppose they shouldn’t be there. If I press V the first time the object always appears, pressing it second time it often doesn’t just disappear, but gets recreated quickly. Maybe this is because it’s your ex? :wink: But it’s not really important, because I mainly need to understand how the logic works, until I will be able to know what I’m doing, even if it gets a bit more complexity.

thanx and regards
Ingo

Acually, the demo made took me like 2 minutes. It’s pretty easy, but i’m kinda advanced in logicbricks, so i don’t know.

Pooba

It’s pretty easy, but i’m kinda advanced in logicbricks, so i don’t know.

Hmm, so what now? Is the only written description of blender logic in the “Reference to Blender’s real-time 3D engine”, which I already have? Are there any sides in the web? Or have I just to use try and error (which might take a lot of time, if something doesn’t work quickly).

But there’s still something on the logic that confuses me, so I will try to tell you what.
If I press the V-key one time, it seems that the puls/pulses sent out by the keyboard actuator are going to ALL actuators on the right site. And there are property actuators which add the value 1 and substract the value -1 at the same time.

Any answer? I’m really new to that whole logic stuff.

thanx, Ingo

I think I mised some basic understanding how the logic works (Had not figured out, that two inputs in and-controller describe that both are needed to get the pulse through.) :frowning: Your examples, and further working on my own project helped. I now have a better view and understanding.

Ingo