EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Proper way to write a variable using a percent? (https://www.eqemulator.org/forums/showthread.php?t=26535)

paaco 10-17-2008 12:37 AM

Proper way to write a variable using a percent?
 
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:
Code:

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:
Code:

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
Code:

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 :)


All times are GMT -4. The time now is 08:37 AM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.