Adding to an array?
#1

Is this possible? I need something like this "new array = array();" like you'd do in PHP.

Thanks.
Reply
#2

I think is something you are looking for
https://sampforum.blast.hk/showthread.php?tid=343172
Reply
#3

I dont want to sort them. Thanks though.
Reply
#4

Check this out.

Source: https://sampwiki.blast.hk/wiki/Advanced_Structures#Lists
Reply
#5

Already tried it. It wont work with my code.
Reply
#6

Bump.
Reply
#7

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).
Reply
#8

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.
Reply
#9

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]);
    }
}
Reply
#10

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;
        }
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)