![]() |
% and timevar
Ok, I usually pick up on things really easily, but I just can't pick up on this subject.
First, explain to me how exactly timevar is usefull. How it works and it's purposes. Second, how can the modulus (%) sign get the time? I have seen many scripts do this but I don't understand how it works. |
timevar uses the server time or something, its more ifficient than adding manually i guess...
% is not for getting time, its like until this.var=(this.var+1)%5; Means Add 1 to this.var until its value is 4 then go back to 0 and start again. |
since i've never really understood this either tell me if this is right...
say you had a fishing npc and you got 1 gralat for each 7 pounds of fish... could you use something like this where client.fish is how many pounds they've caught...? NPC Code: it would find the remainder and store it as "fish left" then take it away from the main number of fish and sell the bulk off... then replace the bulk with what was left over originally... so if you had 30 fish it would have remainder 2, take two away, sell the 28 for 4g, then replace your ammount with just 2 pounds theoretically... something i just kinda thought up from reading your guys' posts |
doesn't int() round to the nearest integer?
or does it always round down, just stripping off the decimels? cause it you had 13 fish i wouldn't want it to round 1.8 up to 2 and give you any free fish |
Quote:
var=int(var+0.5); |
Quote:
|
What is timevar2 then?
and What would this return? NPC Code:test = (mytimevar%(30*24))*2; |
Quote:
|
%
A simple example NPC Code: So let's say you have a npc that has onwall checks and you want it to turn in the other direction when it is at a certain distance from the wall. The above code will make it turn in the opposite direction. if dir==1. So if the npc has onwall detection while heading left, and it gets near the wall and performs this command it will change the direction to 3. So to break it down. dir=(dir+2)%4; =(1+2)%4 =3 - int(3 / 4) * 4 =3 - int(.75) * 4 =3 - 0*4 =3 - 0 So in the end it will be dir=3 There's another way to rotate the player or npc's. I think it's dir=(dir+1)%4; and it rotates clockwise or counterclockwise. Something like that. -- For timevar I have no clue. I never used it before and I'll be learning it now when people explain it in this thread I suppose. |
Quote:
|
Quote:
|
Quote:
And in some cases I'd use while(ndir > 3) instead of if(ndir > 3), just in case it is too big (Which is impossible at the given example). But why is % slower? I think I've heard that modulo is quite a complex floating point operation, but we normaly have FPUs integrated in the CPUs and the FPU operation would still be faster than interpreting 3 additional Graal Script Commands, wouldn't it? |
The point is, WHY would you create a floating point if your answer will never need it. Integer mathmatics takes less processor time that floating point.
I mean all the computer has to do is see if an integer is greater then a certain number and then if it is, set it to zero. but the MOD has to do a-int(a/b)*b to do the same operation. Shorter in the code, but more complex than it needs to be. |
| All times are GMT +2. The time now is 08:23 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.