Having Lua coding problem

Hello everybody!

Having some questions and problems in lua leanguage…

-How do I use Local variable, for exemple do i need to use this variable for a simple print? Iam using corret for this file?
-When I have “maath” and use the varible print, it shows this “table” on console. I know, it should be just “math” and “print(math)”, but i find this, and would like to know if is ther some explanation.
-And most important problem is: When I use a simple string like;

math = (8+3+4)
print(math)

Variable “math.randomseed(os.time())” and “math.random” stop working. WHYYYY?

Anyways, thank you already for your help, this is probably a simple mistake, ez to solve…

link: https://replit.com/@TheUssual/Testing#main.lua

You overrode the math variable with an integer, which can’t have any functions on it. Simply don’t have a variable named math. If, while you’re defining a variable or function, the identifier you’re using (here, math) comes up in the suggestions while you’re typing, you shouldn’t use that identifier.

local result = (8+3+4)
print(result)

It’s better to always use local variables so you don’t override a variable with the same name in a different chunk (file or function). When you do use global variables (ones without local) you should start with a capital letter, e.g. Math, so it’s clear in future that you’re using a global variable which you expect to modify in other chunks.

Not sure what you mean.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.