About arrays
#1

Hello everyone , i'm trying to make pickups storing them in a array

Example :

pawn Код:
new variable[10];

public OnGameModeInit()
{
    variable[0] = CreatePickup(0,1,0,0,0,-1);
    return 1;
}
I'm adding to each one a function using the statement switch but as far i know i can't use arrays in switch.. is there another way to do this?

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    switch(variable[])
    {
        case 0:
        {
            //
        }
        case 1:
        {
            //
        }
        case 2:
        {
            //
        }
    }
    return 1;
}
Thanks!.
Reply
#2

You can't do this with a switch-case statement.
You can however loop through your array and search for the pickupid.
Eventually you could use a switch-case after the loop, as soon as you find the index in your array.

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    new index;

    for (index = 0; index < sizeof(variable); index++)
    {
        if (variable[index] == pickupid)
        {
            // You can do something here

            // Then end the search through the array, as the pickup was found
            // The For-loop will be exited, but "index" will still hold the value where the pickup was found
            break;
        }
    }

    // Here, "index" still holds the index of your array where the pickup was found, and can be used by a switch-case statement
    switch(index)
    {
        case 0:
        {
            //
        }
        case 1:
        {
            //
        }
        case 2:
        {
            //
        }
    }
    return 1;
}
Reply
#3

Thank you PowerPC that was all i need!
+REP.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)