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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Apr 04, 2010 9:45 am   

[3.16b]#THREAD issues, assistance please?
 
I'm not calling this a bug, but for all I know, it may be, therefore I'm asking for assistance before I turn it into a bug.

I'm actually testing out #THREAD for the first time, as I've found it keeps CMUD from 'locking' up on me when running particular scripts. However it seems that I cannot maintain a consistency with #THREAD at all. For instance, I have the following:

#THREAD "Defintion" {#EXEC %-2 @define(%1)}

For whatever reason, IF it works at all, it ignores the parameters given in the alias. Once I set #THREAD "Definition" (or any other thread name for that matter), it seems more on the consistent side to not run #THREAD anymore. For example:

#THREAD "WeatherInfo" {#EXECWIN "Weather" {#CLR;showlocalweather}}

will fire all the time, but if I do:

#THREAD "NoteEmail" {sendnote @email @notesubj @notebody}

it's hit or miss. Now, I know about #SECTION, but I don't think there's a use for it here as 1) I'm not using the variables anywhere else and 2) most of the scripts I'm running with #THREAD are lua-scripts. Am I missing something here? If I go to an untitled session, I can do something like #LOOP 10 {#THREAD Test%i {#THREAD;#SAY {Test fired!}}} and it'd work perfectly. I've never used #THREAD before, so I don't know if I'm doing something wrong or not. If need be, I can provide the scripts for other testing (I haven't actually tested these scripts isolated in an untitled session, though that'll be my next step).

Charneus
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Apr 05, 2010 1:47 am   
 
Are you sure you need to run those in separate threads? In general, there really is no reason to worry about threads unless you need to use #WAIT or similar commands. The reason the first line doesn't work is because, once it is put into its own thread, it no longer has access to the %-2 and %1 values. For the third one, how can you not be using those variables anywhere else? How are those variables getting set?

My advice is, you probably shouldn't be using #THREAD for these things. Unless you are doing fairly complicated things, #WAIT and similar commands are pretty safe to work with, but unless you know what you are doing, don't use #THREAD to spawn new threads.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Apr 05, 2010 3:10 am   
 
The reason why I'm using #THREAD in the first place is because whenever those particular scripts run, it eats up the processor for a few seconds, effectively locking me out of the command line until the script has run its course.

Here's what the scripts are doing (at least for the weatherbot one). Every 15 minutes, an alias (showlocalweather) runs, which accesses a website, parses it and looks for a match. When it's accessing the website, CMUD becomes unresponsive (meaning all text, command line, etc are locked) until the script runs its course. Generally takes only a few seconds, but if I'm in battle, those few seconds can mean life or death, especially if I can't heal myself.

As for what I mean about the variables not being used anywhere else, I mean that once they're set, they're not touched until the next time the script is used, and no other script (other than the NoteEmail script) uses them. That script runs automatically, as well - when a new note is posted on the boards, it automatically reads them and emails them to me for logging purposes.

Wasn't aware about #THREAD not being able to use %xx, so that's one change I can make. I see it also doesn't work with local variables? Thanks for the assistance on this, Rahab.

Charneus
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Apr 05, 2010 1:30 pm   
 
Yes, if it takes that long to run, I can see why you want it to run in a separate thread. Let's see...

I hadn't really been aware that #THREAD couldn't use %x either, but it's the only conclusion I can make. And if that's true, it's obvious it wouldn't be albe to use local variables either.

Perhaps the best solution is to use #WAIT instead of #THREAD. That will cause the _current_ script to run in a separate thread. You can use the input parameters and local variables then. I'm not sure why your NoteEmail thread is as hit-or-miss as you describe, if the variables really are being left alone. But try the #WAIT (with no value) to see if you can get better performance.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Apr 05, 2010 4:00 pm   
 
#THREAD doesn't currently pass the arguments from the original script. The #THREAD script is completely independant and doesn't have access to any of the %nn arguments or local variables of the calling script.

I'll add something to the to-do list for the future to pass the %nn arguments. But threads will never be able to access any local variables from the calling script.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Apr 05, 2010 11:37 pm   
 
#WAIT with no arguments is working wonderfully for me. Thanks! Now I can get on with other scripting!

Charneus
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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