Enter / Exit
#1

So far I have this:

pawn Код:
command(enter, playerid, params[])
{
    switch(arrowpickup[])
    {
    //
    }
    return 1;
}
I have the pickups declared and they display, they are also entered into the array shown below:

pawn Код:
// Arrow Array
new arrowpickup[100];

stock showarrowpickups()
{
  arrowpickup[1] = CreatePickup(1318, 1, -2440.8452, 524.1761, 29.9064, -1);
  arrowpickup[2] = CreatePickup(1318, 1, -2453.5320, 504.0138, 30.0802, -1);
  print("Arrow Pickups loaded");
 
}
The error is on the "switch" line, the error is: "bensamp.pwn(944) : error 029: invalid expression, assumed zero".

Can anyone please help me? Or see as to where I have gone wrong.
Reply
#2

Switch statements can only be used for integers.

pawn Код:
arrowpickup[]
is a string.
Reply
#3

Okay, how should I turn it into an integer?

Basically, I'm trying to assign an ID to the pickup, and use the ID in the case statement rather than writing a million if statements.
Reply
#4

actually it looks like an array of ids to me.

i think this is something closer to what you want.
pawn Код:
command(enter, playerid, params[])
{
    new param = strval(params);
    switch(param)
    {
        case arrowpickup[0] :
        {
        //some code here
        }
        case arrowpickup[1] :
        {
        //some code here
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
actually it looks like an array of ids to me.

i think this is something closer to what you want.
pawn Код:
command(enter, playerid, params[])
{
    new param = strval(params);
    switch(param)
    {
        case arrowpickup[0] :
        {
        //some code here
        }
        case arrowpickup[1] :
        {
        //some code here
        }
    }
    return 1;
}
Thank you very much, I cannot add this into my code right now but I will asap. Repped.
Reply
#6

btw have you looked at this system?
http://forum.sa-mp.com/showthread.ph...85#post1456585

makes adding these very easy!


good luck with ya mode!

~j5
Reply
#7

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
btw have you looked at this system?
http://forum.sa-mp.com/showthread.ph...85#post1456585

makes adding these very easy!


good luck with ya mode!

~j5
That looks good but, I'm trying to use as little includes and I would rather it be a command rather than just run into it and TP, thanks though mate ^^
Reply
#8

You can't have variables as cases in a switch statement. You should save the location of the pickups in a variable and loop through it.
Reply
#9

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
You can't have variables as cases in a switch statement. You should save the location of the pickups in a variable and loop through it.
In PAWN you can have variables as cases.

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid) //don't know why you would use a command to enter pickups
{
    switch(pickupid)
    {
        case arrowpickup[1]:
        {
            //do stuff
        }
        case arrowpickup[2]:
        {
            //do stuff
        }
    }
}
Reply
#10

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
In PAWN you can have variables as cases.

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid) //don't know why you would use a command to enter pickups
{
    switch(pickupid)
    {
        case arrowpickup[1]:
        {
            //do stuff
        }
        case arrowpickup[2]:
        {
            //do stuff
        }
    }
}
I get two errors regarding the two cases themselves.

pawn Код:
C:\Users\Ben\Desktop\SF-RP\gamemodes\bensamp.pwn(542) : error 008: must be a constant expression; assumed zero
C:\Users\Ben\Desktop\SF-RP\gamemodes\bensamp.pwn(546) : error 008: must be a constant expression; assumed zero
Not to sure what the error is either.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)