Blockland Forums > Modification Help

Question(s)

Pages: (1/6) > >>

Placid:

I'm attempting to run a for loop to do stuff with an array. I'm using a global variable, how would I go about getting the number of variables in the array? I've tried $_.getcount(), which doesn't work.


--- Quote from: Placid on March 19, 2011, 02:35:09 PM ---I've actually got another question; I've been trying to add a weapon to someone's inventory through a script. I've been looking at the addItem script, but I can't seem to figure out where I'm going wrong. I've got it cycling through the variables, but it can't seem to tell whether the slot is empty or not.

--- End quote ---

So, how would I go about this? Any help is appreciated.

otto-san:

What I always did is have a variable that keeps the amount of variables in it like this:

$value[0] = "value";
$value[1] = "value";
$values = 1;

then just do the for loops with the variable values

edit:

So of course when adding that, you have to do $values++;, but that should be given.

Bauklotz:


--- Quote from: Placid on March 19, 2011, 10:48:09 AM ---array

--- End quote ---

Blockland doesn't have arrays. It's as simple as that.

otto-san:


--- Quote from: Bauklotz on March 19, 2011, 12:17:52 PM ---Blockland doesn't have arrays. It's as simple as that.

--- End quote ---
Dohoh. They're still arrays, just a very dumb form of them.

Chrono:


--- Quote from: otto-san on March 19, 2011, 12:22:57 PM ---Dohoh. They're still arrays, just a very dumb form of them.

--- End quote ---
Not actually arrays, but much as a replacement for them.

Expanded on your first post, this is how you'd do something.

$value[$values] = "player 1";
$value[$values++] = "Player 2";
$value[$values++] = "Player 3";
$value[$values++] = "Player 4";
$value[$values++] = "Player 5";
$values++;

for(%x=0;%x<$values;%x++)
{
echo($value[%x]);
}

Will print to the console:
player 1
Player 2
Player 3
Player 4
Player 5

Pages: (1/6) > >>

Go to full version