In the previous lesson, we talked about struct scopes. It's not just for define a scope for structs, but it also affects the order the program is executed.
Well, there are two kind of struct scopes: "Scopes" and "Libraries".
Library -> It's the first thing that is executed in program. Everything put onto it will be executed before the most of code. So, it's useful for to put piece of codes that are used by many others. That's why it's called library. Example:
library testAPI
...
endlibrary
What if there are two libraries, which one will be executed first? Well, logically, the top-most on trigger editor, but it can become complicate. Sometimes the user don't know that and put the library in anywhere. What if a library requires other for work? It means the "other" needs to be read first. For that there's a special keyword:
library testAPI requires other, another
...
endlibrary
That way don't matter if one come before the other.
Now, scopes. Scopes are simply. They always come after the libraries, so it's useful to put pieces of code that needs libraries to work onto it, like spells. Example:
scope testSpell
...
endscope
Libraries and scopes have also a special keyword: initializer.
Initializer takes a function name and means that function will be executed when the scope is read, in the beginning of the program. Example:
scope testSpell initializer init
function init takes nothing returns nothing
// that will be executed when the scope is read
endfunction
endscope
Answer mentally:
- For what scope/library is?
- What is a library?
- What is a scope?
- What does "initializer" keyword means?
<<Previous>> <<Next>>
No comments :
Post a Comment