Page 1 of 1

creating new units in unitdefs_post.lua

Posted: 21 May 2011, 20:45
by knorke
I want to create new unitDefs in unitdefs_post.lua

Just doing this:

Code: Select all

newunit.name  = "testunit"
newunit.objectname  = "cube.s3o"
newunit.script = "empty.lua"
UnitDefs["testunit"] = newunit
does not work:
/give testunit
testunit is not a valid unitname


If I add something on top to copy every tag from an existing unitdef like this:

Code: Select all

newunit = {}
ud = UnitDefs ["tpthulsa"]
for key,value in pairs(ud) do
	Spring.Echo(key,value)
	newunit[key]=value
end
newunit.name               = "testunit"
newunit.objectname         = "cube.s3o"
newunit.script = "empty.lua"
UnitDefs["testunit"] = newunit
Then it works.

So I thought that maybe name, objectname & script alone are not enough to define a valid unitDef.

But this unitdef works, when saved as units\cube.lua:

Code: Select all

local unitName = "cube"
local unitDef = {
	name = "Cube Unit",
	objectName = "cube.s3o",
	script = "empty.lua",
}
return lowerkeys({ [unitName] = unitDef })
Notice it also only uses name, objectname & script.

So what is going on there?
Are the rules for unitdefs_post just more strict?
Or something else?

Re: creating new units in unitdefs_post.lua

Posted: 21 May 2011, 21:15
by quantum
It looks like it adds the "filename" field. You can check here: https://github.com/spring/spring/blob/m ... itdefs.lua

Re: creating new units in unitdefs_post.lua

Posted: 21 May 2011, 23:52
by smoth
Look at gundam's feature def pots there is a bare minimal unit defined when I create units from features

Re: creating new units in unitdefs_post.lua

Posted: 22 May 2011, 01:39
by knorke
thanks, adding
newunit.filename = "xxx"
makes it work. seems like a bug that spring requires the filename to be present even if the unitdef is created in unitdefs_post?

Re: creating new units in unitdefs_post.lua

Posted: 22 May 2011, 02:34
by smoth
Filename?

Re: creating new units in unitdefs_post.lua

Posted: 22 May 2011, 03:28
by knorke
yes.

Code: Select all

newunit.name = "testunit"
newunit.objectname  = "cube.s3o"
newunit.script = "empty.lua"
newunit.filename = "blabla nonsense blablabla" <- is required due to how unitdefs are read
UnitDefs["testunit"] = newunit

Re: creating new units in unitdefs_post.lua

Posted: 22 May 2011, 05:10
by smoth
honestly dunno.