SA-MP Forums Archive
What's wrong with this code? - 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: What's wrong with this code? (/showthread.php?tid=345517)



What's wrong with this code? - Face9000 - 25.05.2012

pawn Код:
public WantedColor()
{
    for (new i; i < MAX_PLAYERS; i++)
    {
        switch(GetPlayerWantedLevel(i))
        {
            case 1...3:
            Ticketable[i] = Create3DTextLabel("Suspect - Ticketable",yellow,30.0,40.0,50.0,40.0,0);
            Attach3DTextLabelToPlayer(Ticketable[i], i, 0.0, 0.0, 0.7);
            SetPlayerColor(i,yellow);

            case 4...10:
            Arrestable[i] = Create3DTextLabel("Suspect - Arrestable",red,30.0,40.0,50.0,40.0,0);
            Attach3DTextLabelToPlayer(Arrestable[i], i, 0.0, 0.0, 0.7);
            SetPlayerColor(i,red);
        }
    }
}
2003 : error 001: expected token: ":", but found "..."
2003 : error 029: invalid expression, assumed zero
2003 : error 029: invalid expression, assumed zero
2003 : fatal error 107: too many error messages on one line

Line 2003:

pawn Код:
case 1...3:



Re: What's wrong with this code? - FalconX - 25.05.2012

Change

pawn Код:
case 1...3:
to

pawn Код:
case 1 .. 3:

and same for the second one.


Re: What's wrong with this code? - Face9000 - 25.05.2012

Now i get this:

Quote:

2005 : error 002: only a single statement (or expression) can follow each "case"
2005 : warning 215: expression has no effect
2008 : error 014: invalid statement; not in switch
2008 : warning 215: expression has no effect
2008 : error 001: expected token: ";", but found ".."
2008 : error 029: invalid expression, assumed zero
2008 : fatal error 107: too many error messages on one line

Line 2005:
pawn Код:
Attach3DTextLabelToPlayer(Ticketable[i], i, 0.0, 0.0, 0.7);
Line 2008:
pawn Код:
Arrestable[i] = Create3DTextLabel("Suspect - Arrestable",red,30.0,40.0,50.0,40.0,0);



Re: What's wrong with this code? - Mandrakke - 25.05.2012

pawn Код:
public WantedColor()
{
    for (new i; i < MAX_PLAYERS; i++)
    {
        switch(GetPlayerWantedLevel(i))
        {
            case 1 .. 3: {
                  Ticketable[i] = Create3DTextLabel("Suspect - Ticketable",yellow,30.0,40.0,50.0,40.0,0);
                  Attach3DTextLabelToPlayer(Ticketable[i], i, 0.0, 0.0, 0.7);
                  SetPlayerColor(i,yellow);
            }

            case 4 .. 10: {
                  Arrestable[i] = Create3DTextLabel("Suspect - Arrestable",red,30.0,40.0,50.0,40.0,0);
                  Attach3DTextLabelToPlayer(Arrestable[i], i, 0.0, 0.0, 0.7);
                  SetPlayerColor(i,red);
            }
        }
    }
}



Re: What's wrong with this code? - FalconX - 25.05.2012

Quote:
Originally Posted by Logitech90
Посмотреть сообщение
Now i get this:



Line 2005:
pawn Код:
Attach3DTextLabelToPlayer(Ticketable[i], i, 0.0, 0.0, 0.7);
Line 2008:
pawn Код:
Arrestable[i] = Create3DTextLabel("Suspect - Arrestable",red,30.0,40.0,50.0,40.0,0);
Basically you must put the brackets open and close after Case, this is how it works. like the following:-

pawn Код:
case 1 .. 3:
{
}
//res of the code
Original topic: https://sampwiki.blast.hk/wiki/Control_Structures#case


Re: What's wrong with this code? - Face9000 - 25.05.2012

Nope,doesn't work.


Re: What's wrong with this code? - Faisal_khan - 25.05.2012

Quote:
Originally Posted by FalconX
Посмотреть сообщение
Basically you must put the brackets open and close after Case, this is how it works. like the following:-

pawn Код:
case 1 .. 3:
{
}
//res of the code
Original topic: https://sampwiki.blast.hk/wiki/Control_Structures#case
This must be like this:
pawn Код:
case 1 .. 3:
{
    //res of the code
}



Re: What's wrong with this code? - FalconX - 25.05.2012

Yes mate that's what I meant, I put the "//rest of the code" down so he can continue his code like the above code

Like this:-

pawn Код:
case 1 .. 3:
{
    //rest of the code
}
// rest of your code.

-FalconX


Re: What's wrong with this code? - Mandrakke - 25.05.2012

Quote:
Originally Posted by Logitech90
Посмотреть сообщение
Nope,doesn't work.
If my code won't work so I will just leave the earth.


Re: What's wrong with this code? - FalconX - 25.05.2012

Quote:
Originally Posted by Mandrakke
Посмотреть сообщение
If my code won't work so I will just leave the earth.
Hahahha made me laugh in real life Well it should work :/

-FalconX