Page 1 of 1

[LUA] How make pumping ?

Posted: Sun Sep 12, 2010 6:50 am
by D.Durand
Hi,

How do i make pumping with lua ? I mean, an element go in a direction, then in reverse, then reverse again, etc.

I found something in a TA unit (a T3 mexe), but i don't understand how to do the same thing in lua.

Re: [LUA] How make pumping ?

Posted: Sun Sep 12, 2010 9:36 am
by zuzuf
you need to start a script (which will then run in parallel to the function that started it) with a loop containing one cycle of the pumping animation which will be repeated until the loop ends.

Something like:

Code: Select all

local ANIM_SPEED = 0.2
__this.PumpingAnimation = function(this)
    while true do
        this:move( this.piston, y_axis, 0, 1)
        this:sleep( ANIM_SPEED )
        this:move( this.piston, y_axis, 10, 1)
        -- required to avoid the engine being stuck in a script
        this:sleep( ANIM_SPEED )
    end
end
you could then do "this:start_script(this.PumpingAnimation, this)" in the Create function to have the unit pumping as soon as it's created (you may also want to delay the animation until build is complete). With this code it'll pump until its death but you can replace the "true" condition with a variable or something else to allow stopping/starting the animation with some event.

Re: [LUA] How make pumping ?

Posted: Sun Sep 12, 2010 2:43 pm
by D.Durand
Thank you. I will try that.

Re: [LUA] How make pumping ?

Posted: Mon Sep 13, 2010 3:26 pm
by D.Durand
Well, i tried to add that to my unit script, but how do i call the function, particularly by adding the name of the element i want to make "pumping" ?

Re: [LUA] How make pumping ?

Posted: Mon Sep 13, 2010 3:58 pm
by zuzuf
Just use the start_script function which accepts as many parameters as you want:

Code: Select all

__this.my_function = function(this, parameter1, parameter2)
end

__this.Create = function(this)
    this:start_script(this.my_function, this, this.head, this.lleg)
end
Since you can manipulate only variables in Lua, the model pieces are just variables containing the piece's ID so you can copy it into another variable, change it (not recommended), use it as a return value for a function, etc...

Re: [LUA] How make pumping ?

Posted: Mon Sep 13, 2010 5:19 pm
by D.Durand
Thanks, i will try that.