0
$\begingroup$

with a script, can we change at will the EditObjectActuator.time ? in my case, I want to add time of life to an object, while the game is running with a property or a message from another object ... I 'm a newbie in scripting with Python, I used to code with logic bricks but I do not know how to do ...

JLThe head of my snake

I've tried many methods uncessfully. So I simplified the code to show what I want to do. This is the head of the snake

the inactive layer with the tail I want to increase gradually

Here is the result with a time life of 64 The problem is "How to increase the timelife at will ?"

$\endgroup$
1
$\begingroup$

Yes, not only you can change the actuator.time attribute in realtime, but you can add an object without an actuator.

Change the time based on a property

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

act = cont.actuators["AddObjectActuator"]

act.time = own["MyProperty"]
cont.activate(act)

Adding object through script

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = own.scene

# Both objects can be from scene.objects instead of names
scene.addObject("ObjectNameToAdd", "ObjectWhereToAdd", time=own["MyProperty"])

More info about this method here.

$\endgroup$
  • $\begingroup$ something is wrong with your api link, says 404 error $\endgroup$ – user58715 Jul 30 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.