Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
Hi im trying to make a time based counter that adds 1 each sec that is not affected by lag.? |
||||
|
I tried this code i made but i get error and i cant find it error is: SyntaxError: missing ) after condition function count() |
||||
|
while(now!>endTime){ You cant use "!" there also there is no need for that because if you want to run while until now is smaller than endtime then you can use just < instead of > or <= https://www.w3schools.com/js/js_... |
||||
|
yes i found the bug but the script does not do the job |
||||
|
wrote: yes i found the bug but the script does not do the job this is not a good way to do that because your function will freeze the game while in while loop -it does the job but not the way it would be useful. Its a good way to learn javascript anyways. |
||||
|
Well im always learning trying to figure this out. |
||||
|
You can check out this project i made while ago.. there i use timers and this may give ideas: First overlay displays seconds and game framerate shouldnt affect it. https://5v3n.itch.io/coppercube-... it has behaviour that it uses behavior_GTime |
||||
|
this one should do the job: /* |
||||
|
If you want you can simply use every few seconds do something behavior and set 1000ms as the time and can then set to change a variable there, for example variable name = Timer; operation = Add; value = 1; also make sure to set this variable to zero before first drawing. Now what this will do is it will add a value to the timer every 1 second. For doing it with code. You wanted to achieve something like do something later action. I don't know where you are executing your code. So can't tell much. But you need to have either an OnFramevent or OnAnimate prototype if working inside a behavior. First you need to set your startTime and endTime[b] outside the onframe or onAnimate function. and then inside you onAnimte or onFrame event you need to compare it with the currentTime [b]now if the "now" is greater than your endtime you can increase the counter by +1.
something like this should work. Hope that helps |
||||
|
Sorry for my previous post which increases every cycle, I think I've overlooked "every sec". Of course, you still would have to put my result in relation to passed seconds in time |
||||
|
Ahaan, What a timing @hadoken, You commented while I was typing my response. @Coa, if you want you use the behavior posted by @hadoken as well. |
||||
|
thanks all for your help. I needed it to add 1 each 0.1 sec so your script hadoken did the trick |
||||
|
Here is what i made and use from all your help but i have one problem i cant fix i was trying to add <property name="timems" and i would only get 0 when calling this.timems variable what im i doing wrong /* |
||||
|
i found out why it did not work |
||||
|
here is the final code free to use and modify if you want it has property value timems that you can change in the cc editor if you dont know you need to save the code in text editor as the same name of the behavior
|
[ 1 2 ] Page 1 of 2 |
|