 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Dec 06, 2007 7:07 pm
Button Question |
Can someone explain to me how a toggle button is supposed to work? Right now it seems backwards to me.
For instance this button:
Code: |
<button name="btn_herbs" type="Toggle" variable="@AutoHerb" transparent="false" color="#400000" textcolor="white" priority="2030" id="1376">
<caption>Herbs</caption>
<value>info_notice Auto eating of herbs ON</value>
<state caption="Herbs" color="green">info_notice Auto eating of herbs OFF</state>
</button> |
When the button is not depressed it is OFF and the AutoHerb value is 0. When it is pressed it is ON and the AutoHerb value is 1. However, the notification I put in the script text is the exact opposite. When it is pressed it fires the script that is in the off state and vice versa. This is why I had to change them around backwards. Shouldn't it be the other way around or am I just confused? Green is ON and sets the variable to 1. |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Dec 06, 2007 7:13 pm |
States are numbered starting from 0, so 0 is when the button isn't pressed and 1 is when it's pressed. In this case, you'll want state 0 to be the "off" state and state 1 to be the "on" state.
|
|
|
 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Dec 06, 2007 7:21 pm |
That's what I just said. I know that. I think I have just readded these states so much now it is confusing me. Sort of like when you say a word that you say every day of your life and suddenly it doesn't sound right at all.
I was talking about what is in the script box for each state. If I put This button is ON in the ON state it only fires when I turn it off. You know when you are looking at the editor? I am looking at the OFF state 0 the button is red. In the script box if I put to show This button is now OFF it would show that when I push the button IN. |
|
Last edited by oldguy2 on Thu Dec 06, 2007 7:32 pm; edited 1 time in total |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Dec 06, 2007 7:28 pm |
The way it works is that the variable is used to track the current state of the button and it does that for buttons with multiple (more than two) states as well. Its use as a toggle for settings, the way you're using it, is a happy side-effect.
So the process is this:
1) Current state is 0 and the variable is 0.
2) You press the button and the script associated with the current state (0) is run.
3) The current state is changed to 1.
4) The current state is now 1 and the variable is 1.
5) You press the button and the script associated with the current state (1) is run.
6) The current state is changed to 0.
7) Repeat.
In your example, when you push the button, you're printing the value that the button is going to, not the value the button is coming from. That's why your text has to be reversed. |
|
|
 |
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Dec 06, 2007 7:31 pm |
It does seam a little loopy but the backwards way you did it is the way it is supposed to be.
If you are just using the Variable for the state of the button then obviously pressed should be ON and not pressed should be OFF.
For this to work properly then you would expect when the button is ON and you press it that it would be turning something OFF.
So your script should either do whatever is necessary to turn things off or to output that things are being turned off when it is in the ON state.
The reverse is true for the OFF state of course. Hope that helps.
Edit: ninjas All around... *dies* I really should just forgo answering questions when Fang's around it seems... |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Last edited by Arminas on Thu Dec 06, 2007 7:33 pm; edited 1 time in total |
|
|
 |
ardwick Novice
Joined: 31 May 2007 Posts: 32
|
Posted: Thu Dec 06, 2007 7:33 pm |
oldguy2 wrote: |
That's what I just said. |
It is "backwards". When you press the button you are doing two things. Changing the state of the button and executing a script for the state you are in.
So yes, if you currently in OFF (or 0) when you press the button, it executes a change of state from 0 to 1 and the script that lets you know that you are changing
from OFF to ON.
It doesn't execute the change of state and then the script of the new state. That script only executes when you repress the button to go back to State 0. |
|
|
 |
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Thu Dec 06, 2007 7:37 pm |
Fang Xianfu wrote: |
In your example, when you push the button, you're printing the value that the button is going to, not the value the button is coming from. That's why your text has to be reversed. |
Okay this is where I figured I was getting confused. Like I said I think I have just been readding the states to these buttons so much it confused me. I'm not stupid and I know how the states change. I have been playing Muds for years now. I played Avalon for years and then started playing IRE Muds. I try to keep things simple and not complex. The basic state of the button I understand. It was the script part that confused me for a moment. Sorry to post and waste time. |
|
|
 |
|
|