Preventing infinite loops?

Posted by Arout on Sun 07 Nov 2004 03:19 PM — 4 posts, 15,142 views.

#0
Hi, I'm new to this and I keep having a piece of my code that has a do loop in it cause MC to freeze. I had read a topic before about how you're supposed to use triggers or timers or something to stop it from happening. How can I do that? Thanks.

Amended a little bit, It's a do until loop:

do until Clock1 = Clock2

Hope that helps some
Amended on Sun 07 Nov 2004 03:26 PM by Arout
USA #1
What are you actually doing with it?

Yes. Dont use any loops in MC, (well, unless its looping to send something 10 times or whatever) but no open ended loops.

Since MC freezes until the script is done, which means that it wont get anything from the server (and nothing will change) so if youre waiting on some variable to change to be equal to something (based on another trigger, or an alias, or whatever) then it wont ever happen.

So what exactly are you trying to do?

Do Until Clock1 = Clock2 doesnt really tell us much.
#2
Basically it's this:

I have a really small (9 friends) game that I'm experimenting on. I'm writing a script to automatically pick up milkbottles (an item on the game) and give them to someone else. they're usually dropped on the ground of the room you're in when you start exploring.

I want to do it in script because i want to know how to do stuff in it. i know i could do it in triggers and so on but i don't want to. it works like this: (I cut out the part about establishing the variables and everything to keep it easier to read)

do until Clock1=Clock2
world.execute "EXSTART stary " & Clock1 & "rhyne" ' start exploring in the stary area with the specified quest number (clock1) and the clan (rhyne)
[a world.execute to get the bottles]
world.execute "give" & Recepient & "=" & NumberOfMilkBottles ' give the recepient the milk bottles
world.execute "EXEND" ' end exploring
Clock1=Clock1+1
loop


in this example Clock2 is 20 and Clock1 starts as 1.

Is that more what you were looking for?
Amended on Mon 08 Nov 2004 04:33 PM by Arout
USA #3
What you would do with that piece of code right there, is send your lines, twenty times, and then stop.
If youre going to wait for something to happen (exploring) then it NEEDs to be strewn together with triggers.

However, you CAN keep track of the ammount of bottles you have (use a variable, I prefer MC variables, but you can use script variables if you want, just remember script variables will go away if you reload your script), and then stop after you get 20 (or whatever).

You'd just have the trigger to pick stuff up (it matches on "a milk bottle is here" or whatever) and then in that trigger, you'd check to see if your bottlecount was 20.

Oh wait. Your variables are clocks.
Youre trying to search until the time is up?

Then you'd need to use a timer. And have that timer stop you from searching (and give them to the person).

I think? I honestly still am rather confused as to what youre actually trying to accomplish. Thats why I left the first part, both paragraphs may or may not help you.
But yes, that explaination was better, but apparently still not good enough.

I dont understand why you (assuming that loop worked) would stop searching each time, and then start again.