|
Post by GH Games on Dec 31, 2016 17:19:46 GMT
Hi, how does one create a Scripted Timer?
Example of what I mean:
void Main(){ //after 1 second... iObjectShow(Object to show)
//after another 2 seconds... iObjectHide(Hide the first one) iObjectShow(Show the second one) } How do I create the Timer parts? I think it uses a float but I'm not sure.
Thank you in advance!
P.S. I'm writing this at 17:20 GMT 31/12/2016, so happy new years eve everybody!
|
|
|
Post by Karvy on Dec 31, 2016 21:46:40 GMT
it should use a float if you like the timer count with decimals, but if you want it very simple just use int value
void Main(){
int timer; timer++; //count if(timer == 60){ //after 1 second...
iObjectShow(Object to show)
}
if(timer == 120){ //after another 2 seconds...
iObjectHide(Hide the first one)
iObjectShow(Show the second one)
} }
oh and happy new year to you too! (here isn't yet :p)
|
|
|
Post by GH Games on Dec 31, 2016 22:01:46 GMT
Yes thank you Karvy, I went away did my research and found out how to do it another way right after I created this post. Now I have two ways xD thank you bro.
|
|
|
Post by n_iron on Jan 6, 2017 22:58:26 GMT
Hi everyone, When i saw the script above I realized it just won't work it has a major flaw.
Every time the processor reads this it will keep re-setting the 'timer' variable to 0. The 'int timer;' must be a global variable to work in this case, so it must be put outside the 'Main(){ }' function.
Next is it will keep counting if the script is not stopped by another object. This is unnecessary processing and can add to frame rate drop.
The answer it below
int timer = 120; void Main(){
if(timer > 0){ timer--; if(timer == 59){ //after 1 second... iObjectShow(Object to show); } if(timer == 0){ //after another 2 seconds... iObjectHide(Hide the first one) iObjectShow(Show the second one) } } }
Now this code will run until timer is '0' and won't count any further unless 'timer' is increased above zero. The only thing it does is check if timer is more than zero.
n_iron
|
|