Hello there,
I have a couple of questions regarding the title

I have this piece of code in my
main.lua:
local myGame = require("game")
stage:addEventListener(Event.MOUSE_DOWN, function(e)
myGame.mouseDown(e.x, e.y)
end) |
and in my
game.lua:
local Game = {}
function Game.mouseDown(ex, ey)
-- local mposx = ex / TILESIZE
-- local mposy = ey / TILESIZE
-- print(mposx, mposy)
print(ex, ey)
end |
My problem is that when I try to do ex / TILESIZE gideros throws the error: attempt to perform arithmetic on global 'TILESIZE' (a nil value)
That's weird because print(ex, ey) works just fine. Do I need to convert ex and ey to some kind of int?
Thank you for your help. Peace!
Comments
You didn't declare global variable 'TILESIZE' (or declared it as local somewhere outside of 'game.lua' file).
Btw if you want to avoid globals like
TILESIZE@32
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
I have declared TILESIZE as Game.TILESIZE. My mistake was using TILESIZE and not Game.TILESIZE. Super quick answer thank you a ton!
Thank you also for the macro.
My gideros quest continues, youpi!
Peace and love!
eg:
tileWidth@32
gameWidth@20
zoom=5
pixels=tileWidth*gameWidth*zoom
will effectively be in bytecode:
pixels=640*zoom
So the interpreter will only need to search for one variable (zoom), if you had them as variables then it would have had to search for all 3 variables so it would have taken longer.
Likes: Apollo14, MoKaLux
https://deluxepixel.com