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
zito
Newbie


Joined: 11 Aug 2010
Posts: 6

PostPosted: Wed Aug 11, 2010 11:10 am   

zvar and sess objects documentation and enabling mult-thread
 
Hi,

I have been wondering how to communicate with the client from within a running script, specifically python.

It comes from what I understood here that you use sess and zvar objects to do so.

Unfortunately I couldn't find any documentation on the functions provided by these objects? Could anyone forward me to the documentation or briefly list the more important ones? Variable assignment, access and input command to mud, etc?

Furthermore I'd like to know how I can enable threads so I can literally let a script with wait instructions execute, while still inputing my own commands.

Best regards,
Zito
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Aug 11, 2010 1:01 pm   
 
I don't know about the sess and zvar objects, so someone else will have to handle that.

Creating a new thread can be done a number of ways, depending on what exactly your script is trying to do. In essence any of the #WAIT... commands will automatically cause that script to run as a separate thread. It is important to make sure the code is thread-safe, however. Specifically, you have to be careful when using or modifying variables that other threads might be changing at the same time. If you could be more specific about what you are trying to do, we might be able to give more specific advice.
Reply with quote
zito
Newbie


Joined: 11 Aug 2010
Posts: 6

PostPosted: Wed Aug 11, 2010 3:55 pm   
 
I want to basically let the script control my character continuously. Besides that, I want also to be able to input commands myself as to talk or to execute extra commands input by me.

Right now I tried the following:
for i in range(6):
sess.EchoStr("hello")
time.sleep(0.5)

I saved that as the alias "test". Everytime I input "test" the client input line is unresponsive for the time the script is running. Am I doing something wrong, I thought I'd be able to still walk around for example.

Furthermore, without knowing how sess and zvar work, there is nothing I can do. My only way out would be to use Lua I suppose, but I'm not interested in doing that.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Aug 11, 2010 8:31 pm   
 
As I said, in order to put something into a thread, you use one of the #WAIT... commands, i.e. #WAIT, #WAITFOR, #WAITSIGNAL, #WAITTHREAD. A simple command of "#WAIT 0" will be sufficient to put it into a separate thread. Look at the documentation on these commands, and on threads in general. See also the documentation for #SECTION, because you will need to work hard to make this code thread-safe.

One significant problem will be that mud output is generally interpreted and run through triggers in the _main_ thread, not this separate thread you are making. Another problem will be that both this thread and the main thread will potentially modify and read the same variables, leading to threading conflicts. You are going to have a real hard time making this work.
Reply with quote
zito
Newbie


Joined: 11 Aug 2010
Posts: 6

PostPosted: Thu Aug 12, 2010 8:20 am   
 
Hi Rahab,

my problem with the #WAIT commands and the others is that they will not work in python. That is specifically why I need to know how sess abd zvar objects work. I used now the standard wait call from python which did not activate threading on cmud.

While what you are saying is right, I did not have problems with what you are saying. For my regular gaming experience I seldom use triggers and thelikes. Moreover, care must be taken to yes, only set variables from one side, or to track racing conditions to do so. In my opinion though, it is easier to have a central script which takes care of pretty much everything, instead of a a high set of triggers and more doing stuff for you all in parallel and possibly conflicting. But that is only the way I decided to do things.

So, if you go for example to an alias, set the scripting language to python and try to issue the regular cmud commands (e.g. #WAIT, #ECHO), it won't work. And that's precisely why sess and zvar objects are so important to be known for any scripting language, but Lua? Here is where I got two different usages for zvar and sess from: http://forums.zuggsoft.com/forums/viewtopic.php?p=145834 . I hope someone still knows more about them or can point me where to look for the objects documentation.

Thanks for your help so far,
Zito
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Aug 12, 2010 2:05 pm   
 
I wish you luck then. As far as I know, only one or two people have tried to write anything in python or any language other than Lua for Cmud, and there is zero documentation for doing so. I think the only way to interact with Cmud is through the zvar and sess objects, which is why the time command did not do anything. What you need (you've probably figured this out already) is a listing of the functions available through the sess object. I don't think it is documented at all.

I am wondering, though, how you expect your master script to react to messages from the mud without triggers? The only way to know what is coming from the mud is with triggers. I suppose you could have a single trigger matching *, or a few triggers which match specific types of messages from the mud you care about, which add each line from the mud into a stringlist variable, then have your master script parse each line in the variable and figure out what to do. But your master script will have to examine the entire stringlist each time it wants to do something. For instance, if the master script is fighting an orc, the script needs to know before it casts Destroy Orc that five lines into the stringlist there is a message saying the orc is already dead. How do you intend to deal with mud output?
Reply with quote
zito
Newbie


Joined: 11 Aug 2010
Posts: 6

PostPosted: Thu Aug 12, 2010 2:37 pm   
 
Rahab wrote:
I wish you luck then. As far as I know, only one or two people have tried to write anything in python or any language other than Lua for Cmud, and there is zero documentation for doing so. I think the only way to interact with Cmud is through the zvar and sess objects, which is why the time command did not do anything. What you need (you've probably figured this out already) is a listing of the functions available through the sess object. I don't think it is documented at all.


Yes, a listing of available functions for the objects would do. This was exactly the purpose of my post. "zvar and sess objects documentation".

I don't think this information is confidential or impossible to retrieve. Any person with access to the source of cmud should be able to answer it.

"enabling mult-thread" has been answered by you right in your first post. Though I cannot access the wait functions as you well know. :-(

Rahab wrote:
I am wondering, though, how you expect your master script to react to messages from the mud without triggers? The only way to know what is coming from the mud is with triggers. I suppose you could have a single trigger matching *, or a few triggers which match specific types of messages from the mud you care about, which add each line from the mud into a stringlist variable, then have your master script parse each line in the variable and figure out what to do. But your master script will have to examine the entire stringlist each time it wants to do something. For instance, if the master script is fighting an orc, the script needs to know before it casts Destroy Orc that five lines into the stringlist there is a message saying the orc is already dead. How do you intend to deal with mud output?


I do intend to use triggers to extract required status information from the mud.

Race-conditions occur for shared variables. On shared variables it is wrong to assume that it will stay in that state only because you set it so. However, in the case of a mud script, you actually want to acquire status information from the mud and use this information to decide what to do inside a script. You will not set states which you don't know, you always ask the client about it and the client set states through triggers. Other required variables to keep track of the state of your script can be stored in the very script, separating the scopes and avoiding synchronization need.

The only harm here is that you might work with outdated variables for some time. But that is not a big issue, we are not handling software with safety requirements here. The worst that can happen is maybe a character death.

So, I know I am in a bad position since so few people actually tried something besides Lua. But I will still be hoping for a listing on the functions of the zvar and sess objects.

Thanks again Rahab and thanks in advance if someone can give me any insight on zvar and sess.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu Aug 12, 2010 5:22 pm   
 
I'm fairly certain it is closely related to COM so check out http://www.zuggsoft.com/page.php?file=zmud/comzmud.htm and http://www.zuggsoft.com/page.php?file=zmud/comserve.htm

[EDIT]
Also see http://forums.zuggsoft.com/forums/viewtopic.php?t=33625 and note the following:
Zugg wrote:
Better (but old) documentation for the VBScript (Microsoft scripting interface) API can be found here: http://www.zuggsoft.com/page.php?file=zmud/comserve.htm where you replace most instances of "zmud" with "cmud".

You may also be interested in the amazing work done by Dharkael http://forums.zuggsoft.com/forums/viewtopic.php?t=30282
[/EDIT]
_________________
Taz :)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Aug 12, 2010 6:40 pm   
 
Quote:
I don't think this information is confidential or impossible to retrieve. Any person with access to the source of cmud should be able to answer it.

The _only_ person with access to the source of Cmud is Zugg himself. I believe the zvar and sess are not documented yet because after implementing Lua, Zugg postponed further development for supporting other languages, since he had many higher priorities.

So, you _will_ be using triggers, but only to set state variables. Your earlier statement confused me. Smile That should work, once you find out more about the Cmud COM interface. It looks like the links Taz gave will help. Good luck!
Reply with quote
zito
Newbie


Joined: 11 Aug 2010
Posts: 6

PostPosted: Wed Aug 18, 2010 8:34 am   
 
Thanks Taz and thanks Rahab.

Taz, the links you provided helped me some. The only thing I still cannot do is to call #wait from python. I didn't find this method on the list.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Wed Aug 18, 2010 2:53 pm   
 
I really need to re-learn all the documentation stuff. With that said I'm pretty sure you'd be able to use the COM method ProcessCommand. It executes a string as if it were entered from the command line. The cMudCommand method would be better of course, but it requires knowing the COM Id for the #WAIT command.
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Aug 18, 2010 5:47 pm   
 
Do not try to use the CMUD Wait commands via any scripting language like Python. The problem is that the Wait commands in CMUD spawn threads, and the Microsoft Scripting Host that is responsible for handling the external languages like Python is not thread-safe and just does not properly handle threads.

So at *best* it just won't work at all. At worst you'll end up with all sorts of thread problems and instability.

If you want to use Wait, then you should stick with zScript. Lua works pretty well and *does* have some thread support, although limited. None of the Microsoft Scripting Host languages (VBScript, JScript, Perl, Python, etc) will work very well.
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