ID:171021
 
I have having major problem with loops. I cannot find a decent example of a loop and if I did i'm not sure i'd understand it.

I'd like to run a level system that runs on time. The longer you in the more exp you get. The problem is that its an infinite loop! After so long it will be automaticly disabled because of...stack space? What can I do to make this system run without being turned off or causing major lag?

Turning off the worlds loop check is NOT a good idea btw 8)
I'd like to run a level system that runs on time. The longer you in the more exp you get. The problem is that its an infinite loop! After so long it will be automaticly disabled because of...stack space? What can I do to make this system run without being turned off or causing major lag?

Sounds like you're infinitely recursing. You probably want to show us how you're setting up the loop. Its also easy for us to show you how to increase effeciency if you give us something to work with,
Event though I may be wrong (It's hard to be right without an example). If you don't want the loop to stop, use the line
set background=1

So, for example,
mob/verb/Infinite_Loop_Song()
set background=1//Put it in the background.
src << "I know a song that gets on everybody's nerves.
sleep(3)
src << "Everybody's nerves.
sleep(3)
src << "Everybody's nerves.
sleep(3)
src << "I know a song that gets on everybody's nerves, and this is how it goes\c"
sleep(1)
src << ".\c"
sleep(1)
src << ".\c
sleep(1)
src << "."
spawn() Infinite_Loop_Song()//Do it again!!
In response to Theodis
I see. Its horrable coding =[. I see my first problem is im using like 3 procs. Proc goes to 2nd proc, goes to third proc, third proc starts 1rst proc over... Duh no wonder. I need to improve my logic and understanding of the DM language.

I'm going to figure this out myself. But if you could, in the example with the inf loop song, wont that majorly lag the game?
In response to Lilcloudy1
Lilcloudy1 wrote:
I'm going to figure this out myself. But if you could, in the example with the inf loop song, wont that majorly lag the game?

Well, actually, no. It would go on forever with no way of stopping it. It would drive everyone insane. But the lag would be about equal to the lag a conversation with a Say() verb causes.

Usually, however, infinite loops have the potential to lag the world down at incredible amounts. If possible, they should be avoided, and if necessary, should be treated with extreme caution in regard to efficiency.
In response to Wizkidd0123
I do beleave ive figured it out. That example helped alot and I remade the whole system and it seems to work.




mob
proc
EXPLOOP()
set background=1
if(src.inside==1)
src.pexp +=1
if(src.pexp >= src.maxpexp)
src.ranks+=1
src.pexp = 0
sleep(3)
spawn() EXPLOOP()
else
sleep(30)
spawn() EXPLOOP()
else
return

This isnt exactly and infinite loop is it since when the usr is no longer INSIDE it should turn off right? Any way to make this work better?
In response to Lilcloudy1
Instead of
if(src.inside==1)
, you should use
if(src.inside)
for more watertight coding. Also, you should probably be using while()(read it) anyway. This would be accomplished with
while(src.inside)


Nice job on finding a way around the loop though :)
In response to Lilcloudy1
Lilcloudy1 wrote:
> mob
> var/explooping = 0 // to track if they are already looping
> proc
> EXPLOOP()
> //set background=1 no real need for this
> if(explooping==1) return // make sure each mob only has one loop
> if(src.inside==1)
> src.pexp +=1
> if(src.pexp >= src.maxpexp)
> src.ranks+=1
> src.pexp = 0
> spawn(3)
> src.explooping = 0 // let them loop again
> EXPLOOP()
> else
> spawn(30)
> src.explooping = 0 // let them loop again
> EXPLOOP()
> // else This really not necessary
> // return

This isnt exactly and infinite loop is it since when the usr is no longer INSIDE it should turn off right? Any way to make this work better?

You can put how long to wait before spawning in the spawn() call itself. The sleep() procs you were using were actually hanging up the flow of the code until they timed out. Spawn() does not make the code wait, it automatically waits in the background until it times out, then executes the code. Also, it might be wise to check to see if they're already doing an EXPLOOP(), if so, return so you don't have numerous loops for the same mob.

~X
In response to Wizkidd0123
Wizkidd0123 wrote:
Instead of
if(src.inside==1)
, you should use
if(src.inside)
for more watertight coding. Also, you should probably be using while()(read it) anyway. This would be accomplished with
while(src.inside)

Nice job on finding a way around the loop though :)


Thank you very much. Its difficult for me to learn this language...I dont understand all the peices yet. while() I just started messing with, I never would have though of using while(src.inside) Thank you.

[edit] Oh man ive been here for damn near 5 years and i'm such a noob v_v;. I don't understand enough!
In response to Lilcloudy1
Don't worry about it, ive been creating games for 3 years. I've made about 50 games, 45 of which have never seen light due to the fact i left the idea.
In response to Tazor07
Dejavu to me ;)

Though i'm starting a serious game with a friend sometime soon . . . maybe :P

Btw, like to point out for()
Maybe not the best way to make a inf loop BUT it could make one, just, if your still learning the DM language you would find for() really usefull to loop trough just a specific kind of thing, and personally, i use nothing but lists and for() procs ;)

world/New()
..()
var/i = 1
for(i = 1)
world << "*Insane driving song playing on the background*"
sleep(600) //this would disply this message every minute