attempt to index a nil value (global 'math')) - lua

I am using lua to make scripts in my game,
after updating the lua libs version from 5.1 to 5.3, an error appears on the game engine every time I use
math.X in a function
error :
Lua run doFile failed.attempt to index a nil value (global 'math'))
original code :
local value = math.random(1,10)
do you have any solutions ?

Related

unpack() not available on Lua 5.4?

I am reading a few tutorials on Lua and am trying to figure out how to use unpack(). I found an example that goes like this:
t = { "the", "quick", "brown" }
print (unpack (t))
The output should be "the quick brown".
What actually happens is this: "stdin:1: attempt to call a nil value (global 'unpack')".
How can I make unpack() work?
My Info:
OS: Mac OS 10.8
Lua: 5.4.2
Since Lua 5.2 unpack function is now at table.unpack
Function unpack was moved into the table library and therefore must be called as table.unpack.

Attempt to index global 'application' (a nil value) error

I'm trying to follow a Lua roguelike course to learn the language and by line 17 when I had attempted to run the program to see the title it came up with the error
lua: [string "<eval>"]:1: attempt to index global 'application' (a nil value)
stack traceback:
[string "<eval>"]:1: in main chunk
Here's all the code I've written and the link to the course
application:setOrientation(Application.LANDSCAPE_LEFT
application:setScaleMode("letterbox")
BLACK # 0x1A1A1A
application:setBackgroundColor(BLACK)
local fg = Bitmap.new(Texture.new("images/foreground.png", true))
fg:setX(1201)
stage:addChild(fg)
YELLOW # 0xDAD45E
local title = TextField.new(nil, "The Long Dark")
title:setTextColor(YELLOW)
title:setPosition(1320, 100)
stage:addChild(title)
https://programmingbymoonlight.com/roguelike-part-1-lua-and-gideros-an-introduction/
So I tried gideros and it worked properly, while it depends on lua it has it's own commands native to it's IDE framework.

Lua: "Attempt to index a nill value"

Hi so I just installed Lua and I have been playing around with it a bit. When I run a program that is supposed to calculate whether an integer is even or odd it throws an error at me.
Program:
function is_even(n)
if bit32.band(n,1) == 0 then
print('Even')
else
print('Odd')
end
end
This is the error that I receive:
stdin:2: attempt to index a nil value (global 'bit32')
stack traceback:
stdin:2: in function 'is_even'
(...tail calls...)
[C]: in ?
What am i doing wrong here? This program is supposed to work on Lua 5.2+ I currently have Lua 5.3.3 installed.
The bit32 library was deleted from Lua 5.3, because it now supports bitwise operators.

attempt to index global 'torch' (a nil value)

When I run a simple piece of code a = torch.Tensor(5,3) in ZeroBraneStudio, I receive the following error:
attempt to index global 'torch' (a nil value)
Does this mean that ZeroBraneStudio does not recognize Torch?
Make sure you select Torch as the interpreter (Project | Lua Interpreter | Torch-7) and configure the path to your th or luajit executable from torch (as described in this post).

LM_TranslateLayer:DrawMe(moho, view) error

this is old code (Lua 5.1)
if (self.wiggleMode == self.LAYER_MODE) then
if (self.wiggleChannel == self.TRANS_MODE) then
LM_TranslateLayer:DrawMe(moho, view)
i have try change to lua 5.3 but error on:
LM_TranslateLayer:DrawMe(moho, view)
error: attempt to index global 'LM_TranslateLayer' (a nil value)
My guess is that LM_TranslateLayer comes from an external library that is loaded via require. Make sure that this library does define global symbols.
In Lua 5.1, require automatically defined a global table to hold the module's content. So, require"foo" definedfoo`.
In Lua 5.2 this changed and the idiom is now local foo = require"foo".
Check how the library that defines LM_TranslateLayer is loaded.

Resources