CreateUnit bitching
Moderator: Moderators
CreateUnit bitching
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?
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
Are you using the base content gadget handler or a CA/ZK derived one?
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: CreateUnit bitching
Please post a link to (pastebin, if needed) your gadget handler and an infolog containing your errors.
Re: CreateUnit bitching
Just unhappy ones when I see a post like this lacking critical information.code_man wrote: Any toughts?
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
Just what came with spring 0.95.FLOZi wrote:Are you using the base content gadget handler or a CA/ZK derived one?
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")
Code: Select all
VFS.Include("LuaGadgets/gadgets.lua",nil, VFS.BASE)
Otherwise i only have my own stuff in there which im positve doesnt cause trouble.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: CreateUnit bitching
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
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.
Also here is the infolog i wanted to post last time but forgot at the end.
http://pastebin.com/hhx2XhF5
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
Im almost a 100% certain that is not the case.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.
Also here is the infolog i wanted to post last time but forgot at the end.
http://pastebin.com/hhx2XhF5
Re: CreateUnit bitching
Add this gadget -
and use it with
Only downside is, that you dont get the UnitID back..
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)
Re: CreateUnit bitching
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.
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)
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
Re: CreateUnit bitching
Its not mine.. jk made it after one rant to much. :) Thus the title 

Re: CreateUnit bitching
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?
Also seriously is this a glitch or lazyness or by design for some reason?
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: CreateUnit bitching
[edit] Removed my guess - as said below there are so many errors in the infolog that could be the cause.
Last edited by Silentwings on 27 Jan 2014, 14:49, edited 2 times in total.
- KingRaptor
- Zero-K Developer
- Posts: 838
- Joined: 14 Mar 2007, 03:44
Re: CreateUnit bitching
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
wrt "new unit during the destruction of an old one": this works.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
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
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.
So wont somebody Kill me now.. i want to die.
Re: CreateUnit bitching
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.
infolog: http://pastebin.com/5ThxyMR8
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?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
infolog: http://pastebin.com/5ThxyMR8
Ok .. i cant make much sense out of this.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.
Last edited by code_man on 28 Jan 2014, 12:23, edited 1 time in total.
Re: CreateUnit bitching
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.is a metafile really nececary?
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.infolog it seems spring wants either pieces of models i have not yet rigged properly
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.it bitches about the delay thing