Log in

View Full Version : Proper way to write a variable using a percent?


paaco
10-17-2008, 12:37 AM
I made this what I thought it should be and it completely breaks the quest, can someone tell me the proper format for this in perl?
This is what I currently have, it completely breaks the quest.
if($mlevel >= .34 $ulevel) {

It is basically supposed to say:
if mob level is greater or equal to 34% of userlevel

AndMetal
10-17-2008, 02:54 AM
I think this would be the easiest way:

if($mlevel >= (.34 * $ulevel)) {
quest::say("Success!");
} else {
quest::say("Not quite...");
}


However, if you're just trying to make it an even third (33.3%), you could also do it like this:

if($mlevel >= ($ulevel / 3)) {
quest::say("Success!");
} else {
quest::say("Not quite...");
}


Hope this helps.

spoon
10-17-2008, 09:00 AM
Some times you'll see something like

if( ($mlevel * 3) >= $ulevel ) {
quest::say("Mob is OVER 1/3 of the user level");
} else {
quest::say("Mob is UNDER 1/3 of the user level");
}

which is mathematically equivalent but is processed on the integer side of the CPU which is significantly faster.

paaco
10-17-2008, 11:44 AM
Thanks guys :)