|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Fri Aug 10, 2012 3:13 am
Looping causing random freezeup |
As far as I can tell this shouldn't cause this loop to randomly freeze so apparently I'm doing something wrong. It has now froze up
Cmud twice.
Code: |
$numlimbs = %numitems(@jakariattacks)
#if ($numlimbs >= 2) {
limb1 = %item(@jakariattacks,%random(1,$numlimbs))
limb2 = %item(@jakariattacks,%random(1,$numlimbs))
#until (@limb2 != @limb1) {limb2 = %item(@jakariattacks,%random(1,$numlimbs))}
}
|
|
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Fri Aug 10, 2012 4:03 am |
If it's freezing, it sounds like it's getting stuck in an infinite loop. I can't see why that would happen with this loop, but if all you're trying to do is get two different items from the list, I would do it like this:
Code: |
$jakariattacks = @jakariattacks
$numlimbs = %numitems($jakariattacks)
#if ($numlimbs >= 2) {
limb1 = %item($jakariattacks, %random(1, $numlimbs))
#delitem $jakariattacks @limb1
limb2 = %item($jakariattacks, %random(1, ($numlimbs - 1)))
} |
After the first random limb is chosen, it removes that one from the list, and selects another random limb from what's left. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Fri Aug 10, 2012 10:55 am |
if you have a script with a big loop in it, its a good idea to stick '#WAIT 0' in there somewhere (preferably the start).
This will shunt it into a separate thread and perhaps not hang your system. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Aug 10, 2012 1:10 pm |
Is there ever a situation where @jakariattacks has only one item in it? That would produce an infinite loop because limb1 could never be different from limb2.
|
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Fri Aug 10, 2012 2:32 pm |
Rahab wrote: |
Is there ever a situation where @jakariattacks has only one item in it? That would produce an infinite loop because limb1 could never be different from limb2. |
Yes, that's why it has the numlimbs check to make sure there are two or more.
Thanks, Daern. I will try this solution. Also taught me I can use local variables as string lists.. Didn't know that. |
|
|
|
|
|