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


Joined: 25 Sep 2010
Posts: 7

PostPosted: Sat Sep 25, 2010 3:20 am   

Multiplay variable help...
 
Is there an easy or efficient method of getting variables from one window in to another window without using external scripting such as LUA? I'm not proficient in LUA, C, C++, Java or any of the other supported languages, though I'm fine with basic programming structure which allows me to make use of zScript and some more advanced triggers and the like... Since I'm multiplaying pretty much exclusively now it would be handy to be able to pass info back and forth between the two windows. For example if I'm playing a warrior who's tanking in window MAIN and a cleric who's the party healer in window BOT it would be handy to have the cleric in BOT heal the warrior in MAIN via trigger if his hp fall below a certain point.

Options I've considered but discarded due to inefficiency:

[code=In warrior MAIN window..}
#if {maxhp-hp > 500} {gtell major heal me}
#tr {You tell your group 'major heal me'} {#gag}
[/quote]

[code=In cleric's BOT window...]
#tr {%1 tells your group 'major heal me} {cast 'major heal' %1;#gag}
[/code]

While this would (barring syntax errors cause I was just trying to get the point across) accomplish the necessary task it would a) rely on the MUD's group communication method and b) introduce up to a full second of lag in the command process and involve a whole new layer of input and output... Ideally I would be able to use something like this, where (HP: is the beginning characters of the game's prompt...

Code:

#tr {[HP:} {#if {:main:@maxhp - :main:@hp > 500} {cast 'major heal' :main:@%char}}


Effectively pulling the maxhp, hp and %char variables from the MAIN window for use in the #if statement.

Is this doable somehow someway? Thanks in advance!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Sep 25, 2010 5:59 pm   
 
Move your variables to a module (nothing inside a window is visible to anything outside it). You perhaps may want to centralize your common scripts into a module as well, but if you do that you may want to explicitly change your prompt so that each character has a unique identifier:

MAIN window
BOT window
VITALS module
Code:
#trigger {^[(%w)'s HP: (%d)/(%d)...the rest of the trigger pattern} {
  //Vitals/%1/hp = %2
  //Vitals/%1/maxhp = %3
  #if ((%1 != "whatever equates to bot character") and ((@//Vitals/%1/maxhp - @//Vitals/%1/hp) > 500)) {:bot:cast 'major heal' %1}
}
_________________
EDIT: I didn't like my old signature
Reply with quote
jwbrandon
Newbie


Joined: 25 Sep 2010
Posts: 7

PostPosted: Sat Sep 25, 2010 6:29 pm   
 
Wonderful example, should work just fine. Can I define a variable using similar syntax?

Code:
//Vitals/mainhp=%1


?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Sep 25, 2010 6:56 pm   
 
Anywhere you need to refer to a variable can use that syntax, though in the 2.37 version you might not be able to do so in all situations for all variable types (bunches of these types of fixes occurred later in the 3.xx beta cycle).

For example, an equivalent way to rewrite the above example using the #VARIABLE command would be #VARIABLE //Vitals/mainhp %1.
_________________
EDIT: I didn't like my old signature
Reply with quote
jwbrandon
Newbie


Joined: 25 Sep 2010
Posts: 7

PostPosted: Sat Oct 02, 2010 7:58 am   
 
Okay.. so I've got the general gist of this, and it's very powerful. I'm running in to a snag though with something I'm trying to do now..

I have all my character's prompts in my MUD set to display their name. I have a trigger that defaults to enabled at connect that captures the name from the prompt in to a variable local to that window named sessionChar. I maintain a set of information about that character in my shared module in a class called char and subclass for each specific character. For example //wocshared/char/Stasheff/stTypeDrink contains the data flask. The reason to maintain the information in the shared module is that I would like to be able to share every trigger and alias between the two, but customize them for each character on the fly. Since Stasheff uses a water flask to drink from but Teibidh uses a barrel my drink trigger needs to know which word to put in the command. Easy enough in concept. What i need to do though is assign //wocshared/char/Stasheff/stTypeDrink's contents to the variable //main/typeDrink. I thought something like:
Code:
typeDrink=@//wocshared/char/@sessionName/stTypeDrink
... would work, but it assigns the value 0 to //main/typeDrink. To see what was going on I typed in a simple say command at the command line with the variable as typed in the code above... sure enough, it's not evaluating @sessionChar, If I type:
Code:
typeDrink=@//wocshared/char/Stasheff/stTypeDrink
then the proper result is given, but that removes my ability to have things set up automatically. How can I force everything to evaluate as needed?

EDIT:
The other thing I decided I could try was calling an alias manually at login, as long as I only had to do it once, no big deal... but it doesn't work either:
Code:
#al setupChar {typeFood=@//wocShared/char/%1/stTypeFood;typeDrink=@//wocShared/char/%1/stTypeDrink}


This still populates typeFood and typeDrink with 0. If I type:
Code:
say @//wocShared/char/Stasheff/stTypeFood

I get mushroom, which is what's actually stored in that variable. I add all this to make sure my problem is clear, to you and to me. It seems to me that even though CMUD (beta 3.29) is supposed to evaluate all variables at the command line or in aliases without being forced using [] or () it's not actually doing it in this case. I'm sure it's something I"m doing wrong or just don't know yet, though. Thanks in advance!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Oct 04, 2010 1:10 pm   
 
A better method would be to keep variables specific to a character only within that character's session. Each session could have a variable of the same name, and would only look up the value from within their own session. Only put into the shared module the things that every other session needs to know about.
Reply with quote
Teibidh
Beginner


Joined: 09 Nov 2002
Posts: 14

PostPosted: Mon Oct 04, 2010 1:23 pm   
 
"Better" is a relative concept, though. Doing that would require multiple packages and because I play a lot of different characters in a lot of different combinations and from a lot of different computers I am very interested in keeping the amount of files I have to manipulate to a minimum. Since the ability to write variables to other classes and read from them exists I would like to take advantage of this fact. Really, I just need the help getting the variables to expand all the way. I only have one session right now, just the one for the one MUD that uses the one package, it supports two windows that are generically named and depending on the role that a given character will play for a particular period of gaming time my cleric might be in my bot window while my warrior is in my main or vice-versa. Having to keep track of multiple sessions and rearrange them every time I wanted to focus control on one character over another would certainly not, in my opinion at least, be better.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Oct 04, 2010 4:09 pm   
 
Um, unless I'm mistaken, you said that you have multiple windows for different characters. Do you have all those windows running from a single session? I'm afraid I don't see how that can work without multiple session. But, if you think you can do it, go ahead.

Regarding your specific problem, the issue is that you are relying on implicit concatenation of strings and variable values. Using explicit concatenation should work, I believe. Something like this:
#al setupChar {typeFood=@{%concat("//wocShared/char/",%1,"/stTypeFood"});typeDrink=@{%concat("//wocShared/char/",%1,"/stTypeDrink")}}
Reply with quote
Teibidh
Beginner


Joined: 09 Nov 2002
Posts: 14

PostPosted: Mon Oct 04, 2010 5:25 pm   
 
Outstanding, thank you for solution :) I had assumed that getting a variable to expand within a variable name would work, didn't even know there was a %concat function available.

As for the multiple windows, yes, it works just fine. I don't remember off hand exactly where all the different menu options and the like are, but the process essentially was to create a new session with an empty package (though reusing the existing package is even easier), setup some of the aliases and variables (though that's not truly necessary), then save the package. I then used the commands #window Main, and #window bot. I believe that I had to right click each of those two windows to choose the options to display the status bar and the command prompt in each window, but it might have been somewhere else.

Once that's done I went to the original session and disconnected it, then selected one of the two new windows as active. Then in package editor I chose the original window, and hit advanced, then clicked on 'Convert to Module' or whatever that lil button in the bottom right corner is labeled. Then in each of the main and bot windows I hit file and reconnect. Then tiled them. Poof. Two windows, two logins, one session and one .pkg file. I'll post some screenshots when I get home, along with perhaps refining the instructions a little bit.
Reply with quote
Teibidh
Beginner


Joined: 09 Nov 2002
Posts: 14

PostPosted: Mon Oct 04, 2010 8:15 pm   
 
Rehab, using %concat() worked perfectly. Thank you very much!
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