Ah, thought I'd lost this.
Hope you don't mind my attaching it. 8)
In C, variables must be of certain types.
In POTC, the types available are:
int - an integer. -32767 through 0 through 32767.
bool - Subtype of int. Can only be 0 or 1 (true or false). note that in POTC true is #defined as 1 and false is #defined as 0 so you can use those words. In all other respects (use in operations, conversions, etc.) it's a normal int.
float - a `floating-point` number. I don't know offhand the number of decimal places POTC supports. Examples: -20.0, 3.14159, 1.414.
string - a string of character(s): i.e. "b", "the quick brown fox", "32767".
object - an object. Basically, a string that can have attributes (which are strings), that can have attributes, and so on. Check the Plea thread for more details.
ref - check the Plea thread for more details
aref - ditto
You can also convert between the three main types.
Whenever you assign a bool, int, or float to a string (whether to a string xxx variable, or an attribute of an object) it's converted to a string.
If you want to convert a string to a number you can use
int sti(string conv); // converts string to int
float stf(string conv); // converts string to float
note that you use sti for bools since bools are ints; if the string != 0, it's considered true. (have to check if negative values are also true; IIRC they are).
You can use MakeInt or MakeFloat as well; they take anything--string, int, float, bool--and output it correctly.
I've also added functions Roundup and Roundown to utils.c; they take floats and output ints.
And, note that floats and ints automatically convert--i.e. pass an int to a function that expects a float and it gets made a float; or assign a float to an int (int b = 12.2) and it gets automatically MakeInt'd.
So.
When you see a function definition like so:
void DoSomething(float num)
That means whenever you call it you need to pass a float to it (whether directly, or based on a variable)--like DoSomething(12.5) or DoSomething(var_my_float).
If there's more than one argument, it gets separated by commas.
You can then use the arguments in the function.
So in the example you have,
void LAi_NPC_Equip(ref chr, int rank, bool isWeapons, bool isGun)
that means that function takes, in order,
a reference, referred to in that function by chr
an int
and two bools.
So then whenever we call it, we must pass it the correct number of variables, of the correct type.
So again in the example:
LAi_NPC_Equip(chr, sti(chr.rank), true, true);
Chr must have been declared before that, and assigned a valid reference to a character; so chr is OK. sti(chr.rank) outputs an int, so rank is OK.
then two booleans are passed (true and true) so isWeapons and isGun are OK.
A note.
By default, variables passed to functions are passed as copies. Example:
Code:
void switch(int v1, int v2)
{
int temp = v2;
v2 = v1;
v1 = temp;
}
int t1 = 1;
int t2 = 2;
switch(t1, t2);
will do absolutely NOTHING because when switch() is called, the variables passed to it are copied into /new/ variables especially for it.
This is great if you make changes in the function that you /don't/ want saved; but it's not if you do want them saved. And besides it requires enough extra memory to make those copies.
If you /don't/ want copies made, you need to do two things.
1. Pass variables to the function with the & sign in front, i.e. switch(&t1, &t2).
2. In the function definition, use ref or aref instead of the specific variable type: void switch(ref v1, ref v2)
This is why you see the following often:
ref someref = &variable[pos]; that means that the ref is pointing to the variable, not a copy of the variable.
Once you've done that /once/, you can pass the ref itself without the &.
Examples:
1. Passing &variables
Code:
void switch(ref v1, ref v2)
{
int temp = v2;
v2 = v1;
v1 = temp;
}
int t1 = 1;
int t2 = 2;
switch(&t1, &t2);
2. Using refs to &variables
Code:
{switch(ref v1, ref v2) the same as above}
int t1 = 1;
int t2 = 2;
ref r1 = &t1;
ref r2 = &t2;
switch(r1, r2);