Question about 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)
+--- Thread: Question about Switch (
/showthread.php?tid=362495)
Question about Switch -
CoDeZ - 24.07.2012
Hey guys a question
pawn Код:
new Float:teehee
GetPlayerHealth(playerid,teehee);
Switch(teehee)
{
}
If i want to make a case after checking the HP value from 80 to 100
How can i do it using switch statment?
Re: Question about Switch - next-studio|TheKiller - 24.07.2012
Код HTML:
new Float:teehee
GetPlayerHealth(playerid,teehee);
Switch(teehee)
{
case 1 .. 80:
SendClientMessage(playerid, -1, "You have less than 80% of health");
default:
SendClientMessage(playerid, -1, "You have more than 80% of health.");
}
Re: Question about Switch -
Jeffry - 24.07.2012
Switch works with integers only, not with Floats.
https://sampwiki.blast.hk/wiki/Control_Structures#switch_2
You can convert your Float into an integer, and then use switch:
pawn Код:
new Float:teehee;
GetPlayerHealth(playerid,teehee);
new tmp[5];
format(tmp, sizeof(tmp), "%0.0f", teehee); //Not sure if 0.0f works, just try it. ^^
new health = strval(tmp);
switch(health)
{
case 80..100: {//Stuff here}
case 60..79: {//Stuff here}
case 40..59: {//Stuff here}
case 20..39: {//Stuff here}
case 0..19: {//Stuff here}
default: {//Either smaller 0 or bigger 100, O.o Hax!}
}
Cheers!
Re: Question about Switch -
CoDeZ - 24.07.2012
I know jeffry , just wanted to know how to make it from 80 to 100
Thanks next
Re: Question about Switch -
Vince - 24.07.2012
Quote:
Originally Posted by Jeffry
Switch works with integers only, not with Floats.
https://sampwiki.blast.hk/wiki/Control_Structures#switch_2
You can convert your Float into an integer, and then use switch:
pawn Код:
new Float:teehee; GetPlayerHealth(playerid,teehee); new tmp[5]; format(tmp, sizeof(tmp), "%0.0f", teehee); //Not sure if 0.0f works, just try it. ^^ new health = strval(tmp); switch(health) { case 80..100: {//Stuff here} case 60..79: {//Stuff here} case 40..59: {//Stuff here} case 20..39: {//Stuff here} case 0..19: {//Stuff here} default: {//Either smaller 0 or bigger 100, O.o Hax!} }
Cheers!
|
Floatround? Lol?
Re: Question about Switch -
leonardo1434 - 24.07.2012
it should be floatround or Float as vince started above. :P
Re: Question about Switch -
CoDeZ - 24.07.2012
Excuse me , what about if statments?
when i use " .. " it gives me an error.
Re: Question about Switch -
CoDeZ - 24.07.2012
BUMP
Re: Question about Switch -
[KHK]Khalid - 24.07.2012
When using
if, it should look like this:
pawn Код:
if(health <= 100 && health >= 80)
Re: Question about Switch -
Jeffry - 25.07.2012
Quote:
Originally Posted by Vince
Floatround? Lol?
|
Oh meh. I am so dumb.