wait 40 frames in python

ok i have a script that i modified but i cant figer out how to make it after firing once to wait 40 frames then fire agine

cont = GameLogic.getCurrentController()
own = cont.getSensors()[0]
Ray = cont.getSensors("shot")[0]
mouse = cont.getSensors("mouse")[1]
prop = cont.getSensors("prop1")[2]
shoot = prop.isPositive() and mouse.isPositive() and Ray.isPositive()
if shoot:
    Obj = Ray.getHitObject()
    Obj.Health -= 30

the script works fine except for that, thanks a head off time
P.S. yes Social im finaly learning python

That script doesn’t look all that correct.

I assume your using a ray sensor to simulate bullet fire

Let me try to help you out:

#This is one of my old bullet fire scripts.
#I'll try to comment things as much as I can for you.
import GameLogic as G
cont = G.getCurrentController()
own = cont.getOwner() #getOwner, not sensor.

#When you assign sensors by name like below, you don't put a "[0]"-
#after that. That is done when you call in bulk: "cont.getSensors()[0]"-
#which would pick the first sensor from the top assigned to that object.
#Same goes with actuators.

leftclick = cont.getSensor("LeftClick") 
ray = cont.getSensor("Ray")

#Message Actuator that will send a message to the hit object.
#That object would have a health prop and a logic brick setup-
#to decrease the healthprop by (<i>in your case</i>) 30 points, every time
#the message sensor (<i>on the hit object</i>) would recieve a message from
#the kill actuator (<i>which is attached to your player/weapon</i>)

kill = cont.getActuator("Kill")

#Get name of the hit object
obhit = ray.getHitObject().getName() 

#Forget "40 frames", measure by time. You can do that by adding a-
#time prop, and you do that by going into the logic brick button window
#and hitting that long ADD property button. Set the property type to "time"
#and name it "time" no quotes.
#Then you call it like this: "own.time"
#Like a clock, it will start counting up seconds as soon as game starts.
if leftclick.isPositive() and ray.isPositive():
    #Set a time condition for 2 seconds (<i>or whatever</i>) from fire to next fire:
    if own.time &gt; 2:
        kill.setToPropName(obhit)#Set message actuator to message this OB
        G.addActiveActuator(kill,1)#Send message
        #reset timer to 0, so that the above statement will be false for 2sec
        own.time = 0
    G.addActiveActuator(kill,0)#Dont's send message/shut down act

I didn’t test this particular timed version, but it should work for you. Play around with it, and if you have any questions don’t be afraid to ask.

PS: I’m glad you decided to take my suggestions. Learning the BGE PY API will help you out plenty, I guarantee it.

accitental post c bellow

um ya i coudnt get that script to work it keeps telling me

AttributeError: 'list' object has no attribute ' getHitObject'

o and that scipt above does work the prop1 property is 4 my own uses here is what it should looklike

cont = GameLogic.getCurrentController()
own = cont.getSensors()[0]
Ray = cont.getSensors("Ray")[0]
mouse = cont.getSensors("mouse")[1]
shoot = mouse.isPositive() and Ray.isPositive()
if shoot:
    Obj = Ray.getHitObject()
    Obj.Health-= 30

You probably don’t have the right logic brick setup (It’s a different setup all together). I gave you my script with comments so that you can implement parts of it in your script (and so you could understand and remove the parts that don’t have to be there in the first place like the “(“sensorname”)[0]”. You don’t do that when you call sensors by name, the [0] is not necessary).

Here try this:

#Your script structure this time. Same concepts.
#Add the time property like I described in my script
cont = GameLogic.getCurrentController()
own = cont.getOwner()#own should not be a sensor as you had before
Ray = cont.getSensors("Ray")#No need for [0]
mouse = cont.getSensors("mouse")#Or [1], because you named your logic
                                               #bricks, Right?

#Instead of "shoot =" just write:
if mouse.isPositive() and Ray.isPositive():
    #Same thing with time as in my script:
    if own.time &gt; 2:
        Obj = Ray.getHitObject()
        Obj.Health-= 30
        #Same reset
        own.time = 0

That should work in your setup.

PS: You can edit your posts, by using the “edit” option on the bottom right corner of the post.

ya lol thats exactly what i did, but u did answer my quetion, and thank u Social you helped me out a lot:)

thanks from a noob

No problem. Glad I could help.