Help with weapondefs_post

Help with weapondefs_post

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Help with weapondefs_post

Post by Forboding Angel »

I want to do this:

Code: Select all

for id,wd in pairs(WeaponDefs) do
		wd.energycost = wd.damage.default * 0.05
end
Essentially, I want to take each weapon's total default damage, then divide that by 20, and whatever number that is, make it the energypershot value.

I'm doing something wrong. Can someone halp?
Last edited by Forboding Angel on 09 Apr 2013, 02:29, edited 2 times in total.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help with weapondefs_post

Post by knorke »

divide by 20 is not same as multipy with 0.2
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Help with weapondefs_post

Post by Forboding Angel »

My apologies. * 0.05 fixed
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Help with weapondefs_post

Post by Forboding Angel »

Update, I did Spring.Echo(wd.name) and it output the names of only the weapons in the weapons folder and apparently skipped the weapons housed in unitdefs.

Tried putting this:

Code: Select all

for id,wd in pairs(WeaponDefs) do
		wd.energycost = wd.damage.default * 0.05
		Spring.Echo(wd.name)
		Spring.Echo(wd.energycost)
end
In unitdefs_post, but keep getting this error:

Code: Select all

Error: Spring: Incorrect/Missing content:  Error in main(): Defs-Parser: [string "gamedata/defs.lua"]:38: [string "gamedata/defs.lua"]:26: error = 2, gamedata/unitDefs.lua, error = 2, gamedata/unitdefs_post.lua, [string "gamedata/unitdefs_post.lua"]:45: bad argument #1 to 'pairs' (table expected, got nil)
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Help with weapondefs_post

Post by Forboding Angel »

I figured it out. Long story short there is a function in my weapondefs_post that converts unitdef weapondefs to be usable in weapondefs post. I needed to have my little blurb in that function. THe moment I put it there everything was fine.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Help with weapondefs_post

Post by Jools »

for id,wd in pairs(WeaponDefs) do
That is line 45 in unitdefs_post? The error is that WeaponDefs is nil. Is that maybe not accessible from unitdefs_post?
Post Reply

Return to “Lua Scripts”