Logic Help

I have a quick question regarding logic bricks (or possibly python).

I have an object that shoots, but I want it to be able to shoot only every 15 pulses. I have it set now so that if you hold down the button, it fires every 15 pulses, but if you tap the button, it fires every time you hit the button, not every 15 pulses. If anyone could help me out, that’d be great.

how about:

Keyboard: > And Cont > Shoot Command
Shoot /
/
Property: 15>/ >Property= 0

Property not equal: 15 > And Cont > property add: 1

something like that should work.

I’m not sure I get what you mean by this. what do you mean by
"Shoot / \
/ "
and what kind of property do mean? Timer perhaps? I’ll tinker a bit and try to see what you mean.

I’m going to bump this, since it’s important that it’s answered. I can upload a .blend if needed…

sure man…
1 minuet i will make a firetimer for you

Here ya go…
http://s91842597.onlinehome.us/blender/firetimer.blend

The cannonball will fire every .5 seconds and not allow the user to press teh key again untill the firetimer resets the firekey property

feel free to ask any questions :slight_smile:

I couldn’t download from that. Maybe use savefile.com? If not, I’ll see if I can do it on another computer in another few hours.

With the file, A) did you do it with python, and b) can it be measured in logic pulses or frames rather than seconds? Or will I need to do some conversion?

here you go:
http://s91842597.onlinehome.us/blender/fire-timer.jpg

you will need to replace my timer with something that counts pulses…

make an intiger property… and an Always>AND>property>add>+1,yourpropertynamehere
will make a pulse counter.

Use seconds instead of pulses. It’s a more common metric, and it’s much easier to handle then just parsing pulses.

Python method:

Logic bricks:
sensor–>python–>editobj(addobj) actuator

Properties:
Timer property - “time” (no quotes)


cont = GameLogic.getCurrentController()
own = cont.getOwner()

sensor = cont.getSensor("sensor")
act = cont.getActuator("act")

if sensor.isPositive() and own.time > 0.5: #I chose 1/2 a second
    GameLogic.addActiveActuator(act, 1)
    own.time = 0

awesome!
Thanks Social :slight_smile:

I am going to be a coder verry soon thanks to you :slight_smile:

Hey thanks pOOf, I’d been puzzling over this for a while, but it’s a lot simpler than I was making it. This helps a lot. I’ll check it out when I get home.

edit: thanks Social!

Hmmm…Neither of these work for me.

pOOf: your method allows me to only fire once, and then not for the rest of the time the game engine is active.

Social: the error reads:
File “Blah”, line 8, in ?
AttributeError: time

thanks for responding. Do you guys have any idea what’s up?

Check that you made the logic brick setup as I instructed, and also check that you added the “time” property (no quotes). Also check your naming (python is case sensitive, remember?)

Go over it one more time, and if you still can’t find anything by yourself post a .blend.

Try the .blend file… seems to work here for me… be sure you click on the pulse mode on the keyboard sensor, if you are following the photo

Well, now I’m embarrassed. I missed something very simple, and totally idiotic. I didn’t connect the sensor to the controller. Sorry about that. It works brilliatly Social. Now I just need to figure out how to integrate it in. Thank you. Just wondering, any way to make those Pulses instead of seconds?

Glad it helped.

Just wondering, any way to make those Pulses instead of seconds?
Why would you want to? I mean you have decimal point seconds at your disposal.

Well anyway if your really so set on it.

Add an integer property named “cpulse” (no quotes)


cont = GameLogic.getCurrentController()
own = cont.getOwner()

act = cont.getActuator("act")

own.cpulse += 1
x = numberofpulsesbeforeshot

if own.cpulse > x:
    GameLogic.addActiveActuator(act, 1)
    own.cpulse = 0

I didn’t test this out, but technically at every “pulse” (script pass) the “cpulse” will increment, and then you can determine the number of pulses by reading “own.cpulse”.

However as I said, I didn’t test this out so I’m not sure if it will work as predicted.

Stick with time, is my advice.