Arrays
Arrays are useful in many ways. You probably won't use arrays if you are a beginner but you should know what they are and how they are used. Let me show you how we can use arrays:
$foodAmount["human"] = 10;
$foodAmount["dog"] = 5;
$foodAmount["cat"] = 3;
$foodAmount["goldfish"] = 1;
$feed[0] = "human";
$feed[1] = "dog";
$feed[2] = "cat";
$feed[3] = "goldfish";
$feedCount = 4;
Now this is saying something like, how many pounds of food do we need to feed each animal (yes, humans are animals lol). So let's do a for loop to see how many each animal needs.
for(%i=0;%i<$feedCount;%i++)
{
//get the current animal in the array $feed and store it to %animal
%animal = $feed[%i];
//get the food amount from the array $foodamount and store it to %foodAmount, %animal being the current animal
%foodAmount = $foodAmount[%animal];
//echo the animal and it's food amount
echo(%animal SPC %foodAmount);
}
OUTPUT:
==> "human 10"
==> "dog 5"
==> "cat 3"
==> "goldfish 1"
Do you see how useful that is?
$foodAmount["dog"] = 5;
$foodAmount["cat"] = 3;
$foodAmount["goldfish"] = 1;
$feed[0] = "human";
$feed[1] = "dog";
$feed[2] = "cat";
$feed[3] = "goldfish";
$feedCount = 4;
Now this is saying something like, how many pounds of food do we need to feed each animal (yes, humans are animals lol). So let's do a for loop to see how many each animal needs.
for(%i=0;%i<$feedCount;%i++)
{
//get the current animal in the array $feed and store it to %animal
%animal = $feed[%i];
//get the food amount from the array $foodamount and store it to %foodAmount, %animal being the current animal
%foodAmount = $foodAmount[%animal];
//echo the animal and it's food amount
echo(%animal SPC %foodAmount);
}
OUTPUT:
==> "human 10"
==> "dog 5"
==> "cat 3"
==> "goldfish 1"
Do you see how useful that is?
We can also do multidimensional arrays. Let me give you an example:
$inventory["blockhead1",0] = "sword";
$inventory["blockhead1",1] = "dagger";
$inventory["blockhead2",0] = "bow";
$inventory["blockhead2",1] = "arrows";
This is pretty self explanatory. Blockhead1's first inventory slot is a sword and his second slot is a dagger.
Blockhead2's first inventory slot is a bow and his second slot is arrows.
That's really it for arrays.
$inventory["blockhead1",0] = "sword";
$inventory["blockhead1",1] = "dagger";
$inventory["blockhead2",0] = "bow";
$inventory["blockhead2",1] = "arrows";
This is pretty self explanatory. Blockhead1's first inventory slot is a sword and his second slot is a dagger.
Blockhead2's first inventory slot is a bow and his second slot is arrows.
That's really it for arrays.