So, first off let's cover some basic knowledge you should have for almost any type of programming; data types. For EQ2Emu LUA scripts in general, the only types you need to understand are
Strings,
Pointers, and
Variables.
1. Variables
A variable is just that - like in algebra, it's a term that holds a value. To create a variable you must do what is known as "declare" it. To do this you just either type the name of the variable followed by an equal sign and then put a value on the other side (assigning the value to that variable), or you may type local followed by the variable name (honestly I'm not sure the difference

). You may assign any type of data you wish to a variable. Examples:
Code: Select all
Zone = GetZone(NPC)
X = GetName(NPC)
I don't expect you to know all the details for these functions at this point, but you can probably guess by looking at them

. Basically what these two statements have done is assign the variable
Zone with the zone pointer for the zone
NPC is in. More on pointers later, just trust me for now. The variable
X ran the function GetName(
NPC), which returns the string value of the
NPC's name.
X now holds the value of that
NPC's name.
2. Strings
A string is basically some text that is treated as just that - text. All you need to do to treat some text as a string, is enclose it in either double quotes (") or single quotes ('). When using a string, everything you put into it is treated as one entity. In other words you can write words that would otherwise be considered a variable, without it using the value of that variable. Certain functions require strings specifically for certain parameters, we'll cover parameters in the next section.
What you need to keep in mind with strings, when you use the same type of quote you used to start the string, the string ends. In other words if your string contains either a single or double quote, you should start the string with the other type of quotation.
Let's say you have a rather complicated string that contains both inside the string, what you then need to do is what's known as Concatenation. All this means is combine two strings, and you do this by placing two periods between the strings, here's an example.
Code: Select all
"Hello there! It's so cold out! Can you teach me how to make a" .. '"snowman"?'
Which evaluates to the text
Hello there! It's so cold out! Can you teach me how to make a "snowman"? (I'm not a wordsmith

)
3. Pointers
A pointer is kind of like a shortcut. Every Spawn and Player, and other values inside the server have a reserved address in memory for them. A pointer is like a link that points to that address. Almost
ALL functions will use a pointer of some kind, in at least one of the parameters. To get these pointers, you generally pass them from one function to another, or there are other functions you may use to get a pointer, and you can either use that function directly in another function, or save the pointer value to a variable.