Question about Switch
#1

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?
Reply
#2

Код 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.");
}
Reply
#3

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!
Reply
#4

I know jeffry , just wanted to know how to make it from 80 to 100
Thanks next
Reply
#5

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?
Reply
#6

it should be floatround or Float as vince started above. :P
Reply
#7

Excuse me , what about if statments?
when i use " .. " it gives me an error.
Reply
#8

BUMP
Reply
#9

When using if, it should look like this:

pawn Код:
if(health <= 100 && health >= 80)
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
Floatround? Lol?
Oh meh. I am so dumb.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)