View Full Version : Loop
GhettoTrucker
07-18-2006, 06:20 PM
How do you make a loop in a script? Like if you want it to do the same cycle over and over again in a script. How do you do that?
Nightmist
07-18-2006, 07:54 PM
In ASH use
while() instead of
if()If your just wanting a infinite loop just stick "true" into the while.
Edit: Go have a read of http://kolmafia.sourceforge.net/ash_tutorial.html, Since it kind of already explains it in there if you dont get what I mean.
GhettoTrucker
07-18-2006, 08:35 PM
So pretty much do
while() and plug my code into the ()?
GoldenRatio
07-18-2006, 10:12 PM
A while loop will look like this
while(my_inebriety() < 15)
{
* * *drink(1,$item[shot of tomato schnapps]);
}
It reads pretty much how you'd expect: "while my inebriety is less than 15, drink 1 schnapps."
The part that goes into the () is the stopping condition, and the stuff between the {} is the code you want to happen while the stopping condition doesn't happen.
GhettoTrucker
07-18-2006, 11:26 PM
ok, i think i understand.
GoldenRatio
07-19-2006, 04:06 AM
Anything in particular you are trying to do?
GhettoTrucker
07-19-2006, 06:32 PM
No, just trying to figure out the loop stuff. Is it possible to have multiple while() and if() sections in a script? like say
while(my_adventures() < 0) <peak farm> and then have a
if(my_adventures() = 0) <drink ___> ?????
GhettoTrucker
07-19-2006, 07:50 PM
oh lol...wrong sign...lol
macman104
07-20-2006, 02:46 AM
No, just trying to figure out the loop stuff. Is it possible to have multiple while() and if() sections in a script? like say
while(my_adventures() < 0) <peak farm> and then have a
if(my_adventures() = 0) <drink ___> ?????
Yes it is. If you look at the scripts on here, many of them have multiple ifs, whiles, and such all over the place.
jw8191
07-20-2006, 06:18 AM
what's the proper syntax for a for loop? would anybody be kind enough to write me a 3 line example?
something along the lines
for x goes from 1 to 7 step 1
{
print("hi");
}
(attempts to print hi 7 times)
I know the first line of this is wrong, but i cant seem to find the right one.
thanks
edit: just so you know, i have searched for this, but searching the word "for" gives way too many results
holatuwol
07-20-2006, 06:28 AM
http://kolmafia.sourceforge.net/advanced.html#branches
for x from 1 upto 7 by 1
print( "hi" );
Powered by vBulletin® Version 4.1.12 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.