Mod Question Repository... Questions come in, answers go out - Page 50

Mod Question Repository... Questions come in, answers go out

Resources to get you going on your new project, or to help you over some emergent problems during your development cycle.

Moderator: Moderators

Locked
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Mod Question Repository... Questions come in, answers go out

Post by KDR_11k »

And the full script, errors like that can be because of syntax issues.
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

Code: Select all

[   2172] [string "LuaGadgets/Gadgets/unit_script.lua"]:316: bad argument #1 to 'co_create' (Lua function expected)
[   2172] stack traceback:
	[C]: in function 'co_create'
	[string "LuaGadgets/Gadgets/unit_script.lua"]:316: in function 'StartThread'
	[string "scripts/kufact1.lua"]:26: in function <[string "scripts/kufact1.lua"]:25>
[   2872] [string "LuaGadgets/Gadgets/unit_script.lua"]:316: bad argument #1 to 'co_create' (Lua function expected)
[   2872] stack traceback:
	[C]: in function 'co_create'
	[string "LuaGadgets/Gadgets/unit_script.lua"]:316: in function 'StartThread'
	[string "scripts/kufact1.lua"]:49: in function <[string "scripts/kufact1.lua"]:48>
That's once for when the factory started making the tank, and then once again for when it was finished.

And here's the animation script:

Code: Select all

local ground = piece "ground"
local ldoor = piece "ldoor"
local rdoor = piece "rdoor"

local building = piece "building"
local nano = piece "nano"
local pad = piece "pad"

local SIG_OPEN = 1
local SIG_CLOSE = 2

function script.Create(unitID)
end

function script.QueryBuildInfo() return pad end
function script.QueryNanoPiece() return nano end

function script.Activate()
   SetUnitValue(COB.YARD_OPEN, 1)
   SetUnitValue(COB.INBUILDSTANCE, 1)
   SetUnitValue(COB.BUGGER_OFF, 1)
   return 1
end

function script.StartBuilding()
	StartThread(build_open)
end

local function build_open()
	SetSignalMask(SIG_OPEN)
	Signal(SIG_CLOSE)
	Move(building, y_axis, 40, 40)
	Sleep(250)
	Turn(ldoor, z_axis, 1, 40)
	Turn(rdoor, z_axis, -1, 40)
	WaitForMove(building, y_axis)
	WaitForTurn(ldoor, z_axis)
	WaitForTurn(rdoor, z_axis)
end

function script.Deactivate()
   SetUnitValue(COB.YARD_OPEN, 0)
   SetUnitValue(COB.INBUILDSTANCE, 0)
   SetUnitValue(COB.BUGGER_OFF, 0)
   return 0
end

function script.StopBuilding()
	StartThread(build_close)
end

local function build_close()
	SetSignalMask(SIG_CLOSE)
	Signal(SIG_OPEN)
	Move(building, y_axis, -40, 40)
	Sleep(250)
	Turn(ldoor, z_axis, -1, 40)
	Turn(rdoor, z_axis, 1, 40)
	WaitForMove(building, y_axis)
	WaitForTurn(ldoor, z_axis)
	WaitForTurn(rdoor, z_axis)
end

function script.Killed(recentDamage, maxHealth)
   return 0
end
I've been getting this error lately with my own units, so I'm inclined to think I've become comfortable with, and therefore careless, with the scripting, or maybe in writing my own lines (as opposed to copy/paste and filling in) I'm missing some detail I never noticed before.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Mod Question Repository... Questions come in, answers go out

Post by Tobi »

SanadaUjiosan wrote:

Code: Select all

function script.StartBuilding()
	StartThread(build_open)
end

local function build_open()
	...
end

Code: Select all

function script.StopBuilding()
	StartThread(build_close)
end

local function build_close()
	...
end
Local functions must be declared before you use them!
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

Oooooh... so it does matter which order these things are in. Something led me to believe that wasn't the case.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Mod Question Repository... Questions come in, answers go out

Post by Erik »

Code: Select all

 canreclaim          = true,
    reclaimspeed        = 10,
anything else needed for a unit to properly reclaims stuff?
I had it working before with the builder tag, but after i added some features (Fly,transport) it didn't show up anymore.
Do i need any script or additional tag for it to work?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Mod Question Repository... Questions come in, answers go out

Post by Tobi »

Unfortunately builder and transport are mutually exclusive in the engine.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Mod Question Repository... Questions come in, answers go out

Post by Erik »

ugh
Any chance that this can be changed engine wise?
*Looks at google summer projects* 8)

Edit: Also it still isn't able to reclaim after removing that transportation, but it started moving differently with strafing runs and loopings!
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

I've poked around a little bit looking at how transports work, but I think I'll just have to flat-out ask.

Have the lua commands for transporting units been changed? The wiki mentions that the "current" setup wasn't ideal and that it was subject to change. I ask because although I try the different approaches it lists, they all seem to do th e same in-game, which is lower to the ground and drop each unit one at a time.

Also, is there a way to hide the passenger? I noticed in BA the boat transport has a crane that puts the passenger in the hull. Does the passenger disappear, or is the hull just large enough to hide any unit it can pick up?

And lastly, is it possible to have multiple link points on the transport? Like units sticking to the transport in 2 parallel rows of points?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Mod Question Repository... Questions come in, answers go out

Post by KDR_11k »

I think ground transports and air transports differ in some way, ground transports can pick units up and hide them in the script while air transports have that hardcoded IIRC.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

SanadaUjiosan wrote:I've poked around a little bit looking at how transports work, but I think I'll just have to flat-out ask.

Have the lua commands for transporting units been changed? The wiki mentions that the "current" setup wasn't ideal and that it was subject to change. I ask because although I try the different approaches it lists, they all seem to do th e same in-game, which is lower to the ground and drop each unit one at a time.
Without looking, did you try the transportUnloadMethod unitDef tag?
Also, is there a way to hide the passenger? I noticed in BA the boat transport has a crane that puts the passenger in the hull. Does the passenger disappear, or is the hull just large enough to hide any unit it can pick up?
Units are hidden by AttachUnit to -1 instead of a valid piece
And lastly, is it possible to have multiple link points on the transport? Like units sticking to the transport in 2 parallel rows of points?
Yes, just make the empty points in the s3o and AttachUnit to each point in turn as a unit is loaded. SWIW air transports do this for example (and some S44 boats).
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

Without looking, did you try the transportUnloadMethod unitDef tag?
Ah, yep, that did it. Thanks for pointing that out.
Units are hidden by AttachUnit to -1 instead of a valid piece
I've tinkered with this for a while and I haven't been able to figure out how to set it up. Whatever I do just gives me the same error message.

Here is what the infolog says:

Code: Select all

[   1025] [string "scripts/btransportcarrier.lua"]:26: attempt to call global 'AttachUnit' (a nil value)
[   1025] stack traceback:
	[string "scripts/btransportcarrier.lua"]:26: in function <[string "scripts/btransportcarrier.lua"]:25>
And here is my script:

Code: Select all

	local body = piece "body"
	local door = piece "door"
	local flare1 = piece "flare1"
	local flare2 = piece "flare2"
	local flare4 = piece "flare3"
	local flare3 = piece "flare4"
	local link = piece "link"
	local link_false = -1

	local SIG_AIM = 1
	local SIG_AIM_SEC = 2
	local SIG_AIM_THIR = 4
	local SIG_AIM_FOUR = 8


	function script.Create(unitID)
	end

	local function RestoreAfterDelay(unitID)
		Sleep(2500)
		Turn(body, y_axis, 0, math.rad(90))
	end

	local function hide_passenger()
		AttachUnit (link_false, passengerID)
	end

	local function open_door()
		Turn (door, x_axis, -0.5, 2)
		Sleep(2500)
		Turn (door, x_axis, 0, 5)
	end

	local function close_door()
		Turn (door, x_axis, -0.5, 2)
		Sleep(2500)
		Turn (door, x_axis, 0, 5)
	end

	function script.QueryWeapon1() return flare1 end

        function script.QueryWeapon2() return flare2 end

	function script.QueryWeapon3() return flare3 end

        function script.QueryWeapon4() return flare4 end
	
	function script.AimFromWeapon1() return body end

        function script.AimFromWeapon2() return body end

	function script.AimFromWeapon3() return body end

        function script.AimFromWeapon4() return body end
	
	function script.AimWeapon1( heading, pitch )
                Signal(SIG_AIM)
		SetSignalMask(SIG_AIM)
        	Turn(body, y_axis, heading, math.rad(90))
        	Turn(body, x_axis, 0, math.rad(60))
        	WaitForTurn(body, y_axis)
        	WaitForTurn(body, x_axis)
		StartThread(RestoreAfterDelay)
		return true
	end

	function script.AimWeapon2( heading, pitch )
		Signal(SIG_AIM_SEC)
		SetSignalMask(SIG_AIM_SEC)
        	Turn(body, y_axis, heading, math.rad(90))
        	Turn(body, x_axis, 0, math.rad(60))
        	WaitForTurn(body, y_axis)
        	WaitForTurn(body, x_axis)
		StartThread(RestoreAfterDelay)
		return true
	end

	function script.AimWeapon3( heading, pitch )
		Signal(SIG_AIM_THIR)
		SetSignalMask(SIG_AIM_THIR)
        	Turn(body, y_axis, heading, math.rad(90))
        	Turn(body, x_axis, 0, math.rad(60))
        	WaitForTurn(body, y_axis)
        	WaitForTurn(body, x_axis)
		StartThread(RestoreAfterDelay)
		return true
	end

	function script.AimWeapon4( heading, pitch )
		Signal(SIG_AIM_FOUR)
		SetSignalMask(SIG_AIM_FOUR)
        	Turn(body, y_axis, heading, math.rad(90))
        	Turn(body, x_axis, 0, math.rad(60))
        	WaitForTurn(body, y_axis)
        	WaitForTurn(body, x_axis)
		StartThread(RestoreAfterDelay)
		return true
	end
	
	function script.FireWeapon1()
		Sleep(30)
	end

	function script.FireWeapon2()
		Sleep(30)
	end

	function script.FireWeapon3()
		Sleep(30)
	end

	function script.FireWeapon4()
		Sleep(30)
	end

	function script.BeginTransport(passengerID)
		StartThread(open_door)
		StartThread(hide_passenger)
	end

	function script.QueryTransport(passengerID)
		return link
	end

	function script.EndTransport(each)
		StartThread(close_door)
	end

	function script.Killed(recentDamage, maxHealth)
		return 0
	end
If someone could look at that, I'd greatly appreciate it.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

AttachUnit is not localised by default, so you have to call Spring.UnitScript.AttachUnit, or localise it in your script yourself

Code: Select all

local AttachUnit = Spring.UnitScript.AttachUnit
AttachUnit(-1, unitIDofTransportee)
edit: looking at your script, is this an air or ground transport?
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

It is an air transport. Why, is there something odd in it?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

No, I'm just not as familiar with the air transport functions. :oops:
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

FLOZi wrote:Code:
local AttachUnit = Spring.UnitScript.AttachUnit
AttachUnit(-1, unitIDofTransportee)
Well, defining the AttachUnit worked, or at least I think it did. Error has changed. Now it's saying bad UnitID. I tried different variations, but none seemed to work. I tried passengerID, unitID, passengerunitID, and I think another, but I don't remember what it was.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

That's because passengerID is local to BeginTransport. Either put the AttachUnit call at the end of the open_door function, and pass the passengerID to it, or, probably the better way;

Code: Select all

   function script.BeginTransport(passengerID)
      open_door()
      AttachUnit(-1, passengerID)
   end
Note that I'm calling the open_door function immediately rather than in it's own thread, that means that the open_door() will execute first before moving on to the AttachUnit call. Generally speaking, you should keep the number of Threads to a minimum, you only need to use them when functions have to run at the same time as others.
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

Well, the error went away...

But, the passenger unit is not disappearing.

I stupidly tried using 0 and 1 instead of -1, but it didn't do anything.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

SanadaUjiosan wrote:Well, the error went away...

But, the passenger unit is not disappearing.

I stupidly tried using 0 and 1 instead of -1, but it didn't do anything.
As KDR mentioned, there are differences between gorund and air trans, probably it does not work for air trans, because what it actually does is place the unit at -1000 units in the y axis of the transport, which obviously might not work right for aircraft :wink:

What you can do, however, is use some more fanciful lua. Call Spring.SetUnitNoDraw(passengerID, true) when the unit is attached, and Spring.SetUnitNoDraw(passengerID, false) when the unit is dropped.
User avatar
SanadaUjiosan
Conflict Terra Developer
Posts: 907
Joined: 21 Jan 2010, 06:21

Re: Mod Question Repository... Questions come in, answers go out

Post by SanadaUjiosan »

Success!

Sort of... getting it to hide the passengers was easy, but to make them reappear was a hassle. I was trying to use the Unload Drop method, (1), but I couldn't find a way to get the passenger ID to work. So I went with the Unload Land Flood (2) and now it does what I want it to do. I'd prefer to use the cool drop from the air feature, but something is better than nothing.

Thanks a ton Flozi for your help and patience!
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Mod Question Repository... Questions come in, answers go out

Post by FLOZi »

For some reason gnome bugged me on MSN instead of posting himself
gnomre says:
but still
he was having problems with the drop method and passenger ID
he just needs to cache and loop
unless it's transporting a billion units at a time it shouldn't be a very cpu consuming loop
Locked

Return to “Game Development Tutorials & Resources”