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
Asilient_1
Apprentice


Joined: 26 Apr 2007
Posts: 113

PostPosted: Sat Dec 15, 2007 10:15 am   

Toggle buttons working with set values
 
Basically, I wanted to make a few toggle buttons to show me the status of certain classes in my package. Enabled/disabled, if I click them it'd enable/disable dependent on the status of the class.

However, I noticed that it would only accept variables as a value to toggle on/off. What I'd really like to do is have the value (The variable field.) be possible to reference things such as %class(test) etc. So, instead of having the button check on the class, I had to go for something like:
Code:

<window name="Aetolia" usesession="false">
  <uid>{FE71CB01-8573-4BEE-BD20-2A74E960FD86}</uid>
  <packages>English Directions|Aetolia</packages>
  <class name="Test" enabled="false" id="1066"/>
  <button type="Toggle" variable="@test_status" priority="10670" id="1067">
    <caption>Test on</caption>
    <state caption="Test off"></state>
  </button>
  <alias name="teston" id="1069">
    <value>#T+ test
#VARIABLE test_status %class(test)</value>
  </alias>
  <alias name="testoff" id="1070">
    <value>#T- test
#VARIABLE test_status %class(test)</value>
  </alias>
  <var name="test_status" usedef="true" id="1071">0</var>
</window>


So! If there's a better way of doing it, I'd be appreciative of any pointers. I'd also suggest being able to use certain things in a button, rather than variables. %class, %pref, etc. Not sure how possible this is, though.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Dec 15, 2007 4:03 pm   
 
You have the right idea.
The problem with using functions in the button state or expression boxes is that the state of a predefined function never changes.
If Zugg were to make the buttons evaluate the functions things can slow WAY down. Besides handling this yourself is pretty easy.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="ClassStates">
    <button type="Toggle" variable="@ClassStates.Test" priority="10670">
      <caption>Test is Off</caption>
      <value>#call @class(Test,1)</value>
      <state caption="Test is On">#call @class(Test,0)</state>
    </button>
    <var name="ClassStates" type="Record">Test=0</var>
    <func name="Class">
      <value>#if (%null($newState)) {#Return %class($name)}
#switch ($newState)
 (0) {
      #T- $name
      #addkey ClassStates $name 0
     }
 (1) {
      #T+ $name
      #addkey ClassStates $name 1
     }
#Return {%class($name)}</value>
      <arglist>$name,$newState</arglist>
    </func>
  </class>
  <class name="Test" enabled="false"/>
</cmud>

The above code creates the following.
    A class named Test
    A class named ClassStates
    A Button within ClassStates
    A database variable within ClassStates named ClassStates
    A function within ClassStates named Class.

The button is controlled by the value of the key test in the ClassStates variable.

To test things out type '#call @class(Test,1)', '#call @class(Test,0)', or '#show The class Test is in the @class(Test) state.' into the command line.
Clicking the button also turns on or off the Test class.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
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