builder not building with an animation

builder not building with an animation

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
peapod
Posts: 8
Joined: 09 Jun 2014, 16:49

builder not building with an animation

Post 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)
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: builder not building with an animation

Post by knorke »

accidently melted two worlds into one:
endSetUnitValue(COB.INBUILDSTANCE, 1)
peapod
Posts: 8
Joined: 09 Jun 2014, 16:49

Re: builder not building with an animation

Post by peapod »

Thank you, but it doesn't seem to have changed anything...
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: builder not building with an animation

Post by FLOZi »

Any errors in infolog?
User avatar
FireStorm_
Posts: 666
Joined: 19 Aug 2009, 16:09

Re: builder not building with an animation

Post 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
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: builder not building with an animation

Post 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.
peapod
Posts: 8
Joined: 09 Jun 2014, 16:49

Re: builder not building with an animation

Post by peapod »

Thank you for all the answers! But even after searching through the infolog and
changing the signal it still doesn't work...
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: builder not building with an animation

Post 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
peapod
Posts: 8
Joined: 09 Jun 2014, 16:49

Re: builder not building with an animation

Post by peapod »

StartThread fixed it, thank you very much!!
Post Reply

Return to “Game Development”