SA-MP Forums Archive
A little problem with 'switch'. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: A little problem with 'switch'. (/showthread.php?tid=156666)



A little problem with 'switch'. - Ihsan_Cingisiz - 23.06.2010

Hello, i made a Stats System but i want to make that if the
variable is 0 that it writes no and is 1 writes yes, here's my script.

Quote:

public StatsMenu(playerid)
{
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
new file[64];
format(file, sizeof(file), "eSportsGaming/Users/%s.ini", playername);

new string1[100];
new string2[100];
new hours = dini_Int(file, "Hours");
new cash = dini_Int(file, "Cash");
new alvl = dini_Int(file, "AdminLevel");
new skin = dini_Int(file, "Skin");
new guide = dini_Int(file, "HasGuide");
new dlic = dini_Int(file, "DriveLic");

switch(guide)
{
case 0: guide = "No";
case 1: guide = "Yes";
}

format(string1, sizeof(string1), "Playing Hours: [%d] Cash: [$%d] Admin Level: [Lv. %d] Skin ID: [ID: %d]", hours, cash, alvl, skin);
format(string2, sizeof(string2), "Guide: [%s] Driving License: [%s] Sailing License: [%s] Flying License: [%s] Weapon License: [%s]", guide, dlic);

SendClientMessage(playerid, COLOR_GREEN, "[====================| Stats Menu |====================]");
SendClientMessage(playerid, COLOR_LGREEN, string1);

return 1;
}

Errors i get... The errors are on the two lines with the guide = "no"/"yes" :

Quote:

error 006: must be assigned to an array
error 006: must be assigned to an array




Re: A little problem with 'switch'. - Joe_ - 23.06.2010

https://sampwiki.blast.hk/wiki/Control_Structures#.3F:

pawn Код:
new guide = dini_Int(file, "HasGuide");

format(string2, sizeof(string2), "Guide: [%s] Driving License: [%s] Sailing License: [%s] Flying License: [%s] Weapon License: [%s]", (guide == 1) ? ("Yes") : ("No"), dlic);
I think that works, I barely use it, but that's how.

pawn Код:
(guide == 1) ? ("Yes") : ("No")
Means

pawn Код:
if(guide == 1)
{
"yes"
}
else
{
"no"
}
Ofcourse that there won't work, but format needs a string to be fed to '%s' and you can always use:

pawn Код:
format(str, sizeof(str), "%s", "Hello! :D");
It does not need a varible/array or anything.


Re: A little problem with 'switch'. - Hiddos - 23.06.2010

You're now trying to assign a string to a integer.

pawn Код:
new guide[3];

switch(guide)
{
case 0: guide = ''No'';
case 1: guide = "Yes";
}



Re: A little problem with 'switch'. - Joe_ - 23.06.2010

Hiddos, that won't work.

And even if it did, it would be long and a waste.

Your method

pawn Код:
new guide = dini_int(...);

new Guide[3];
format(Guide, "%s", (guide == 1) ? ("Yes") : ("No"));
format(str, sizeof(str)," Guide: %s ", Guide);
which is not needed.