Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
zyloch
Newbie


Joined: 29 May 2020
Posts: 8

PostPosted: Mon Sep 23, 2024 4:19 pm   

Loop keeps getting aborted.
 
I have a script I wrote that basically repeats an attack as long as @botting is equal to 1.
Basically the script goes like this:

@while (@botting = 1) {
#while (@MobsToKill > 0) {
attack_function
#WAIT 2000
}
#step
}
}

However for some reason it keeps getting aborted, even no nothing triggers botting to equal anything other then 1, to abort it out of the while loop. What's the cause of this and is there a better way to write an attack function that would actively spam an ability every 2 seconds?
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 873
Location: USA

PostPosted: Mon Sep 23, 2024 7:03 pm   Re: Loop keeps getting aborted.
 
zyloch wrote:
I have a script I wrote that basically repeats an attack as long as @botting is equal to 1.
Basically the script goes like this:

@while (@botting = 1) {
#while (@MobsToKill > 0) {
attack_function
#WAIT 2000
}
#step
}
}

However for some reason it keeps getting aborted, even no nothing triggers botting to equal anything other then 1, to abort it out of the while loop. What's the cause of this and is there a better way to write an attack function that would actively spam an ability every 2 seconds?


Loops with unusual conditions that do things like #WAIT are funky.

#ALARM {*2} {<<your stuff, this is not valid code>>}

will fire every two seconds. Within the alarm, you can decide what to do based on @botting and other flags.

I'd toss an ID on the alarm to make it easy to turn off (such as if some macro has set @botting to false).
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2420
Reply with quote
zyloch
Newbie


Joined: 29 May 2020
Posts: 8

PostPosted: Mon Sep 23, 2024 8:10 pm   
 
So I tried that loop at one point, but it won't work. It basically spams a bunch of #Alarm loops that will fire after 2 seconds, but there's a hundred of them. It doesn't actually stall between each fire.
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 873
Location: USA

PostPosted: Thu Sep 26, 2024 5:56 pm   
 
zyloch wrote:
So I tried that loop at one point, but it won't work. It basically spams a bunch of #Alarm loops that will fire after 2 seconds, but there's a hundred of them. It doesn't actually stall between each fire.


I'm not sure what you mean by 'tried that loop'. Put an alarm in the loop? That's not what I meant.

A completely separate alarm will fire once every two seconds. Inside, you can check your botting and other variables. Or you can turn the alarm on and off at the same time as you would be updating the botting variable.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Fri Sep 27, 2024 12:10 pm   
 
You have clearly put Tarn's #ALARM inside your trigger.
Yes, this will spawn many instances of the alarm.

It was also not the suggestion given to you.
But rather, an issue of interpretation.

Tarn is suggestion one instance of the alarm, that you would then simply update the script it is running.
It is effectively its own slow loop, and you only need to define what happens per iteration.

He also suggested an ID (which would prevent the infinite population btw).
Code:
#ALARM "slowLoop" {*2} {do something}


If you prefer a one shot alarm that fires once and deletes itself, use a + instead of the *
Code:
#ALARM "oneShot" {+2} {do something}



#HELP #ALARM from the command line will pull up the help file for more information on how to use alarms.
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Fri Sep 27, 2024 12:27 pm   Re: Loop keeps getting aborted.
 
zyloch wrote:
I have a script I wrote that basically repeats an attack as long as @botting is equal to 1.
Basically the script goes like this:

@while (@botting = 1) {
#while (@MobsToKill > 0) {
attack_function
#WAIT 2000
}
#step
}
}

However for some reason it keeps getting aborted, even no nothing triggers botting to equal anything other then 1, to abort it out of the while loop. What's the cause of this and is there a better way to write an attack function that would actively spam an ability every 2 seconds?

Cleaned up your code would be more like:
#IF ((@botting) AND (@mobsToKill)) {#RAISE onAttack}
if either variable evaluates as 0 (or null) it won't fire

But then you need to define the event (your attack_function):
#EVENT onAttack {do something}

#STEP only applies to slowwalking
Loops just keep going until they finish, unless you #BREAK out or #EXIT.
Bots.... require more triggers to detect end conditions (killing mobs), handle cleanup (updating variables), and then #STEP (if applicable).
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Fri Sep 27, 2024 4:35 pm   
 
A simple method would be:

Your simple loop that repeats every 2 seconds:
Code:
#ALARM "autoKill" -2 {this is your attack_function}


A toggle for said simple loop.
Code:
#IF ((@botting) AND (@mobsToKill)) {#T+ autoKill} {#T- autoKill}


And your cleanup/update script. Might need to add any looting commands for your game.
Code:
#TRIGGER {Your kill message here} {mobsToKill=(@mobsToKill-1)}
_________________
Discord: Shalimarwildcat
Reply with quote
zyloch
Newbie


Joined: 29 May 2020
Posts: 8

PostPosted: Wed Oct 02, 2024 4:43 pm   
 
Ok. I'll give it another go. Thanks for the response.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net