actions.lua Trouble
Posted: 16 Jan 2010, 00:00
Hi :) I am currently haveing an odd probleam whos fix is aludeing me
the probleam: I have two gadgets that both create buttons in unit menus ... they both work fine if only one is in the luarules folder BUT when BOTH are in luarules they dont work (no runtime error but there buttons dont show up in the units menue)...the gadgets are very simular because I made one from the other (I copy pasted one of them and then modded it) because of this approach I am sure they have some variable in common that needs to be diffrent
in addition to not working I get this lovely little error on my info log
error = 2, LuaRules/draw.lua, error = 2, LuaGadgets/gadgets.lua, [string "LuaGadgets/actions.lua"]:54: attempt to index local 'g' (a function value)
so I tracked down actions.lua and looked at what it was doing around line 54 and of course right around there is when actions.lua is doing the job of exicuting local function InsertAction(map, gadget, cmd, func, help)....wich looks like this
local function InsertAction(map, gadget, cmd, func, help)
local callInfoList = map[cmd]
if (callInfoList == nil) then
callInfoList = {}
map[cmd] = callInfoList //this is line 54 were the error is flaged
end
return InsertCallInfo(callInfoList, gadget, func, help)
end
now the function InsertCallInfo() is right above it and deals with 'g' wich is refrenced as haveing the indexing probleam in the error
local function InsertCallInfo(callInfoList, gadget, func, help)
local layer = gadget.ghInfo.layer
local index = 1
for i,ci in ipairs(callInfoList) do
local g = ci[1]
if (g == gadget) then
return false -- already in the table
end
if (layer >= g.ghInfo.layer) then
index = i + 1
end
end
table.insert(callInfoList, index, { func, gadget, help = help })
return true
end
...the error says its trying to index 'g' (wich is a variable in the function InsertCallInfo()) ... in the function g = ci[1] and I think this is the core of my probleam (or at least a place of confusion with me)
now this from the gathered info I get stumped and so have my questions
Question 1): Is it possible that there is indeed a variable in these two gadgets that is the same and as a result causing actions.lua to have a hard time? or am I barking up the wrong tree??
Question 2): how does the called variable callInfoList play into all this? it appears to be pulled from the gadgets but I am not very good with return commands and am likely confused... so ANY info on what this for loop
for i,ci in ipairs(callInfoList) do
would be VERY nice
Question 3): what would be a good next place to look? as close as I feel I cant connect the dots so any info would be greatly appriciated.
thanks for listening and for any info :)
the probleam: I have two gadgets that both create buttons in unit menus ... they both work fine if only one is in the luarules folder BUT when BOTH are in luarules they dont work (no runtime error but there buttons dont show up in the units menue)...the gadgets are very simular because I made one from the other (I copy pasted one of them and then modded it) because of this approach I am sure they have some variable in common that needs to be diffrent
in addition to not working I get this lovely little error on my info log
error = 2, LuaRules/draw.lua, error = 2, LuaGadgets/gadgets.lua, [string "LuaGadgets/actions.lua"]:54: attempt to index local 'g' (a function value)
so I tracked down actions.lua and looked at what it was doing around line 54 and of course right around there is when actions.lua is doing the job of exicuting local function InsertAction(map, gadget, cmd, func, help)....wich looks like this
local function InsertAction(map, gadget, cmd, func, help)
local callInfoList = map[cmd]
if (callInfoList == nil) then
callInfoList = {}
map[cmd] = callInfoList //this is line 54 were the error is flaged
end
return InsertCallInfo(callInfoList, gadget, func, help)
end
now the function InsertCallInfo() is right above it and deals with 'g' wich is refrenced as haveing the indexing probleam in the error
local function InsertCallInfo(callInfoList, gadget, func, help)
local layer = gadget.ghInfo.layer
local index = 1
for i,ci in ipairs(callInfoList) do
local g = ci[1]
if (g == gadget) then
return false -- already in the table
end
if (layer >= g.ghInfo.layer) then
index = i + 1
end
end
table.insert(callInfoList, index, { func, gadget, help = help })
return true
end
...the error says its trying to index 'g' (wich is a variable in the function InsertCallInfo()) ... in the function g = ci[1] and I think this is the core of my probleam (or at least a place of confusion with me)
now this from the gathered info I get stumped and so have my questions
Question 1): Is it possible that there is indeed a variable in these two gadgets that is the same and as a result causing actions.lua to have a hard time? or am I barking up the wrong tree??
Question 2): how does the called variable callInfoList play into all this? it appears to be pulled from the gadgets but I am not very good with return commands and am likely confused... so ANY info on what this for loop
for i,ci in ipairs(callInfoList) do
would be VERY nice
Question 3): what would be a good next place to look? as close as I feel I cant connect the dots so any info would be greatly appriciated.
thanks for listening and for any info :)