|
darmir Sorcerer
Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: Sat Oct 23, 2010 4:07 am
Understanding Multi State button |
I just don't get how to set and use a multi state button.
I want a button with the default setting to be the word "Command" that sets the variable @speech to 0.
I want the first state of the button when select it to be same as the default.
I want the second state of the button when selected to show "Stutter" and sets the variable @speech to 1.
I want the third state of the button when selected to show "Old English" and sets the variable @speech to 2.
Now when you click a state I want the Button caption to change to the State Caption.
I tried playing with it and I can't figure it out. I've haven't played with buttons before. |
|
_________________ Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian) |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Sat Oct 23, 2010 4:32 am |
Do you mind terribly if the variable @speech gets set to 1 when the default 'Command' is selected, 2 when Stutter is selected and 3 when 'Old English' is selected? That makes it much simpler to code, since you can link the button state to the variable @speech directly. This way the button will also update immediately if some other bit of script, like an alias or trigger changes the value of @speech.
The trick here is to give @speech a default value of 1 so that the button should never be in state 0.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<button type="Multistate" variable="@speech" autosize="false" width="91" height="23" priority="50">
<button>
<caption>Command</caption>
</button>
<button>
<caption>Stutter</caption>
</button>
<button>
<caption>Old English</caption>
</button>
</button>
<var name="speech">
<value>1</value>
<default>1</default>
</var>
</cmud> |
|
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sat Oct 23, 2010 4:44 am |
Code: |
<button type="Multistate" priority="2300" id="230">
<caption>Command</caption>
<button id="233">
<caption>Stutter</caption>
<value>#var speech 1</value>
</button>
<button id="231">
<caption>Command</caption>
<value>#var speech 0</value>
</button>
<button id="234">
<caption>Old English</caption>
<value>#var speech 2</value>
</button>
</button>
|
I've always just used the default state of the button as a place holder to set the caption when connecting to the session for the first time. After that once you click on the button you have to select one of the menu items for the button to make any changes to anything.
In the above example the three states are defined. The default state is showing Command too but to make @speech actually be 0 by default you need to set that in the variable it's self. To make sure the default state matches the correct variable value, set the @speech variable to have a default of 0 and click use default.
Does that help any? |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
darmir Sorcerer
Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: Sat Oct 23, 2010 4:47 am |
Thanks Fizgar.. I used your first example. I may play with the second one to see if I like it better. I have more states to add.
|
|
_________________ Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian) |
|
|
|
Vrah Newbie
Joined: 19 Oct 2010 Posts: 4
|
Posted: Tue Oct 26, 2010 6:45 am |
I have a similar problem.
I have a database variable that stores a list of afflictions in one column and a corresponding value of 0 or 1. Triggers update this as afflictions are gained or cured.
What I'd like is a button that reflects the variable state. For example if @aff.deafness is 1, I want it to display 'deaf', and if @aff.deafness is 0, to display 'undeaf' preferably with different button background colours. Is there any way to do this? |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Tue Oct 26, 2010 7:13 am |
Set up a toggle type button Vrah and make the expression for the button the variable you want it linked to.
Toggle buttons have two states, 1 for on and 0 for off, so it should be exactly what you need.
This example should be the default color when you're undeaf and yellow when your character is deaf.
Code: |
<button type="Toggle" priority="490" id="49">
<caption>undeaf</caption>
<expr>@aff.deafness</expr>
<state caption="deaf" color="#FFFF80"></state>
</button> |
|
|
|
|
Vrah Newbie
Joined: 19 Oct 2010 Posts: 4
|
Posted: Thu Oct 28, 2010 2:09 pm |
I can't seem to get this working. Once I save the button, the code changes to this:
Code: |
<button type="Toggle" priority="16760" id="1676">
<caption>undeaf</caption>
<expr>@aff.deafness</expr>
<button color="#FFFF80" id="1677">
<caption>deaf</caption>
</button>
</button>
|
And does not change as the variable changes. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Oct 28, 2010 3:33 pm |
What version of Cmud are you using, Vrah?
|
|
|
|
dbosst Apprentice
Joined: 15 Jun 2010 Posts: 121
|
Posted: Thu Oct 28, 2010 5:52 pm |
To Vrah, and others.. I've gotten rid of using any buttons as gauges.. it slows down CMUD more than you would expect it would.. especially if you have many of them ( I originally had a ton of them, one for every affliction type and other things, and if you do that it will slow down cmud a ton )
What I ended up doing was putting everything strategically in my status window as text, and then using mxp font colors to highlight etc.. It was tedious setting up but it works much better now than having 40 buttons
What I ended up doing was having a ton of status bar gauges that only show up in the status window, each set to a specific variable like @tg01 @tg02, etc, each for one line in the status window, and then I have a different function for each line that returns the formatted version of that line depending on the affliction state for that line:
This is the function that returns the second line:
Code: |
#local $tg02k, $tg02v, $len, $spacer, $line
$tg02k="Aeon"
#additem $tg02k "Sleep"
#additem $tg02k "Stun"
#additem $tg02k "Uncon"
#additem $tg02k "Prone "
$tg02v=@aff_aeon
$tg02v=%additem(@aff_asleep,$tg02v)
$tg02v=%additem(@aff_stunned,$tg02v)
$tg02v=%additem(@aff_unconscious,$tg02v)
$tg02v=%additem(@aff_prone,$tg02v)
$len=2
$spacer=%repeat(" ",$len)
$line=""
#call %vartype($line,3);
#loop 1,5 {
#if (%item($tg02v,%i)) {
$line=%concat($line,@{tg_coloron},$spacer,%item($tg02k,%i),$spacer,"</FONT>")
} {
$line=%concat($line,@{tg_coloroff},$spacer,%item($tg02k,%i),$spacer,"</FONT>")
}
}
#return $line
|
where tgcolor on is just the mxp formatting for what I set the ON color on :
Code: |
<FONT COLOR="#008080" BACK="#FFFFFF">
|
Then what I do is in any major place that changes the status of that line I call an alias that will update this line's variable, like the place where I set or clear afflictions I call a master alias to update all my affliction status lines: ie, inside the master alias, format_tg, inside it does a bunch of: tg02=@format_tg02()
that will efficiently update the status window quickly
If you do enough of them you end up with something like this for the affliction part, of course you can make it neater and use better color scheme but this is what works for me:
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Oct 28, 2010 8:25 pm |
The reason it would slow down Cmud so much is because if the key of a database variable is used as the expression, it will update _every_ button and status item that uses it as an expression _every_ time any value within the variable changes. If you have 10 buttons based on the keys of @mydbvariable, all ten buttons will update if any value in the variable changes, even if none of the buttons use the key that changes.
The better solution is to use a separate variable for each button or status window expression. |
|
|
|
darmir Sorcerer
Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: Thu Oct 28, 2010 9:13 pm Bug in Multi-State Button |
I think I found another bug.. Look at the screenshot below.. Notice that the menu list shows in a different order then the state list.. This is messing up my variable too. I checked and the speech variable should be set to 2, but since menu list shows stutter as the first state the speech variable is being set as 1.
Here is the code for the button state:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<button type="Multistate" variable="@speech" autosize="false" width="86" height="24" autopos="false" left="-2" top="-2" toolbar="2" border="red" priority="630">
<caption>Command</caption>
<button border="red">
<caption>Command</caption>
<value>#class CommCmnd 0</value>
</button>
<button>
<caption>Stutter</caption>
<value>#class CommCmnd 1</value>
</button>
<button>
<caption>Old English</caption>
<value>#class CommCmnd 1</value>
</button>
<button>
<caption>Lisp</caption>
<value>#class CommCmnd 1</value>
</button>
</button>
</cmud>
|
|
|
_________________ Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian) |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Oct 28, 2010 10:55 pm |
Try dragging/dropping the button states in the tree view on the left to get the order correct. There can sometimes be problems with this and you might also need to quit CMUD and restart if it gets out of sync.
|
|
|
|
darmir Sorcerer
Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: Thu Oct 28, 2010 11:31 pm |
Zugg wrote: |
Try dragging/dropping the button states in the tree view on the left to get the order correct. There can sometimes be problems with this and you might also need to quit CMUD and restart if it gets out of sync. |
That is exactly how I fixed it by dragging/dropping the button states in the tree view, but the problem is that it keeps going back to the wrong order if I quit CMUD while it is in the secord or third state |
|
_________________ Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian) |
|
|
|
darmir Sorcerer
Joined: 10 Oct 2000 Posts: 706 Location: USA
|
Posted: Wed Nov 10, 2010 1:54 am |
Jellen00 wrote: |
There's no point posting the code (and when you DO you should place it in [ code ] and [ /code ] tags - without the spaces I have added for padding) as the behavior is driven by the selections you make when dropping it on a button - in your case the "COMMAND SENT - when switched ON" and "when switched OFF". The expectation is that YOU write handlers that are called, and that these handlers perform whatever actions you need. If you want help writing these handlers you need to define what you mean by "play" and "pause" - do you mean the entire Director movie, or a video that's playing on your stage, or something else? |
Jellen00.
What the heck are you talking about? The problem was answered, and part of the issue was MY scripting error, which I should have posted that this was resolved. |
|
_________________ Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian) |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Wed Nov 10, 2010 5:54 am |
I'm pretty sure Jellen is a spammie, I'll be removing the post.
|
|
_________________ Asati di tempari! |
|
|
|
|
|