SA-MP Forums Archive
help with arrays - 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: help with arrays (/showthread.php?tid=372053)



help with arrays - lidor5353 - 25.08.2012

Hey,
I am ashamed that I forgot this important section, but I need a little help.
I am trying to index array, but it doesnt work.

My Code:
Код:
 
new a[6][] = {"M4", "RPG", "DOUBLE_RPG", "DOUBLE_M4", "TRIPLE_RPG", "SAW"}; // Attacks pickups



Re: help with arrays - shitbird - 25.08.2012

What errors are you getting, exactly?
- zip - disregard this.


Re: help with arrays - lidor5353 - 25.08.2012

Quote:
Originally Posted by shitbird
Посмотреть сообщение
What errors are you getting, exactly?

I'm not sure, but I believe you're forgetting the NULL character at the end, please correct me - anyone - if I'm mistaken.

I believe your code right now, is the same as this:
pawn Код:
new a[6][] = {"M4", "RPG", "DOUBLE_RPG", "DOUBLE_M4", "TRIPLE_RPG", "SAW", "\0"}; // 7 cells, but you've only given it 6.
If I'm right, you're going to need 7 cells (counting the NULL character) in order for you to avoid exceeding array size errors.

pawn Код:
new a[7][] = {"M4", "RPG", "DOUBLE_RPG", "DOUBLE_M4", "TRIPLE_RPG", "SAW"}; // a +1
tnx for the comment.
i tried to do this:

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

    for(new i = 0; i<sizeof(a); i++)
        if(pickupid == a[i]) GivePlayerMoney(playerid,10000);
    return 1;
}
while using the array "a", and get this error:
Код:
error 033: array must be indexed (variable "a")
about the null character - first time im hearing about that. (and i tried, but it does not worked)


Re: help with arrays - shitbird - 25.08.2012

God damnit. Disregard my comment about the null character, I messed up when I was reading your code.
I'm not entirely sure on your code, I'll see if I can find out, otherwise wait for someone else.

EDIT: I guess you will have to do something like this, unless someone else can help you out.

pawn Код:
#include    <a_samp>

// new pickup[] = {0, 1, 2, 3};
// new pickup[4];

public OnGameModeInit()
{
    pickup[0] = CreatePickup(params);
    pickup[1] = CreatePickup(params);
    pickup[2] = CreatePickup(params);
    pickup[3] = CreatePickup(params);
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i = 0; i<sizeof(pickup); i++)
    if(pickupid == pickup[i]) GivePlayerMoney(playerid,10000);
    return 1;
}



Re: help with arrays - lidor5353 - 25.08.2012

Quote:
Originally Posted by shitbird
Посмотреть сообщение
God damnit. Disregard my comment about the null character, I messed up when I was reading your code.
I'm not entirely sure on your code, I'll see if I can find out, otherwise wait for someone else.

EDIT: I guess you will have to do something like this, unless someone else can help you out.

pawn Код:
#include    <a_samp>

// new pickup[] = {0, 1, 2, 3};
// new pickup[4];

public OnGameModeInit()
{
    pickup[0] = CreatePickup(params);
    pickup[1] = CreatePickup(params);
    pickup[2] = CreatePickup(params);
    pickup[3] = CreatePickup(params);
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i = 0; i<sizeof(pickup); i++)
    if(pickupid == pickup[i]) GivePlayerMoney(playerid,10000);
    return 1;
}
I tried something else... I tried to not define slots, like this: "new a[] = {"m4");"
and it work....


tnx anyway!