Blockland Forums > Modification Help
Schedule Help
Red_Guy:
You need to move the schedule call outside the part that creates the new sky:
--- Code: ---package DayAndNight
{
function Time4(%obj)
{
.................
renderBottomTexture = "0";
noRenderBans = "0";
};
schedule(240000, 0, "Time4", %obj);
}
--- End code ---
however -- this will create an endless loop. make sure thats what you want.
Uristqwerty:
You can't put a schedule directly in a package.
1 million and up are converted to scientific notation as soon as you do any math on them, and schedule won't accept them like that. I think that if you write the number directly, schedule will accept larger numbers than 1000000.
Schedule is a function that schedules a function to be called a certain number of ms in the future. It cannot be put in a package (I think), it can not define a block of code, if you want something to repeat every # ms, it must schedule itself every time it runs.
Red_Guy: You missed some indentation.
--- Code: ---package DayAndNight
{
function Time4(%obj)
{
.................
renderBottomTexture = "0";
noRenderBans = "0";
};
schedule(240000, 0, "Time4", %obj);
}
};
--- End code ---
I would write something like this:
--- Code: ---function changeSky(%number)
{
switch(%number)
{
case 0:
... //Set a dawn sky
case 1:
... //Set a day sky
case 2:
... //Set a sunset sky
case 3:
... //Set a night sky
}
schedule(300000, 0, changeSky, (%number + 1) % 4);
}
changeSky(0);
--- End code ---
If only one or two values differ between the skies, I would put that sets the sky after the switch, and it would use variables set within the switch(). Less code duplication that way.
MegaScientifical:
--- Code: ---function changeSky(%num) {
switch(%num) {
case 0:
... //Set a dawn sky
case 1:
... //Set a day sky
case 2:
... //Set a sunset sky
case 3:
... //Set a night sky
}
schedule(300000, 0, changeSky, (%num + 1 => 4 ? 0 : %num + 1));
}
changeSky(0);
--- End code ---
The above would work, minus that there's no code setting for the cases. Your code would return 0.25 in the second cycle, thus breaking the script.
Uristqwerty:
% is the modulo operator, not division.
MegaScientifical:
--- Quote from: Uristqwerty on November 29, 2010, 01:21:06 PM ---% is the modulo operator, not division.
--- End quote ---
% (Modulus) Computes the integer remainder of dividing 2 numbers.
Bigger explanation, please...