Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Concerning Infinite Loops  (Read 4848 times)

0 Members and 1 Guest are viewing this topic.

Igorrr

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 130
  • Ugh...Ughugh!!!!!!
    • View Profile
    • Struggle For Life And Honour
Concerning Infinite Loops
« on: April 26, 2004, 05:48:49 AM »

This is no How Do I..? question but rather what happens if I do too much ;-)

For my game I am using many infinite loops. A loop for the ingame time. A loop for the day and night transition. A loop for the battle behaviour of your enemies. A loop in the stats window checking the enemies and your life points.
I am already thinking about alternatives to these infinite loops.
But I wanted to ask generally if there could be any problems if I use too many or is it just system dependent?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Concerning Infinite Loops
« Reply #1 on: April 26, 2004, 07:03:47 AM »

The  number of those "threads" isn't that much important. What really matters is the Sleep() time. You should leave the sleep time as long as possible, to give the engine enough time to do its other tasks. Many of those scripts you've mentioned don't need to be executed like every 10 milliseconds so you can safely increase the waiting time.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

McCoy

  • The cocido eater
  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 365
  • Spurrrrrrring
    • View Profile
    • Spur Games
Re: Concerning Infinite Loops
« Reply #2 on: April 26, 2004, 03:10:04 PM »

But, be careful, and think very much if it's really imprescindible to use a loop for the task you want to accomplish. I used a loop in Fred for a task that could be done even better just with events, no loop at all. It caused me a lot of pain & bugs until I finally came to the way of doing it with events instead of loops. So first think about other options, and finally, if you think there's no other way, use loops. But as Mnemonic said, the sleep time is what really makes the difference.
Logged

Click here to sign my sig!

Igorrr

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 130
  • Ugh...Ughugh!!!!!!
    • View Profile
    • Struggle For Life And Honour
Re: Concerning Infinite Loops
« Reply #3 on: April 26, 2004, 04:07:35 PM »

Thanks for the infor McCoy, I was actually thinking about replacing some actions with events. Now there is something that I do not understand and before beginning a new thread I am sure you could help me here.

I have tested and even I called MyEvent which I use on my monster object. If I handle that event in my monster.script there is no problem. But if I try to handle it in a different script (battle.script) that I attach to that monster for battle when it does not work, although telling me that the monster can handle the event (CanHandleEvent = Yes).
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Concerning Infinite Loops
« Reply #4 on: April 27, 2004, 07:14:57 AM »

Thanks for the infor McCoy, I was actually thinking about replacing some actions with events. Now there is something that I do not understand and before beginning a new thread I am sure you could help me here.

I have tested and even I called MyEvent which I use on my monster object. If I handle that event in my monster.script there is no problem. But if I try to handle it in a different script (battle.script) that I attach to that monster for battle when it does not work, although telling me that the monster can handle the event (CanHandleEvent = Yes).

Just for the record: we've found the problem; there's an engine limitation, scripts running in an infinite loop cannot process events. In that case, either the loop or the event handlers must be moved to another script.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Igorrr

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 130
  • Ugh...Ughugh!!!!!!
    • View Profile
    • Struggle For Life And Honour
Re: Concerning Infinite Loops
« Reply #5 on: April 27, 2004, 11:02:47 AM »

Yep that did it :-) Thanks
Logged
 

Page created in 0.043 seconds with 23 queries.