-
assigned issue to
Wait(time in ms); function
Please add the Wait function.
Its really needed for some cases.
Comments (9)
-
reporter -
function sleep(time){ var start = date.getTime(); while(start+time > date.getTime()) true; return; }
try this
-
reporter ok and what this did with CPU load?
I need it for plants growing.... So for massive number of blocks.
Last time when I tried to make my own time function.. I did Killed server's ticks.
-
you want that your plants grow after a long time ?
-
reporter I want to make plants that grow on time.. not just randomly. The idea is that Ill make block with:
tickrate = 999999999999999;
onUpdate[0] = "mod.loadScript('plant_grow.js');";
plant_grow.js:
var rand = Math.floor(Math.random()*10) + 3; // 3 - 10
var time = rand * 60000; // ms to min
Wait(time); // 3 - 10 minutes
// and so on..
-
Instead of doing it as math.random, just have it change onUpdate... I don't understand why you would use that function if you don't want it to be random... Look at my example for wheat on the wiki and instead of loading a script on update just use onUpdate[] = "world.setBlockMetadata(position, world.getBlockMetadata(position) + 1);"; if you're using metadata for the different stages of your plant. Otherwise, replace setBlockMetadata with setBlockId and replace world.getBlockMetadata(position) + 1 with mod.getBlockId().
-
reporter Because I want to make even little random interval for growing offset. Its just for better feeling if you are watching how that plants grow. FE: The idea is that every plant will grow for one level after 60 sec + some little random offset (0 - 10 sec). Thats max. 70 sec for one level and min. 60 sec.
How can I do that with today version of CS2 ? :)
-
reporter BTW there are many cases when the Wait function is welcome ;)
I think that this is not something hard to code for X2.
So PLEASE PLEASE PLEASE
-
I'm not saying adding in a wait function would be useless, but for your particular problem there is a way around it, even if it is a little long winded. Set the tickrate of the growing block to 1200, that makes it update every 60 seconds. Then have it run a function that 'adds' time at random, I'll put a shortened version of that up for you. Unless you can set a range for tickrate, but I can't test that until I get home. Setting a range would give you about a 4.5% chance of it taking any half-second interval between 60 and 70 seconds (1200-1400 ticks)
- Log in to comment