Page 1 of 1

builder not building with an animation

Posted: 17 Jun 2014, 19:31
by peapod
The problem lies (most likely) with the script file; the builder moves around and can build just fine,
but as soon as i add the animation part it will move into range and will just sit there animating
for what i think is the buildduration of that to be built. Here's the script which is a modified version of the Example Mod builder:

Code: Select all

local Body = piece "Body"

local FL_Thigh = piece "FL_Thigh"
local FR_Thigh = piece "FR_Thigh"
local BL_Thigh = piece "BL_Thigh"
local BR_Thigh = piece "BR_Thigh"

local FL_Leg = piece "FL_Leg"
local FR_Leg = piece "FR_Leg"
local BL_Leg = piece "BL_Leg"
local BR_Leg = piece "BR_Leg"

local TR_Arm = piece "TR_Arm"
local TL_Arm = piece "TL_Arm"
local ML_Arm = piece "ML_Arm"
local MR_Arm = piece "MR_Arm"
local BL_Arm = piece "BL_Arm"
local BR_Arm = piece "BR_Arm"

local TR_Hand = piece "TR_Hand"
local TL_Hand = piece "TL_Hand"
local ML_Hand = piece "ML_Hand"
local MR_Hand = piece "MR_Hand"
local BL_Hand = piece "BL_Hand"
local BR_Hand = piece "BR_Hand"


local SIG_BUILD = 2
local SIG_BUILDANIM = 3

function script.Create()
return 0
end

local function BuildAnimate(heading)
	Signal(SIG_BUILDANIM)
	SetSignalMask(SIG_BUILDANIM)
	Turn(Body, y_axis, heading, 2)
	WaitForTurn(Body, y_axis)
	Sleep(50)
	while (true) do
		Turn(TR_Arm, y_axis, -1, 10)
		Turn(TR_Hand, y_axis, -1, 10)
			WaitForTurn(TR_Arm, y_axis)
		Turn(TL_Arm,y_axis, 1, 10)
		Turn(TL_Hand, y_axis, 1, 10)
			WaitForTurn(TL_Arm, y_axis)
		Turn(TR_Arm,y_axis, 0, 10)
		Turn(TR_Hand, y_axis, 0, 10)
			WaitForTurn(TR_Arm, y_axis)
		Turn(TL_Arm,y_axis, 0, 10)
		Turn(TL_Hand, y_axis, 0, 10)
			WaitForTurn(TL_Arm, y_axis)
		Sleep(10)

		Turn(MR_Arm, y_axis, -1, 10)
		Turn(MR_Hand, y_axis, -1, 10)
			WaitForTurn(MR_Arm, y_axis)
		Turn(ML_Arm,y_axis, 1, 5)
		Turn(ML_Hand, y_axis, 1, 10)
			WaitForTurn(ML_Arm, y_axis)
		Turn(MR_Arm,y_axis, 0, 10)
		Turn(MR_Hand, y_axis, 0, 10)
			WaitForTurn(MR_Arm, y_axis)
		Turn(ML_Arm,y_axis, 0, 10)
		Turn(ML_Hand, y_axis, 0, 10)
			WaitForTurn(ML_Arm, y_axis)
		Sleep(10)

		Turn(BR_Arm, y_axis, -1, 10)
		Turn(BR_Hand, y_axis, -1, 10)
			WaitForTurn(BR_Arm, y_axis)
		Turn(BL_Arm,y_axis, 1, 10)
		Turn(BL_Hand, y_axis, 1, 10)
			WaitForTurn(BL_Arm, y_axis)
		Turn(BR_Arm,y_axis, 0, 10)
		Turn(BR_Hand, y_axis, 0, 10)
			WaitForTurn(BR_Arm, y_axis)
		Turn(BL_Arm,y_axis, 0, 10)
		Turn(BL_Hand, y_axis, 0, 10)
			WaitForTurn(BL_Arm, y_axis)
		Sleep(10)
	end
end

local function StopBuildAnimate()
	Turn(Body, y_axis, 0, 2)
	WaitForTurn(Body, y_axis)
	
	Turn(TR_Arm, y_axis, 0, 2)
	Turn(TR_Hand, y_axis, 0, 2)
	Turn(TL_Arm,y_axis, 0, 2)
	Turn(TL_Hand, y_axis, 0, 2)

	Turn(MR_Arm, y_axis, 0, 2)
	Turn(MR_Hand, y_axis, 0, 2)
	Turn(ML_Arm,y_axis, 0, 2)
	Turn(ML_Hand, y_axis, 0, 2)

	Turn(BR_Arm, y_axis, 0, 2)
	Turn(BR_Hand, y_axis, 0, 2)
	Turn(BL_Arm,y_axis, 0, 2)
	Turn(BL_Hand, y_axis, 0, 2)
end

function script.StartBuilding(heading, pitch)
	Signal(SIG_BUILD)
	SetSignalMask(SIG_BUILD)
	BuildAnimate(heading)
	Turn(Body, y_axis, heading, 1)
	WaitForTurn(Body, y_axis)
	Sleep(50)
	endSetUnitValue(COB.INBUILDSTANCE, 1)
return 1
end

function script.StopBuilding()
	Signal(SIG_BUILD)
	SetSignalMask(SIG_BUILD)
	SetUnitValue(COB.INBUILDSTANCE, 0)
	Signal(SIG_BUILDANIM)	
	StopBuildAnimate()	
Sleep(1)
return 0
end

function script.QueryNanoPiece() return TL_Hand end

function script.AimFromWeapon() return TL_Hand end

function script.Killed(recentDamage, maxHealth)
return 0
end



any help is appreciated!
(and sorry if this is a bit blunt or newbie-ridden)

Re: builder not building with an animation

Posted: 17 Jun 2014, 20:41
by knorke
accidently melted two worlds into one:
endSetUnitValue(COB.INBUILDSTANCE, 1)

Re: builder not building with an animation

Posted: 17 Jun 2014, 21:02
by peapod
Thank you, but it doesn't seem to have changed anything...

Re: builder not building with an animation

Posted: 17 Jun 2014, 21:27
by FLOZi
Any errors in infolog?

Re: builder not building with an animation

Posted: 18 Jun 2014, 01:41
by FireStorm_
Not entirely sure, but I think I remember signals need to be a power of 2. Like this:

local SIG_BUILD = 2
local SIG_BUILDANIM = 4

Re: builder not building with an animation

Posted: 18 Jun 2014, 13:59
by Google_Frog
Signals are bit masks so Signal(3) is the same as calling Signal(2) and Signal(1). I have never seen this feature used so just make all signals powers of 2. I hear that there is some alternative to number signals in lua but I have not used them myself.

Re: builder not building with an animation

Posted: 18 Jun 2014, 17:51
by peapod
Thank you for all the answers! But even after searching through the infolog and
changing the signal it still doesn't work...

Re: builder not building with an animation

Posted: 18 Jun 2014, 18:01
by knorke

Code: Select all

function script.StartBuilding(heading, pitch)
...
   BuildAnimate(heading)
That makes it call the function and then it gets forever stuck in the while (true) loop.
Instead call it with StartThread, so it runs in parallel:
StartThread (BuildAnimate, heading)
http://springrts.com/wiki/Animation-LuaCallouts#Threads

Re: builder not building with an animation

Posted: 18 Jun 2014, 19:58
by peapod
StartThread fixed it, thank you very much!!