Somebody can explain me this error ?? I'm new on Lua, and I wanna learn what I'm doing wrong!!
This is my Inventory.Lua
https://pastebin.com/KiUEajMm
I get this error:
ERROR: Unable to load module 'game_inventory': LUA ERROR:
/game_inventory/inventory.lua:117: attempt to index local 'itemWidget' (a nil value)
stack traceback:
[C]: in function '__index'
/game_inventory/inventory.lua:117: in function 'onInventoryChange'
/game_inventory/inventory.lua:77: in function 'refresh'
/game_inventory/inventory.lua:47: in function 'init'
/game_inventory/inventory.otmod:8:[#onLoad]:1: in main chunk
[C]: in function 'reloadModules'
/client_modulemanager/modulemanager.lua:149: in function 'reloadAllModules'
/client_modulemanager/modulemanager.otui:75: [#onClick]:2: in function </client_modulemanager/modulemanager.otui:75: [#onClick]:1>
The error means that you try to access a methode of itemWidget while it is nil. So if the possibility exits that itemWidget can be nil you have to check this:
if itemWidget == nil then
itemWidget:setStyle(InventorySlotStyles[slot])
...
end
Form the code you posted I can only guess why itemWidget is nil:
it is valid that inventoryPanel:getChildById('slot' .. slot) returns nil
a typo somewhere (e.g.: 'slot' .. slot instead of 'slot ' .. slot --> missing space)
wrong order: inventoryPanel:getChildById('slot' .. slot) only works after the init-function has ended or something similar
Related
When I attempt to run this part of my code an error shows up and says that it expected a string but it got a function, I'm new to coding and I can't figure out what's wrong. here's the error,
lua: game:47: bad argument #1 to 'find' (string expected, got function)
stack traceback:
[C]: in function 'find'
game:47: in main chunk
[string "<eval>"]:11: in main chunk
and here's the code
if (string.find(location,patternno2) ~= nul) then
print(" You decide that you will live your life as a hermit, alone and isolated. GAME OVER")
return
end
local patternyes2 = '^[yY][eE]?[sS]?$'
if (string.find(location,patternyes2) ~= nul) then
print(" Great! You leave for the land of Yore.")
print("You arrive at the castle of the previously mentioned king.")
end
here's where location is assigned value
print(" Do you go to the quest location")
local location = io.read
1.i,ve got error while implementing the game mario in games50 the error shows in the statemachine and its like
function StateMachine:change(stateName, enterParams)
assert(self.states[stateName]) -- state must exist!
self.current:exit()
self.current = self.states[stateName]()
self.current:enter(enterParams)
end
Error
src/StateMachine.lua:18: attempt to call method 'enter' (a nil value)
Traceback
src/StateMachine.lua:18: in function 'change'
main.lua:21: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
OK. So you invoke a function called "enter" which is contained in a table called "current", which is contained in another table passed in the hidden parameter "self" of the function "change".
You need first to check how the "change" function is called.
Check if it's something like:
xxxx:change(...
and not:
xxx.change(...
Because in the second version, the hidden "self" parameter (which will contain a reference to "xxx") is not provided.
Then, check is "self.current" is valid, right after self.current = self.states[stateName]() by printing it:
print(self.current)
If you see a table reference in your console, it's good.
At this stage, it will show you that the problem is the "enter" function which does not exists in the table returned by self.current = self.states[stateName]().
All your code sounds like you're using an external library from which you do not master the use. I advice you to start coding game with your own code, simple games, not using external code.
I've this code,
hook.Add( "PlayerSwitchWeapon", function( ply, oldWeapon, newWeapon )
if (tostring(newWeapon) == tostring(hololink_swep) ) then
print( "This weapon is speciall" .. newWeapon:GetClass() .. "." );
end
end );
When I execute it, I get,
Error(s), warning(s): lua5.3: source_file.lua:1: attempt to index a
nil value (global 'hook') stack traceback: source_file.lua:1: in main
chunk [C]: in ?
You need to put your scripts in a specific folder to make them run inside the games engine. I suggest you put them into garrysmod/addons/YOURADDONNAME/lua/autorun/server or client, the realm depends on what you want to do.
Where you need to place what is explained pretty good in the wiki under this link.
Every time I use this:
function love.draw()
love.graphics.setfont(love.graphics.newfon(50))
I get this error:
Error
main.lua:2: attempt to call field newfon (a nil value)
Traceback
main.lua:2: in function draw [C]: in function xpcall
How can I fix it ?
Lua is case-sensitive. The correct call is
love.graphics.setFont(love.graphics.newFont(50))
Okay so here is my function:
function button1()
mon.clear()
sleep(.25)
shell.run("movie")
end
Says: "attempt to index ? (a nil value)" for the shell.run("movie") line
I found out the problem.
You can't call shell.run() from another program using os.loadAPI()
so you have declared the mon variable and the function() there are two choices
switch the this command to shell.run("monitor side movie")
rewrite the program and in the function replace mon.setCursorPos(1.1) to term.setCursorPos(1,1) then when you run the program type "monitor side program" ok