A little problem with 'switch'.
#1

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

Reply
#2

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.
Reply
#3

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";
}
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)