Re: Mod Question Repository... Questions come in, answers go out
Posted: 23 Feb 2010, 13:53
And the full script, errors like that can be because of syntax issues.
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
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>
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
Local functions must be declared before you use them!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
Code: Select all
canreclaim = true,
reclaimspeed = 10,
Without looking, did you try the transportUnloadMethod unitDef tag?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.
Units are hidden by AttachUnit to -1 instead of a valid pieceAlso, 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?
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).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?
Ah, yep, that did it. Thanks for pointing that out.Without looking, did you try the transportUnloadMethod unitDef tag?
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.Units are hidden by AttachUnit to -1 instead of a valid piece
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>
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
Code: Select all
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.FLOZi wrote:Code:
local AttachUnit = Spring.UnitScript.AttachUnit
AttachUnit(-1, unitIDofTransportee)
Code: Select all
function script.BeginTransport(passengerID)
open_door()
AttachUnit(-1, passengerID)
end
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 aircraftSanadaUjiosan 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.
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