Post by Drake™ on May 21, 2010 20:48:20 GMT -6
Array - A simple list of information in programming.
There are many programming languages out that - well...use arrays - however, Starsiege has a huge difference when it uses arrays.
Global variables can be numbered using brackets - [ ] - in simple terms creating an array of information using one variable that is "$sample".
So for instance:
$sample is one variable but because of the numbers it can be used in multiple situations. One situation would be to check it for something we may need - so we run a for() loop.
Sample for() loop:
Basically:
How to use this in checking for an array? Simple:
Basically what we did here was create a function using another loop: while(). This loop checked to see how many spaces were used up in the array $sample. Then it sets that in the for() loop which gives it a limit of what number to check up to for information. Once the loop runs into a variable in the array that has the information we want - it will echo a message and stop the loop.
This is a short tutorial on scripting and I hope to make more for those wanting to learn more on it. If you need more information on how this all works - reply to the topic and I'll modify the post with more information.
There are many programming languages out that - well...use arrays - however, Starsiege has a huge difference when it uses arrays.
$sample[$sampleNumber] = "Information";
Global variables can be numbered using brackets - [ ] - in simple terms creating an array of information using one variable that is "$sample".
So for instance:
$sample[0] = "This";
$sample[1] = "Is";
$sample[2] = "Sparta";
$sample is one variable but because of the numbers it can be used in multiple situations. One situation would be to check it for something we may need - so we run a for() loop.
Sample for() loop:
for(%i = 0; %i > 2; %i++)
{
doSomethingFancyTwoTimes();
}
Basically:
for(create a variable here, check to see if the variable meets a criteria, increase or decrease the variable number)
{
doScriptsHereUntilCriteriaIsMet();
}
How to use this in checking for an array? Simple:
function arrayCount(%array)
{
%count = 0;
while(%array[%count] != "")
{
%count++;
}
return %count;
}
function checkArray(%object)
{
for(%i = 0; %i > arrayCount($sample); %i++)
{
if($sample[%i] == "Sparta")
{
echo("This is madness!");
return;
}
}
}
Basically what we did here was create a function using another loop: while(). This loop checked to see how many spaces were used up in the array $sample. Then it sets that in the for() loop which gives it a limit of what number to check up to for information. Once the loop runs into a variable in the array that has the information we want - it will echo a message and stop the loop.
This is a short tutorial on scripting and I hope to make more for those wanting to learn more on it. If you need more information on how this all works - reply to the topic and I'll modify the post with more information.