Page 1 of 1
CreateUnit bitching
Posted: 23 Jan 2014, 18:04
by code_man
Spring.CreateUnit bitches about something whenever i call, but the scripts otherwise work just fine and it tripple checked there seems to be nothing wrong.
Im using spring 0.95 without any external gadgets or whatever.
It complains about "tail call" inside "luaGadgets/gadgets.lua" in lines 1221 and 1247 from what i could gather.
I wouldnt bother with making a thread usually just beacuse it bitches, but some other primitve gadgets i wrote dont run at all and i suspect this could be related.
Any toughts?
Re: CreateUnit bitching
Posted: 23 Jan 2014, 18:16
by FLOZi
Are you using the base content gadget handler or a CA/ZK derived one?
Re: CreateUnit bitching
Posted: 23 Jan 2014, 18:19
by Silentwings
Please post a link to (pastebin, if needed) your gadget handler and an infolog containing your errors.
Re: CreateUnit bitching
Posted: 23 Jan 2014, 18:21
by gajop
code_man wrote:
Any toughts?
Just unhappy ones when I see a post like this lacking critical information.
It could be that you are invoking CreateUnit within a UnitCreate(d) callin recursively. Or that you are doing it in places where you aren't allowed to, such as when you receive a lua msg from unsynced.
I'd rather not guess, so post your infolog and code.
Re: CreateUnit bitching
Posted: 23 Jan 2014, 18:28
by code_man
FLOZi wrote:Are you using the base content gadget handler or a CA/ZK derived one?
Just what came with spring 0.95.
I dont really know what a gadget handler is but, the only 2 things i have are these:
Code: Select all
-- Enables Lua unit scripts by including the gadget from springcontent.sdz
-- Uncomment to override the directory which is scanned for *.lua unit scripts.
UNITSCRIPT_DIR = "scripts/"
return include("LuaGadgets/Gadgets/unit_script.lua")
in "LuaRules/Gadgets/unit_script.lua" and:
Code: Select all
VFS.Include("LuaGadgets/gadgets.lua",nil, VFS.BASE)
inside "LuaRules/main.lua".
Otherwise i only have my own stuff in there which im positve doesnt cause trouble.
Re: CreateUnit bitching
Posted: 23 Jan 2014, 18:36
by Silentwings
You are using the basecontent gadgethandler, in that case, so no need to link to it
Please post a link to (pastebin, if needed) ... an infolog containing your errors.
Re: CreateUnit bitching
Posted: 26 Jan 2014, 01:10
by code_man
Excuse my long delay and my leaky brain, i had alot for things to do and am overworked and slightly stressed out and these little issues dont make it easier.
Anyway i switched to 0.96 and the problem still remains.
Here is the code for one of two cases where it bitches. I wont bother to post the other one because its long, gets called only at start and im absolutely positive its proper.
This one here also except for bitching about Spring.CreateUnit works properly.
Code: Select all
-- spawn_crews.lua
--
function gadget:GetInfo()
return {
name = "Spawn Crews",
desc = "Spawns soldiers when a vehicle gets destroyed",
author = "Code_Man",
date = "2013-12-5",
license = "Public domain",
layer = 1,
enabled = true
}
end
if (not gadgetHandler:IsSyncedCode()) then
return false
end
local Random = math.random
function gadget:UnitDestroyed(unit, unitDef, team)
if (UnitDefs[unitDef].modCategories["tank"]) then
local x, y, z = Spring.GetUnitPosition(unit)
local health = math.ceil(2000 / UnitDefs[unitDef].health)
if (Random(0, health) == 0) then
unit = Spring.CreateUnit("nod_rifle_soldier", x, y, z, 0, team)
Spring.SetUnitHealth(unit, Random(1, 100))
end
if (Random(0, health) == 0) then
unit = Spring.CreateUnit("nod_rifle_soldier", x, y, z, 0, team)
Spring.SetUnitHealth(unit, Random(1, 100))
end
end
end
gajop wrote:
It could be that you are invoking CreateUnit within a UnitCreate(d) callin recursively. Or that you are doing it in places where you aren't allowed to, such as when you receive a lua msg from unsynced.
I'd rather not guess, so post your infolog and code.
Im almost a 100% certain that is not the case.
Also here is the infolog i wanted to post last time but forgot at the end.
http://pastebin.com/hhx2XhF5
Re: CreateUnit bitching
Posted: 26 Jan 2014, 09:52
by PicassoCT
Add this gadget -
Code: Select all
function gadget:GetInfo()
return {
name = "Shut up and live with it, Pica,
desc = "Its easy to Workaround ",
author = "jk",
date = "3rd of May 2010",
license = "Free",
layer = 0,
version = 1,
enabled = true
}
end
--GG.UnitsToSpawn:PushCreateUnit(name,x,y,z,dir,teamID)
if (not gadgetHandler:IsSyncedCode()) then
return
end
local function PushCreateUnit(self,...)
self[#self+1] = {...}
end
if GG.UnitsToSpawn== nil then GG.UnitsToSpawn = { PushCreateUnit = PushCreateUnit } end
function gadget:GameFrame(frame)
if (frame % 10 == 0) and GG.UnitsToSpawn and GG.UnitsToSpawn[1] then
local cur = GG.UnitsToSpawn
GG.UnitsToSpawn = { PushCreateUnit = PushCreateUnit }
for i=1,#cur,1 do
-- Spring.Echo(unpack(cur[i]))
Spring.CreateUnit(unpack(cur[i]))
end
end
end
and use it with
Code: Select all
GG.UnitsToSpawn:PushCreateUnit("unitname",lx,ly,lz,0,teamID)
Only downside is, that you dont get the UnitID back..
Re: CreateUnit bitching
Posted: 26 Jan 2014, 10:26
by FLOZi
It is due to how lua interacts with engine - in layman's terms it is not safe to create a new unit during the creation / destruction of an old one (as the lua is called before the prior unit is 'cleaned up' engine side).
My own preference would be to use the
Delay API
to call a local function which in turn called Spring.CreateUnit, that way I can get the unitID.
e.g.
Code: Select all
local DelayCall = GG.Delay.DelayCall
local function SpawnUnit(unitDefID, x,y,z, teamID)
local unitID = Spring.CreateUnit(unitDefID, x,y,z, 0, teamID) -- didn't check args these are prob wrong order
-- now do whatever you need to with this unitID
end
function gadget:UnitDestroyed(...)
-- blah blah
DelayCall(SpawnUnit, {unitDefID, x,y,z, teamID}, 1)
end
DelayCall is probably worth having in your game anyway as it is very useful in general (compared to Pica's gadgets specific focus on spawning units)
Re: CreateUnit bitching
Posted: 26 Jan 2014, 10:31
by PicassoCT
Its not mine.. jk made it after one rant to much. :) Thus the title

Re: CreateUnit bitching
Posted: 26 Jan 2014, 23:27
by code_man
I havent yet looked exactly at the codes, but so to undersand this i must delay the creation by atleast 1 frame or some specific time?
Also seriously is this a glitch or lazyness or by design for some reason?
Re: CreateUnit bitching
Posted: 27 Jan 2014, 00:08
by smoth
It is retard proofing.
Re: CreateUnit bitching
Posted: 27 Jan 2014, 01:36
by Silentwings
[edit] Removed my guess - as said below there are so many errors in the infolog that could be the cause.
Re: CreateUnit bitching
Posted: 27 Jan 2014, 07:50
by KingRaptor
I'd have thought it was these errors:
Code: Select all
[f=0000000] [unit_script.lua] Error: [string "scripts/mobile_radar_jammer.lua"]:10: piece not found: dish
[f=0000000] [unit_script.lua] Error: [string "scripts/unit_base.lua"]:10: piece not found: base
Re: CreateUnit bitching
Posted: 27 Jan 2014, 11:04
by knorke
FLOZi wrote:It is due to how lua interacts with engine - in layman's terms it is not safe to create a new unit during the creation / destruction of an old one
wrt "new unit during the destruction of an old one": this works.
For example this gadget:
http://springrts.com/phpbb/viewtopic.ph ... bo#p521519
To add on what KingRaptor wrote:
There is lots of other errors unrelated to this gadget
[f=0000000] [Model] Error: 'objects3d//rifle_soldier.lua': could not open file: objects3d//rifle_soldier.lua. Using defaults.
That is a unit you use in gadget, are you sure that all your units work normal with errors? If they do not get loaded because errors then can not spawn them etc
Re: CreateUnit bitching
Posted: 27 Jan 2014, 19:31
by PicassoCT
The problem is that you have a create script within a create script, and there is no communication between those too.. so if you do something dandy with the other unit (alien chestbursts out of moma), the whole unit would have to do a expensive integrity check after it spawned some unit, and it would have to do that for every alien that burts from the bursters chest..
So wont somebody Kill me now.. i want to die.
Re: CreateUnit bitching
Posted: 28 Jan 2014, 11:56
by code_man
Ok i have tried the gadged flozi linked me, i used it with a delay value of 100 and it spawns the units with a noticable delay, however now it bitches about the delay thing.
knorke wrote:
That is a unit you use in gadget, are you sure that all your units work normal with errors? If they do not get loaded because errors then can not spawn them etc
All units i use spawn and work properly, however looking at the infolog it seems spring wants either pieces of models i have not yet rigged properly or a metafile for every model, is a metafile really nececary?
infolog:
http://pastebin.com/5ThxyMR8
PicassoCT wrote:The problem is that you have a create script within a create script, and there is no communication between those too.. so if you do something dandy with the other unit (alien chestbursts out of moma), the whole unit would have to do a expensive integrity check after it spawned some unit, and it would have to do that for every alien that burts from the bursters chest..
So wont somebody Kill me now.. i want to die.
Ok .. i cant make much sense out of this.
Re: CreateUnit bitching
Posted: 28 Jan 2014, 12:11
by Anarchid
is a metafile really nececary?
Supposedly you can set textures for models right in the model file somehow. Didn't try, took path of least resistance. For anything except textures, metafile isn't needed at all.
infolog it seems spring wants either pieces of models i have not yet rigged properly
Slightly different: you are trying to animate a piece in your script that the animated model does not posess. You can't do operations on nonexistent entities, that's an error.
it bitches about the delay thing
If you received such a complaint, could you infer what the problem was and suggest a solution? I suspect not, because that doesn't contain any useful information.