Create array in a loop?
#1

Hey guys, i hope you all are doing ok, well... Today i was wondering if i could create an array in a for, i did this a while ago in php, is there a way to do it in pawn?
ex:

In php:
Quote:

<?php
for ($i = 1; $i <= 2; $i++) {

$test[$i] = $i. ",";

echo $test[$i];

}
?>

What i want to do is something similar to this:
Quote:

new Skins[2] = {
1, 2,
};

But, in a "dynamic" way, i don't know if you get what im trying to say.

This is what i want to do, but it wont work:
Quote:

stock MueblesObjetosIDS(casaid)
{
new objects[2] = {
for(new x = 0; x < 2; x++)
{
x,
}
};
return objects;
}

You see, i want to make this work so i can use it on "e_selection" which requires an array with objects id on it...
Quote:

ShowModelSelectionMenu(playerid, "Tus muebles", Muebles, MueblesObjetosIDS(casaid), MueblesGuardadosEnCasa(casaid), -16.0, 0.0, -55.0);

Thanks for reading, i hope you can help me
Reply
#2

Pawn does not support dynamic memory allocation. All array sizes must be known at compile time.
Reply
#3

Quote:
Originally Posted by Vince
View Post
Pawn does not support dynamic memory allocation. All array sizes must be known at compile time.
Thanks for replying, so... What would you recommend me to do? i want to get some objects ids from a database (MYSQL) and then sort them like objectid1,objectid2 , etc. And then show them by using e_selection, what can i do instead of using arrays?, thanks.
Reply
#4

You could use another table and split the result wherever you need to use the data.
Reply
#5

Quote:
Originally Posted by CheezIt
View Post
You could use another table and split the result wherever you need to use the data.
Can you give me an example? please, thanks!
Reply
#6

Do like your php:
PHP Code:
stock MueblesObjetosIDS(casaid)
{
    new 
objects[2];
    for(new 
02x++)
    {
        
objects[x] = x;
    }
    return 
objects;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)