Trouble with timers

You must understand the Game Editor concepts, before post here.

Trouble with timers

Postby Athistaur » Wed Aug 24, 2011 10:03 am

Hello,
So far I have been able to solve most of my issues by lurking. I'm developing a game for the iPad and i have some troubles with timers.
The simple task I intend to solve with timers is the following:
My characters talk with each other. I set a text. Wait... I remove the text.
I already implemented a state machine to allow for complex conversations.Mostly by switch and some helpful functions.
My problem is with the wait part.
First approach was to create a timer 3000ms and once it timed out start the next iteration of th state machine. Destroying the timer and create a new one as needed. Didn't work because once a timer is created it seems to exist forever. Destroy timer seemed to do nothing. Creating a new timer seemed to only work if the timer has a new unique name.

The next approach was to create a periodic timer at startup and use it as clock. Whenever I need to wait I set a real value to the desired time. This value is decreased in the "clock timer" and once it reaches 0 it fires up the state engine again. This last approach works great.
However, once on the iPad the last approach results in frequent crashes. So far it seems that the problem appears when I try to set a new timer value at the same time I change the timer value in the clock timer. So... A classic multithread problem.
Before I include a semaphore in my script I pose a few questions:
Is there a reliable way to stop and restart a timer and to change the time on the timer?
Are there known bugs that lead to crashes on the iPad ?
Is my assessment of the issue realistic or am I on the wrong track?
What is the save minimum time a timer should have? 500ms? 100ms?
Athistaur
 
Posts: 10
Joined: Tue Aug 16, 2011 2:54 pm
Score: 1 Give a positive score

Re: Trouble with timers

Postby skydereign » Wed Aug 24, 2011 9:10 pm

Athistaur wrote:My problem is with the wait part.
First approach was to create a timer 3000ms and once it timed out start the next iteration of th state machine. Destroying the timer and create a new one as needed. Didn't work because once a timer is created it seems to exist forever. Destroy timer seemed to do nothing. Creating a new timer seemed to only work if the timer has a new unique name.

Someone else was mentioning that timer problem. Not sure what you are doing, but I posted a working example here.
http://game-editor.com/forum/viewtopic.php?f=2&t=6722&#p75288

The lowest a timer should be I believe is 13ms, so 500 shouldn't be a problem. But, if you continue to have problems with gE's timer system, you can always use a variable timer. Essentially set it at some number, and each frame reduce it by 1. Then when it reaches 0, activate the code you want. I usually don't use gE's timers due to the inability to destroy another actor's timers and this simple method (also you have more control of the timer this way).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Trouble with timers

Postby Athistaur » Thu Aug 25, 2011 5:28 am

Thank you,
Destroying another actors Timer is exactly what i was doing. Strang that it is not possible, but that explains the behavior.
I'll have a look at your example, thank you :-)

I was already able to Track down the cause of the crash and it had nothing to do with the timer. I learned that sound isn't included in the export package and needs to be moved to the IPad manually. (I'm using geplayer at the moment.)
Sorry for being misleading.

So problem solved, I'm back on track.

Cheers,
Athistaur
Athistaur
 
Posts: 10
Joined: Tue Aug 16, 2011 2:54 pm
Score: 1 Give a positive score

Re: Trouble with timers

Postby ikarus » Thu Aug 25, 2011 6:10 am

Yep, and it's still not working with me. What I did was I created a cnt variable that I changed each time the timer when off and only did certain things at certain counts. So let the timer run forever, I worked around it.
By the way, the example you posted skydereighn worked oddly but it still didn't for me in my biggy game. I just figured it's one of those issues ge has when you get a lot of scripts and timers going at the same time. It's a bug in the editor but not the engine it seems cause I get a shitload of bugs all the time for weird reasons, but they hardly ever show up in the exported versions. Or I just have to restart ge and then it works. For instance, when I try to skip levels it'll fire things only supposed to go off in level one even though I've made it absolutely concrete that they should only go off in their level. When I restart ge, it works, or if I export it, it works. So my view: Don't sweat it, it's a fluke with the editor most likely and won't show up in the final game once exported ^-^
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest