• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

What does local & function mean?

Status
Not open for further replies.

Bird

Banned User
Joined
Mar 19, 2019
Messages
12
Reaction score
0
Sorry if i sound like a complete noob but what does local & function mean? Sometimes i see the word local in front of a word and other times i see local in front of the word function and then there are more words and parentheses and more words separated by commas.

I really want to learn this stuff but i am having a hard time understanding it and the link i was given earlier to learn this is too complicated for me to understand. :(
 
If you have 2 lua scripts (separated files):
  • config.lua
  • system.lua
Inside config.lua
Lua:
local CONFIG_VERSION = "1.0.0"
SYSTEM_CONFIG = {
    foo = "bar"
}

Inside system.lua
Lua:
dofile("config.lua")

function onStart()
    print("Config loaded" .. CONFIG_VERSION) -- failed, CONFIG_VERSION is local
    print("foo = " .. SYSTEM_CONFIG.foo) -- worked, SYSTEM_CONFIG is global
end

Same thing goes with functions. If you use local function foobar() then it's scoped only to the file it's inside.
I didn't see your post before i replied but there is that word scope again. I asked this before what does scope mean and no one has answered it.
 
I thought that is what support was for to ask questions?
Sure, to ask specific questions that can be answered with a single post. Right now you went from one question to dozens completely different not related to the original.

I didn't see your post before i replied but there is that word scope again. I asked this before what does scope mean and no one has answered it.
If you know english then you should know just by the definition of the word "scope". It defines what given variable or function can reach. If it's local then it can reach only code in the file it's initialized. If it's global then the scope is unlimited.
 
I didn't see your post before i replied but there is that word scope again. I asked this before what does scope mean and no one has answered it.
There's also common sense, your brain and your friend Google y'know.
 
Sure, to ask specific questions that can be answered with a single post. Right now you went from one question to dozens completely different not related to the original.


If you know english then you should know just by the definition of the word "scope". It defines what given variable or function can reach. If it's local then it can reach only code in the file it's initialized. If it's global then the scope is unlimited.
How are these additional questions not related? I asked what local and function meant and people kept responding with the word scope. If you use a word I don't know of course I am going to ask what it means. I asked for examples and still I do not know what it means. Like what is a variable can you provide an example?
thats why the lady @Stigma gave a link to you, but I can guess you do not want to read. There is no one who can explain it better than Lua doc itself.
I don't mind reading but this person Stigma and several other people here don't seem to know how to teach. You don't give a book to a 1 year old and tell them to read if you're trying to teach them the ABC's.
There's also common sense, your brain and your friend Google y'know.
If I don't know what to look for then what good would using google do?
 
It doesn't load. What was that link to?
Just google "lua tutorial" - nothing else, just these two words.
This forum is not meant for explaining every god damn word related to scripting / programming.

This dude is trolling.
Oh god, please be true. It starts to hurt my brain.
 
I thought that is what support was for to ask questions?
No... not really. The support board is for support related to problems that you have within your server or scripts that you use. "Encountered an issue related to OpenTibia? Ask for support here". You haven't really specified a problem nor do you even have one. You're just uneducated and you're looking to learn the basics of programming -- which is fine. I respect that. But then you should be grateful for the useful links that you've been redirected to, instead of just blindly asking followup questions and expecting to be getting professional support, and questioning them when they're trying to help you.
 
He's been doing this for two or three years, guys. Don't mind him.
 
No... not really. The support board is for support related to problems that you have within your server or scripts that you use. "Encountered an issue related to OpenTibia? Ask for support here". You haven't really specified a problem nor do you even have one. You're just uneducated and you're looking to learn the basics of programming -- which is fine. I respect that. But then you should be grateful for the useful links that you've been redirected to, instead of just blindly asking followup questions and expecting to be getting professional support, and questioning them when they're trying to help you.
Not all of those links were useful and I am not expecting professional support just simple answers.
Just google "lua tutorial" - nothing else, just these two words.
Thanks I will google that now.
This dude is trolling.
Why would you say that? I see a lot of you have experience with scripts or am I wrong? Correct me if I am wrong but isn't it wise to ask those who know what they're doing questions?
Realized he was trolling long ago, that's why I stopped replying.
Just like I have questions I would like answered. I am taking the time to answer yours :)
He's been doing this for two or three years, guys. Don't mind him.
Who has? Me? I just got here like 2 days ago.
 
Status
Not open for further replies.
Back
Top