love2d just wont accept some codes - lua

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))

Related

How do I fix Error Syntax error: main.lua:5: unexpected symbol near '20' on love

might be a dumb beginner question but When I run my code:
function love.draw()
love.graphics.print("Hello World", 400, 300)
end
function love.load()
20, 20, 60, 20
end
it give me the error message:Error
Syntax error: main.lua:5: unexpected symbol near '20'
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: at 0x7fff3e0d31d0
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
I just wanna add values
In Lua writing meaningless literals like that are not accepted, you need to know what you want to do with those numbers, do you want to print them? Store them in a variable? Call another function with them?
Line 5 contains a syntax error, like the error says.
If your intent was to return a list from the love.load function, you need something like:
function love.load()
return {20, 20, 60, 20}
end

I can't find the problem in my code, do you see it?

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

can anyone help me to get the error cleared?

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.

attempt to index local 'itemWidget' (a nil value)

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

Lua Minecraft ComputerCraft function issue

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

Resources