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
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Sun Mar 15, 2009 4:52 am   

(Fixed) [3.05] Scoping and the Mapper room enable/disable code
 
I decided to start taking advantage of the new mapper abilities to enable/disable my hunting triggers depending on which zone I'm in. If I enter a zone, then I have a 'Zone###' item under the mapper that will disable/enable the appropriate hunting triggers.

I'm trying to figure out with the scoping how to call an alias in my main window from the mapper window code. How do I do this?


Last edited by ReedN on Sat Apr 18, 2009 7:13 pm; edited 2 times in total
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Sun Mar 15, 2009 5:19 am   
 
I found by searching around that variables are accessed like this:
@//ModuleName/class/variable

Aliases by extension:
//ModuleName/class/alias
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Sun Mar 15, 2009 5:46 am   
 
I think I've run into a bug with the scoping.

My first incarnation of this was to create an alias in my main window to enable and disable the hunting classes. The alias would just need the zone number and would be called from the mapper. The mapper would just have to call it like this:
//Achaea/HuntingTriggers/HuntingZoneChange 51 0

The alias (which I confirmed working from the command line) was this:
Code:

<alias name="HuntingZoneChange" id="3594">
  <value>$zone = %db( @ZoneNameTranslation, $zonenum)
#if (%ismember( $enable, {0|1}) and $zone) {
  //
  #if ($enable) {#T+ $zone class} {#T- $zone class}
  } {
  //
  #print "-E- Error HuntingZoneChange - Syntax: "
  }</value>
  <arglist>$zonenum, $enable</arglist>
</alias>

<var name="ZoneNameTranslation" type="Record" id="3591">129=Underworld|30=Moghedu|71=ForestWatch|36=Arcadia</var>



When run from the mapper, I could verify that the alias was indeed being called, and also that the arguments were correct. However it wasn't enabling or disabling the classes. Could it be that when called from another window the enabling/disabling are still referring to the old window? This is the only thing I can think of since I can verify this alias works just fine when run from my main window.

Since this wasn't working, what I've done to work around this is to just directly reference it to disable it:
#T+ //Achaea/HuntingTriggers/AalenForest class
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Sun Mar 15, 2009 7:01 am   Procedure for Reproducing
 
I went and set up a procedure for reproducing this. This is very odd in that when I created this by hand it didn't show the bug, but then when I exited out and re-entered the session it stated showing the bug again.

Procedure:
Code:

1) Open Cmud, create a session called 'test'.  Open 'test' off-line.
2) Copy the xml code for the 'test' window and copy it into the root of 'test'.
3) Open the map.
4) Create two rooms on the map.
5) Copy the xml code for the 'test Map' window and copy it into the root of 'test Map'.
6) Run 'runme' a few times to see how it works.  The alias 'runme' will toggle a class active/disabled.  Inside the class there is an alarm that prints out when the class is enabled.  When the class is disabled it doesn't print out.
7) In the map right click and 'Set Current Position' alternately on one room and then on another.  Alternately you can alternate typing in: '#tele 1' and '#tele 2' to get the room changes.

What you should see:
Setting the position between the two map locations should cause the map to fire the 'runme' alias from the main window.  You'll see the script print out to the screen saying that it is enabling/disabling the class, but the class won't actually disable/enable and you'll see that by either looking in the settings editor or by noting the presence or absence of the alarm output.

Sorry this couldn't be made more simple, there are a lot of elements to reproduce in this one.


Code for Window 'test':
Code:

<window name="test" width="1600" height="849">
  <uid>{FB6DCC60-C7D1-499B-A00D-D11AA75B9E39}</uid>
  <packages>English Keypad|English Directions|Clickable URLs|test</packages>
  <loc name="test" color="blue" id="2">
    <value>2</value>
  </loc>
  <class name="class1" initenable="true" id="5">
    <trigger type="Alarm" priority="80" id="8">
      <pattern>*1</pattern>
      <value>#print ** Class1 Active ** </value>
    </trigger>
  </class>
  <alias name="runme" id="6">
    <value>#if (@class_state) {
  #print Disabling the class
  #T- $name class
  #var class_state 0
  } {
  #print Enabling the class
  #T+ $name class
  #var class_state 1
  }</value>
    <arglist>$name</arglist>
  </alias>
  <var name="class_state" usedef="true" id="7">
    <value>1</value>
    <default>1</default>
  </var>
</window>


Code for Window 'test Map':
Code:

  <class name="Room1" keyword="Room1" enabled="false" id="8">
    <onenable>//test/runme class1</onenable>
    <ondisable>//test/runme class1</ondisable>
  </class>
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sun Mar 15, 2009 12:27 pm   
 
I just barely skimmed your script, but (from the help file):

"Note that the room script is only executed when you move into a room. It is not executed if you manually select the current room on the map."

Might explain some of your problems here. Did you try right-click and selecting "execute room script" to reproduce this?
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Sun Mar 15, 2009 2:54 pm   
 
Gamma_ray, I believe you misunderstand. Teleporting (#tele) does cause it to be executed, as does 'Set Current Position' (not 'select current room' as you mentioned). Additionally it is easy to verify it is running the alias because it outputs text as expected.
Reply with quote
Zugg
MASTER


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

PostPosted: Mon Mar 16, 2009 5:42 pm   
 
You shouldn't need to use the //module/class/alias syntax. The mapper is supposed to execute your scripts within the context of the session window that is attached to the location object being tracked in the map. So you should just need to call "HuntingZoneChange 51 0" directly if your Achaea window is the window containing the map tracking location.

I'll play with your script to see what I can find, but if you find any areas in the mapper scripts where the //module/classname syntax is required, then that's a bug. I'm trying to get people away from using that syntax since it makes your scripts all package dependent (and window name dependent).
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Mon Mar 16, 2009 6:09 pm   
 
Zugg: The very first thing I tried was to just call "HuntingZoneChange 51 0" directly. When the mapper enable/disable code was run it simply dumped that text out to the mud like it didn't realize it was an alias needing to be run.

To be exactly clear on what I had tried, I'll summarize again below:

Code:

Achaea Window:
  Class:  All my hunting classes to be enabled/disabled
  Alias: HuntingZoneChange // What is going to change the above classes to enabled/disabled

Achaea Map Window:
  ZoneXX:
     Enable:  HuntingZoneChange 51 1
     Disable:  HuntingZoneChange 51 0

When it is setup like this (which is what I think you suggested), the mapper runs the Enable/Disable code and it can't find the "HuntingZoneChange" alias contained by the Achaea Window. That's the whole reason why I started trying to call the alias with the //module/class/alias syntax in the first place. Then I ran into the problem that although it indeed calls the alias, the alias cannot enable/disable the class when run from the Mapper.
Reply with quote
Zugg
MASTER


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

PostPosted: Mon Mar 16, 2009 7:18 pm   
 
OK, I'll definitely look into this. I had tested Room scripts with accessing variables, but didn't specifically test accessing aliases. Seems like they should work the same, but obviously there is a problem. Or maybe it's a problem specifically to zone scripts that are working differently than room scripts.
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Tue Mar 17, 2009 2:05 am   
 
Knowing now that aliases should work without the //module/classname syntax syntax, here's a simplified method to show it:

Procedure:
Code:

1) Open Cmud, create a session called 'test'.  Open 'test' off-line.
2) Copy the xml code for the 'test' window and copy it into the root of 'test'.
3) Open the map.
4) Create two rooms on the map.
5) Copy the xml code for the 'test Map' window and copy it into the root of 'test Map'.
6) Run the alias 'runme' at the command line.

What you'll see:
- You'll see 'test' echo'd to the screen several times indicating it couldn't find the alias.  If it had actually found and run the alias it would have printed 'I ran successfully!'.


Code for Window 'test':
Code:

<class name="test" id="10">
  <ondisable>test</ondisable>
  <alias name="runme" id="4">
    <value>#tele 1
#tele 2
#tele 1</value>
    <arglist>$name</arglist>
  </alias>
  <alias name="test" id="9">
    <value>#say I ran successfully!</value>
  </alias>
</class>


Code for Window 'test Map':
Code:

<class name="Room1" keyword="Room1" id="8">
  <onenable>test</onenable>
  <ondisable>test</ondisable>
</class>
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Sat Apr 18, 2009 4:35 pm   
 
Confirmed fixed 3.06.
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