Loading...
  OR  Zero-K Name:    Password:   

Lua Error Report

3 posts, 220 views
Post comment
Filter:    Player:  
sort
Lua crashes with this error:


Under these circumstances:
1.
o = math.random(#guns)
table.insert(ud.weapons, guns[o][1])
ud.weapondefs[guns[o][2]] = guns[o][3]

NOTE: Replacing the first line with o = 1 doesnt cause a crash

2.

table.remove(guns, 1)

NOTE: table.remove(guns) doesnt crash
¨


EDIT: I narrowed the problem down to this:

new_w = {}
for k, v in new_w do
end

Whenever Zero Ks Lua loops over an empty array, it crashes. Unbelievable!

Code above for replication:
bmV3X3cgPSB7fQpmb3IgXywgXyBpbiBuZXdfdyBkbwplbmQK
+0 / -0
Are you saying that
quote:
for k, v in new_w do
end

doesn't crash when new_w has elements? That's weird, as I think your code is just invalid Lua. Look up pairs.
+0 / -0
Damn, youre right. There must be something else wrong with my code.
Here is something that REALLY doesnt work:

[...]
for wdname, wd in pairs(ud.weapondefs) do
for wi, w in ipairs(ud.weapons) do
if wdname == w["def"] then -- DOESNT WORK
[...]

Why is wdname never equal to w.def? Def must be equal to wdname, but the code doesnt trigger. If I set to "true", the code below triggers.

Example, weapons & weaponsdef
https://github.com/ZeroK-RTS/Zero-K/blob/master/units/cloakraid.lua
+0 / -0