Adding to an array? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Adding to an array? (
/showthread.php?tid=364845)
Adding to an array? -
Luis- - 01.08.2012
Is this possible? I need something like this "new array = array();" like you'd do in PHP.
Thanks.
Re: Adding to an array? -
Squirrel - 01.08.2012
I think is something you are looking for
https://sampforum.blast.hk/showthread.php?tid=343172
Re: Adding to an array? -
Luis- - 01.08.2012
I dont want to sort them. Thanks though.
Re: Adding to an array? -
Arca - 01.08.2012
Check this out.
Source:
https://sampwiki.blast.hk/wiki/Advanced_Structures#Lists
Re: Adding to an array? -
Luis- - 01.08.2012
Already tried it. It wont work with my code.
Re: Adding to an array? -
Luis- - 01.08.2012
Bump.
Re: Adding to an array? - Disturn - 01.08.2012
An array is merely a list of elements. If a function returns an int type or character, the first element of the array retains the value of the assigned function.
pawn Код:
stock func()
{
return 'A';
}
main ()
{
new array[4];
array[0] = func();
printf("%c", array);
}
I'm still unsure if THIS is what you actually want though (it's just an example).
Re: Adding to an array? -
Luis- - 01.08.2012
I want to be able to add ints to an array. I have no idea how I can explain it.. Something like, when I type a command which chooses a random number, I want that random number to be added to an array.
Re: Adding to an array? - Disturn - 01.08.2012
Quote:
Originally Posted by -Luis
I want to be able to add ints to an array. I have no idea how I can explain it.. Something like, when I type a command which chooses a random number, I want that random number to be added to an array.
|
Then assign an element of the array with a value? I mean, that's all there is to it.
pawn Код:
main ()
{
new array[4];
for(new i = 0; i < sizeof(array); i++)
{
array[i] = random(10);
//printf("%d", array[i]);
}
}
Re: Adding to an array? -
Luis- - 01.08.2012
So, if I was to add a check to see if the chosen number has already been used, i'd do something like this?
pawn Код:
for(new i = 0; i < sizeof(UsedObjsID); i++) {
if(ChosenObj == UsedObjsID[i]) {
ChosenObj = randomex(0, TotalObjs);
format(string, sizeof string, "INFO: {FFFFFF}ObjectID: %d has already been used! Looking for another object", ChosenObj-1);
SendClientMessageToAll(COLOR_ASKQ, string);
format(string, sizeof string, "TEST: {FFFFFF}ObjectID: %d", UsedObjsID[i]);
SendClientMessageToAll(COLOR_ASKQ, string);
return 1;
}
}