|
Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Wed Jan 16, 2013 6:36 am
Global Package and Automated export/import questions. |
I'm trying to learn to use packages as intended, but after placing all of my speedwalks in one, I found that I had almost nothing left that didn't require unique variable values/keys from one session to the next, and worried that these things would overlap and thus fail to operate as they should. So, to put my mind at east, is there an approved method for using a variable path in a variable to ensure that it is defined in, and referenced from, the session/class that I desire?
For instance, a little experimentation shows me that:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="newvar" copy="yes">
<value>#var %expand(//%char/classname/varname, 1) %1</value>
</alias>
</cmud> |
seems to have the desired result, but I fear that it's sloppy, and possibly unnecessary. Are variables created from global packages always going to be defined in whichever session they're created from?
Now, the experimentation it took to achieve this has probably left the two packages involved huddled in the fetal position in the shower, sobbing. Which brings me to another question. Would it be possible to create a global package with OnConnect and OnDisconnect events, the former of which would import a specified xml file (for ease of use, let's say it has the same name as the session), and the latter of which would export all in the current session, and then delete the package associated with that session? If you hadn't guessed, making file structure changes is beyond the scope of anything I've ever attempted with cmud, I don't even know if commands exist that can accomplish these goals. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Wed Jan 16, 2013 7:00 am |
Variables defined from any package should automatically be defined in the root class of the session that the script is running in (unless it already exists in a class), not the package that tries to define it.
#VAR name {value} _nodef {class|names}
should be fine, though i rarely see the point of defining the class unless i have more than one variable of the same name going, and frankly i prefer to always use a unique varname
i just moves the variables about manually when i go in to clean up my scripts |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Jan 16, 2013 1:25 pm |
In general you shouldn't need to specify the full path to the variable. You can put triggers, aliases, etc. in a global package, even if they use variables defined in the session packages. As long as each session defines those variables in the session package, the global triggers and aliases should work fine. And new variables created by scripts in the global package will by default be created in the session package. That is one of the specific purposes global packages are designed for.
|
|
|
|
Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Thu Jan 17, 2013 8:58 pm |
Excellent, that makes using packages a lot easier. Trial and error also proved that triggers created by the package also showed up in sessions, so everything worked out.
Thanks for the info! |
|
|
|
Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Sun Jan 20, 2013 9:42 am |
Well, changing over my major/most used scripts to packages is nearly complete. I discovered early on that scripts which rely on triggers that turn on/off based on input from the mud don't work very well in global packages (first session to match the pattern fires them, rather than the session that initialized them, obviously). Now the only issue (so far) deals with connecting packages to sessions. I went through and edited the session individually, adding packages to those sessions which needed them, then I discovered that a session will use a package that I did NOT link to it, providing only that the package is loaded when said session is online (or vice versa).
For example: I have a thief's session loaded up, which uses a "rob script" package. At some point while the thief's session is loaded, I decide to load up a cleric's session, which is not linked to/should not use that package, but triggers in the "rob script" package fire in the cleric's session.
I can fix this (so far) by opening the the package editor, clicking on the main icon of the session that I do not want to use the package, and unchecking the package in the advanced tab. This works, but I wondered if there were some way to avoid this problem. With some 6+ packages per session, 20+ sessions, and a variety of packages I want to use with each session, loading up every possible combination and unchecking packages manually could turn out to be a very long process.
Any suggestions? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Sun Jan 20, 2013 6:47 pm |
well you could edit each of your sessions (package files tab) and make sure that they are only loading the packages that are actually relevant to them
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Sun Jan 20, 2013 10:54 pm |
That is exactly how I added packages to the sessions. The issue is with packages running on any session that is loaded, regardless of whether or not those packages were added to the session in the package files tab.
I have found it to be mostly true, thus far, that global packages which create or define variables do so in the session that causes the action to take place. However, I've been having a great deal of trouble with one session accessing another session's variable when a global package sets it. For instance, I have an alias in a global package, "ca," which does
Code: |
cast %-1
#variable lastspell {%-1} {_nodef} |
This seems to correctly set the defined variable in the session which uses the alias (seems, because it's all but impossible to keep a running check, it is used in multiple sessions simultaneously and 4 or 5 times in fairly rapid succession). However, the purpose of this alias is to automatically recast spells on failure, and I'm finding that when this variable is being set and accessed at about the same time, one session will reference another session's variable. I tried getting really specific with it, setting the spell failure triggers' values to
Code: |
#if (@auto) {#wait %random(700,1600);#if (@{%expand(//%char/lastspell, 1)}) {cast @{%expand(//%char/lastspell, 1)}}} |
which, in theory, should cause the trigger to send cast @//name/variable, which I'd have thought would prevent the problem. It doesn't. I've completely exported/imported all packages and sessions, including default packages. I've deleted all layout files and recreated layouts, and I've reinstalled cmud. It really doesn't seem like this is a corruption issue.
I suppose I could try changing the alias to add the session's name to the variable's name somehow, and adjust the triggers to check for that, so that each session uses a unique variable name. Any syntax suggestions for that? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Sun Jan 20, 2013 11:47 pm |
it sounds like you are having one of the standard multiplay issues... i think you need a supersession that only handles the layout
on top of a session for each character you play
there are other threads that go into this more in depth
seeing as i always run a seperate instance of CMUD for other characters, i cant really help you out further |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Mon Jan 21, 2013 2:22 am |
Well, I believe I have solved the problem, though further testing will be required to find out for certain. In case anyone has a similar problem and wonders what I did, here's an explanation.
I did this by first changing the variable into a database record, using
Code: |
#addkey LastSpell %char %-1 |
and changing the spell failure triggers to use
Code: |
#if (@auto) {#wait %random(700,1600)
#if (@LastSpell.%char) {cast {@LastSpell.%char}}} |
This entirely prevented one session from referencing another session's value, and it also allowed some extra debugging. After running through a few fights, I could see that two sessions that had been running simultaneously (fighting grouped together, even) had experienced some overlap. Session one and session two each had two keys in the @LastSpell variable, one for each of their names. So I knew at that point that the variable creation did not always without fail create/modify variables in the appropriate session. So, I changed the alias ca to this:
Code: |
cast %-1
#addkey %expand(//%char/LastSpell, 1) %char %-1 |
After that, I no longer had instances of one session modifying the other session's variable. Things went pretty smoothly, except that, on occasion, a spell failure trigger would simply not fire (despite the debugging echo showing up as it should). After a while, I noticed that this happened when both of them failed a spell within oh... 0.7 to 1.6 seconds of each other. I.e., if they both had a #wait going on at the same time. This is either because the #wait function is just not the right thing to use here (I favored it over #alarm primarily due to a bet) or because the #wait for each session runs in the package where it was created, and thus one cancels the other out. Or both.
Changing the triggers to:
Code: |
#if (@auto) {#if (@LastSpell.%char) {#alarm %char {+1} {cast (@LastSpell.%char)}}} |
Appears to have put an end to that behavior, without having to path the variable specifically (pathing and uniquely keying them in the alias is enough).
So, if this were a known issue, I believe it to be solved.
I'd still like some way to make packages only function in those sessions where I've gone in and added the package in the packages tab (even if it were adding line in the xml script like
Code: |
#if (%char = guy OR %char = otherguy) {do nothing} {run}. |
|
|
Last edited by Llohr on Mon Jan 21, 2013 5:25 am; edited 1 time in total |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Jan 21, 2013 5:22 am |
#wait creates a new thread. One thread referencing a variable that another thread references will result in an AV when both try to reference the variable at the same time.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Mon Jan 21, 2013 5:33 am |
I didn't think that that could be considered the same variable. Although each session had its own instance of the @LastSpell variable, one character, we'll call him Joe, will have a reference to @//Joe/Lastspell.Joe, while character Bob has his reference to @//Bob/LastSpell.Bob.
If both characters had a #wait (which was created by a trigger in a global package both of them are using) at roughly the same time--i.e., the one wait began at any point before the other had finished--only one of them would fire. |
|
|
|
|
|
|
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
|
|