switch statement - 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: switch statement (
/showthread.php?tid=302792)
switch statement -
Luis- - 10.12.2011
Can anyone tell me whats wrong with this?
pawn Код:
forward OnPlayerPickUpDynamicPickup(playerid, pickupid);
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
switch(pickupid)
{
case LowClassCar:
{
GameTextForPlayer(playerid, "~g~Low Class Car Dealership~n~~r~/buycar", 6000, 3);
}
case VIPCar:
{
GameTextForPlayer(playerid, "~r~VIP Dealership~n~~r~/buycar", 6000, 3);
}
case CourierInfo:
{
ShowPlayerDialog(playerid, 1905, DIALOG_STYLE_MSGBOX, "Courier Help", "{FFFFFF}When doing this job, you're basically delivering supplies to the city of San Andreas. A red marker will appear on your map after you type {00B3FF}/work{FFFFFF}. We hope you find some interesting ideas for this job!", "Okay", "");
}
case HeliPad1LS:
{
SetPlayerPos(playerid, 1771.7668,-2425.3403,26.2578);
}
case HeliPad1LSE:
{
SetPlayerPos(playerid, 1771.3595,-2432.6167,13.5547);
}
}
return 1;
}
I am getting these errors:
Код:
C:\Users\BooNii3\Scripts\Project Avaition 0.3d\gamemodes\projectaviation.pwn(5159) : error 008: must be a constant expression; assumed zero
C:\Users\BooNii3\Scripts\Project Avaition 0.3d\gamemodes\projectaviation.pwn(5163) : error 008: must be a constant expression; assumed zero
C:\Users\BooNii3\Scripts\Project Avaition 0.3d\gamemodes\projectaviation.pwn(5167) : error 008: must be a constant expression; assumed zero
C:\Users\BooNii3\Scripts\Project Avaition 0.3d\gamemodes\projectaviation.pwn(5171) : error 008: must be a constant expression; assumed zero
C:\Users\BooNii3\Scripts\Project Avaition 0.3d\gamemodes\projectaviation.pwn(5175) : error 008: must be a constant expression; assumed zero
Re: switch statement -
sciman001 - 10.12.2011
Try putting LowClassCar and the other cases into " " ex:
"LowClassCar"
If that doesnt work, Sorry, but idk.
Re: switch statement -
Luis- - 10.12.2011
That's obviously not going to work.
Re: switch statement -
Flyfishes - 10.12.2011
If the variables like 'LowClassCar' was created in another callback and not global it won't work. Cretae them outside any callback and change their value inside a callback if you need to.
Re: switch statement -
MadeMan - 10.12.2011
You can't use variables with
switch. You have to use
else if
Re: switch statement -
Ash. - 10.12.2011
Quote:
Originally Posted by MadeMan
You can't use variables with switch. You have to use else if
|
This^
You have to use static integers for switch statements, you should use if statements, or you could use the ternary (triadic) operator.
Re: switch statement -
Scenario - 10.12.2011
Are all of your cases defines?
Re: switch statement -
Phanto90 - 10.12.2011
Quote:
must be a constant expression; assumed zero
|
You can't use variables.
You need a code that should not change during execution, so i suggest a macro #define PICKUPID idpickup or simply an enumeration if you know pickupid
Example:
Код:
enum{
pickupinfo1,
pickupinfo2,
pickuphouse1,
pickuphouse2
}
My suggestion is to use if statements because pickup are very dynamic (at least in some gamemodes...)
If you doesn't have a dynamic gamemode that creates and destroyes pickup in game then you can use macros or enumeration.
Best Regards
-P