- Home /
Do something every each multiple of 1000..
I have a char that add's 750 to the "turncounter" variable every each move, and i wanted to put an npc which would move in a random direction everytime the "turncounter" hits 1000, 2000, 3000, etc.
So for 750 - 1000 it would work like that: player move, npc stays at same position (750 - 1000) player move, npc move (1500 - 1000) player move, npc move (2250 - 2000) player move, npc move (3000 - 3000) player move, npc stays (3750 - 3000)
etc. How to do that ? Preferably JS.
Answer by Stormizin · Jun 20, 2013 at 01:25 PM
Try something like that, actually in C#:
public int result = 0;
public int multipler = 0;
void Update(){
//Numbers increasing(Using multipler variable) ...
if(multipler % 1000 == 0){
//do stuff you want
}
}
Converted to JS
public var result : int = 0;
public var multipler : int = 0;
function Update(){
//Numbers increasing(Using multipler variable) ...
if(multipler % 1000 == 0){
//do stuff you want
}
}
But this makes the code only if the turn counter is at 3000, then 6000 etc. I want it to notice if eg, the variable jumps between 750 and 1500.
if(multipler >= 750 || multipler <= 1500){
//Do what you log
}
$$anonymous$$y question is: Do you want to know when the variable is between 750 and 1500? Or do you want to know where the variable is jumping 750 numbers?
I want to know IF the variable hit full thousands, while jumping by 750 each "turn".
You can use the var result to check if the divisor has the rest equals integer, then you will know if is 1000, 2000, 3000 etc.
Answer by MariuszKowalczyk · Jun 20, 2013 at 04:11 PM
To do what you want, you should probably do this:
var counter : int = 0;
function Update()
{
counter += 750; //example
if (counter >= 1000)
{
counter -= 1000;
//move your npc here
}
}
But then it keeps adding 750 every frame.
That's why I wrote //example. You can put that part when you need, the rest is important and doing what you want.