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
jjloraine
Novice


Joined: 10 Jul 2006
Posts: 30

PostPosted: Fri Feb 15, 2013 12:22 pm   

Buttons displaying a phantom "0"
 
So, I can't figure this out for the life of me. I've got a button.

When I click the button, it sips a potion. That part works fine.

For the caption, I have:
Code:
%if(@mycloak,%btncol(Diffusion,green,black)"Cloak",%btncol(Diffusion,red,black)"No Cloak")


The idea is that the text color changes to green when I have the def, and red when I don't. The text also updates. This part works - it changes color and updates fine! The only problem is that it also displays 0 in front of the text for some reason. Eg, it'll show 0Diffusion and 0No_Diffusion. I cannot figure out where this 0 is coming from.

I assume it has something to do with the button name, so I've fiddled with that a bit, but if I change the ID field to anything with a number or put any sort of quotes or script into the ID, then the text updates fine (without the 0), but the colors don't swap. Changing it to another word results in the same thing.

Basically the %btncol(Diffusion,green,black) part is returning a 0 which is being displayed. I can't figure out how to make it just display the text after that evaluation. Any help would be greatly appreciated!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Feb 15, 2013 1:24 pm   
 
Yes, %btncol() will return a number representing the color of the button--0 in this case, for black. One solution, I think, is to enclose the %btncol() function inside some other function which won't do anything, and returns a null. Actually, %null() itself might work, since we know %btncol() always returns a value. So:
Code:
%null(%btncol(Diffusion,green,black))
Reply with quote
jjloraine
Novice


Joined: 10 Jul 2006
Posts: 30

PostPosted: Fri Feb 15, 2013 3:49 pm   
 
%null didn't work. I tried that before posting. :(
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Feb 15, 2013 9:15 pm   
 
I'm not coming up with an obvious function which would work.

Of course, the correct solution is to put the variable name in the Variable Expression of the button, and have the two labels and colors be the on and off states of the button.
Reply with quote
jjloraine
Novice


Joined: 10 Jul 2006
Posts: 30

PostPosted: Sat Feb 16, 2013 1:06 am   
 
Any suggestions on how to do that? I want the button's function just to be to sip the potion, with the visual appearance changing based on a value set from my prompt. I couldn't figure out how to go about changing the on/off state
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sat Feb 16, 2013 1:43 am   
 
That's very strange--a button to send the sip command, but the label has nothing to do with sipping? No, you can't do a sip function and have the on/off controlled by a variable, so I see why you were trying to do the button changing in the caption. But that is a very strange thing to do. You would probably be much better off using two different buttons--one to display the cloak state, and the other to do the sip command. They really aren't intended to do both kinds of things at the same time, unless the state of the variable is controlled by the state of the button.

If you really insist on having both things in the same button, you could do it moving the %btncol() function to an expression trigger controlled by the variable. Or you could use this in your button caption, but this is really brute-force:
Code:
%subchar(%btncol(Diffusion,green,black),"1234567890")
Reply with quote
jjloraine
Novice


Joined: 10 Jul 2006
Posts: 30

PostPosted: Sat Feb 16, 2013 1:50 am   
 
I don't see how it's that strange. I'm writing this as a package for new players to use to help get them used to the game. The button's display shows if they have the defense up or not, while clicking the button will do the action to create the defense. Ie, it shows if they have the cloak defense, and clicking on the button will sip the potion which creates that defense. So, the two things are quite related on a human level, even if they aren't linked by code.

I'm trying to create a CMUD-version of the visual UI they have with the java client. If you have any suggestions on how to create a similar set-up, I'd love to hear it - I kinda stumbled into this method after trying a lot of stuff. >_<
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sat Feb 16, 2013 3:17 pm   
 
I see--it wasn't clear from your description how they were related. The two methods I just gave you should work, though it is very awkward.
Reply with quote
jjloraine
Novice


Joined: 10 Jul 2006
Posts: 30

PostPosted: Sat Feb 16, 2013 4:01 pm   
 
I'll give that a try.

I'm not tied to this execution, however. This is just the roundabout way I found to do what I want: display a defence's current state, and do an action which will active that defence when clicking the display. This mimics the newbie UI and is something new users miss when they switch to CMUD. If you have any suggestions for another method to achieve the same thing (or similar) I'd love to try them out!

Thanks again for all the help! :)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Feb 18, 2013 9:26 pm   
 
Code:

%if(@mycloak, %if( %btncol( Diffusion, green, black) == 0, Cloak, ),%if( %btncol( Diffusion, red, black) == 0, Cloak, ))
Reply with quote
jjloraine
Novice


Joined: 10 Jul 2006
Posts: 30

PostPosted: Thu Feb 21, 2013 5:10 pm   
 
AWESOME!!! That was exactly what I was looking for. Thanks! :)
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