[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  DoAfter bug?

DoAfter bug?

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Ranthony   (12 posts)  [Biography] bio
Date Mon 24 May 2004 06:08 PM (UTC)

Amended on Mon 24 May 2004 06:09 PM (UTC) by Ranthony

Message
I've got a script that when triggered is supposed to cast the same spell until I fall below a certain amount of mana. Instead of using timers, I just did a DoAfter in a while loop. A trigger is set to call a function that sets a boolean when my mana drops. However when this train function is called, mushclient simply locks up. If I do a DoAfter outside of the loop, it executes the command immediately with no pause. Here's the snippet.


function train()
{
	var counter = 0;
	
	while(aboveManaLimit)
	{
		world.Note("Iteration " + counter);
		var temp = counter  % 3;   //every third cast, check where.
		if(!temp)
		{
			world.Execute("where");
		}
	
		world.DoAfter (3, spellName);  //This is what's failing.
		counter++;
	}

	goToSleep();

}
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #1 on Mon 24 May 2004 06:15 PM (UTC)
Message
MUSHclient waits for the function to return before doing anything else, that's why it locks up. You can't have delays in scripts, unless you use DoAfterSpecial or make a timer...

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Ranthony   (12 posts)  [Biography] bio
Date Reply #2 on Mon 24 May 2004 07:20 PM (UTC)
Message
From what I observe, that world note is printed over and over again with no delay. MUSHclient isn't waiting for anything at all, but instead continuously iterates through that while statement. I changed the while loop to iterate five times before breaking out.

When ran, this is what I see now.


Iteration 0
where
Iteration 1
Iteration 2
Iteration 3
where
Iteration 4
Sleeping.
sleep

c plumbum                
c plumbum
c plumbum
c plumbum
c plumbum


we get to the sleep part in less than a second.


So MUSHclient continues executing statements after the DoAfter statement just as it does with a timer(which is expected for the addTimer). What I had expected however was for MUSHclient to stop at the DoAfter statement, wait for the specified period of time, send the command and then resume execution of the lines below. If this is intended behavior then I'll have to figure something else out. I've tried a timer, same behavior. Am I going to have to kludge this and do something like setting up a timer that fires once, starts a timer which casts the spell, creates another timer which casts the spell again, ad nauseum? I'd prefer to not have to just spam a set number of commands in which will allow me to react if someone who can kill me enters the area. Maybe I'll give that timer/function combo calling itself a shot.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #3 on Mon 24 May 2004 07:57 PM (UTC)

Amended on Mon 24 May 2004 08:02 PM (UTC) by Flannel

Message
Thats the point of DoAfter, what it does is makes a temporary timer.

With MC, like poromenos said, MC waits for your script to finish before doing anything. This includes recieving output from the server, or input, or anything.

MC is funcionining correctly with the notes. Youre doing your loops, and each time you loop, youre making a temporary timer with the spellname, and then going back up and starting over.

All DoAfter does is makes the old proccess of creating a self destructing timer with temporary flags and the like a bit easier.

As for reacting, your current situation wont allow any input from the server until the script is done, so you wouldnt be able to react at all.

If youre simply trying to cast a spell every X, with wheres being sent, there are more efficient ways. If I knew all the details, Id supply a solution. Is it spell every 3 seconds? and where every 9? or the other way around, and then you have a trigger to tell you when youre past your mana limit? or...

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 24 May 2004 11:42 PM (UTC)
Message
Quote:

What I had expected however was for MUSHclient to stop at the DoAfter statement, wait for the specified period of time, send the command and then resume execution of the lines below.


Say you do a DoAfter for one hour. Do you really want MUSHclient to "stop" for one hour? Not process your menus, commands, input from the MUD and so on?

The script engine (eg. VBscript, JScript) does not let me "break out" of a script and resume execution later. Thus, DoAfter is a simplified way of telling MUSHclient to set up a timer which will "do something after" the nominated interval, however that is queued up and done once the entire script finishes.

There are many posts about this in the forum, you are not the first to wonder that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ranthony   (12 posts)  [Biography] bio
Date Reply #5 on Tue 25 May 2004 12:29 AM (UTC)
Message
Good points there. I had the notion that it may have worked that way from a few threads I had read that suggested DoAfter as a form of a sleep, pause or wait function. Flannel, basically what I'm trying to do is cast a particular spell ever two or three seconds, which is roughly a bit more than the actual lag from casting the spell. Before each cast of the spell I'd like to make sure my mana hasn't dropped below a set point, and if it has dropped below that point put the character to sleep. The first and every third cast I'd like to preempt the casting of the spell with the where command. I do the where command often for the same reason that I don't simply have an alias or trigger that casts the spell ten times in a row.. I'd like to have the ability to recall to my hometown if an agressor enters the area and I cannot do that if I've got a minutes worth of commands in the queue. There are some simpler ways of doing that, such as just creating a timer that fires every three seconds, and disabling it when the mana drops below the set point. I had origionally thought it would have been more simple to keep it mostly contained within the script itself if possible.


No worries though, thanks for the help.


-Ray


[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #6 on Tue 25 May 2004 10:32 AM (UTC)
Message
Ah, I confused DoAfter with VBScript's DoEvents, sorry... The other answers should cover you :p

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #7 on Mon 31 May 2004 01:45 PM (UTC)
Message
Well, here's my suggestion:

If you don't already track your mana with a variable, then create an appropriate trigger to do so, and keep your current mana level in a variable global to your script file.

Create an alias to begin the casting process.

Create a trigger to fire on the spell success\fail line you presumably receieve from the mud.

In that trigger, use an if statement and if your mana is above your threshold, then send the line to cast the spell again.

In this scenario, you don't need timers at all.

If you begin casting initially based on some triggered line, and you don't want to interrupt if you are currently casting, then you have two options:

Use a boolean variable to indicate your casting status, and if true, don't interrupt yourself, or:
Build a named timer when you begin casting, and test for the existance of the timer to prevent interupting yourself.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


22,132 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]