Author Topic: Do I understand this code snippet correctly?  (Read 785 times)

Code: [Select]
function AirDragonArmor::onTrigger(%this, %obj, %trig, %press) {
if(%trig == 2 && %press && getsimtime() >= %obj.lastjump+400)
{
%obj.forbidJump = true;
%obj.addVelocity("0 0 24");
%obj.playThread(0, "Jump");
ServerPlay3D(AirDragonJumpSound, %obj.getPosition());
%obj.lastjump = getsimtime();
}
else Parent::onTrigger(%this, %obj, %trig, %press);
}

I ripped the above code out of the Player_Dragons pack.

In the line:
Code: [Select]
if(%trig == 2 && %press && getsimtime() >= %obj.lastjump+400)

Is this checking if a key as been pressed (%press), that the pressed key is the jump key (%trig == 2), and checking if it has been 400 milliseconds since the last time the function was triggered successfully (getsimtime() >= %obj.lastjump+400)?


Instead of getsimtime() >= %obj.lastjump+400, try (getSimTime() - %obj.lastJump) >= 400

(Mouse over on the codes to see why)
« Last Edit: December 26, 2013, 04:55:41 PM by Advanced Bot »

those are functionally the same, right?

those are functionally the same, right?
Yes, but it will have a tiny issue.

i don't get the issue? could you put some examples down?


um it doesn't matter which way you do it, they both are identical

Instead of getsimtime() >= %obj.lastjump+400, try (getSimTime() - %obj.lastJump) >= 400

(Mouse over on the codes to see why)
dude
a > b + c
a - b > c
It's the same goddamn thing?