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


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 12:17 am   

Changing Button Text and Color
 
For the life of me, I cannot figure out how to change the color of the text when the value of the variable changes.

In the caption I have:

Code:
%if(@Balance,Yes,No)


I want Yes to be lime and No to be red on black background when the variable changes. I can get the entire button to change colors, but I have this in a separator. I only want the Yes and No to change colors and the background to always be black. Is there a way to do this in the caption of the button?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Mar 01, 2008 1:43 am   
 
Use the %btncol function. I talk about it tangentially here
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 1:48 am   
 
It doesn't work. I tried.

You are talking about this right?

Code:
%if(%if(@Balance,%btncol(btn_bal,green,black),%btncol(btn_bal,red,black)),Yes,No)


I want the Yes to be green and the No to be red on black background. I want the word to CHANGE and ALSO the color to change. I don't want to include it in all the different balance regained triggers. I just want to use the %if in the caption. Can this be done?
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 2:06 am   
 
See my tool bar at the bottom? I want to change those Yes and No words between green and red, preferably lime and high red.

[/img]
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Mar 01, 2008 4:47 am   
 
This should do what you want.

Code:
%if(@Balance == "Yes" , %if( %btncol( btn_bal, green, black) == 0, Yes, ),%if( %btncol( btn_bal, red, black) == 0, No, ))


I just coded it up for 'Yes' to be green and everything else is red No.

The reason your code was failing is that the inner if would evaluate to true since @Balance would have a value. It would execute the %btncol to set it green. But since the successful return code of %btncol is 0, No would always get set.

[Edit] I didn't do the part about CHANGE and ALSO because I wasn't sure what you meant, but that should be enough of a start for you.
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 5:10 am   
 
Tech this won't work either. It just changes it to a red No whether the balance variable is true or false.

When I get balance my @LeftBal variable will be 1 and it should display a green Yes. When I lose balance my @LeftBal variable will be 0 and it should display a red No. This is what I meant by the word changing as well as the color. I used exactly what you posted and it just turned to a dark red No and didn't change no matter whether it was true or false. I'm trying to do this with all of those items at the bottom tool bar you see above. I mean I can leave them as one color but its easier to notice if the color changes when the word does between Yes and No.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Mar 01, 2008 6:14 am   
 
Hmm how about using an expression trigger to change the button colours (and maybe the caption at the same time.
To change colour and caption at the same time try
Code:
<trigger type="Expression" priority="40" id="4">
  <pattern>@balance<999999999999999999999999999999999999999999999999</pattern>
  <value>#if (%number(@balance)) {
 #button btn_bal YES ""
 #call %btncol(btn_bal,green,black)
 } {
  #button btn_bal NO ""
  #call %btncol(btn_bal,red,black)
  }</value>
</trigger>

if you leave the caption as %if(@Balance,Yes,No)
the trigger could be changed to something like
Code:
<trigger type="Expression" priority="40" id="4">
  <pattern>@balance<999999999999999999999999999999999999999999999999</pattern>
  <value>#if (%number(@balance)) {
 #call %btncol(btn_bal,green,black)
 } {
  #call %btncol(btn_bal,red,black)
  }</value>
</trigger>
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 6:44 am   
 
Geesh are you sure that is right? You have an "<" after @balance. I didn't want to create more triggers though.

I just wish I could do something easy like this...

Code:
%if(@balance,%ansi(high,green)Yes,%ansi(high,red)No)


Too bad it won't work. haha
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Mar 01, 2008 6:50 am   
 
OldGuy2 the code does work.. you just have to take to change
Code:
@Balance == "Yes"
to
Code:
@Balance


I must have misunderstood your earlier statements and inferred that @Balance would carry a value of 'Yes' or 'No'; so that's what I was checking for instead of '0' or '1'.

So the new expression is
Code:
%if(@Balance, %if( %btncol( btn_bal, green, black) == 0, Yes, ),%if( %btncol( btn_bal, red, black) == 0, No, ))
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 1:11 pm   
 
I know. I tried that. It wouldn't work. In fact when I changed Balance to 0 it crashed CMUD.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Mar 01, 2008 2:06 pm   
 
Tech's code works for me.
For any value (so far) of balance 0 , negatives empty string positives.... whatever
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Mar 01, 2008 2:14 pm   
 
oldguy2 wrote:
Geesh are you sure that is right? You have an "<" after @balance

It's an expression trigger, not a pattern trigger. The idea is that, because of the <99999999999999, it'll fire every time @balance is changed, because the value will always match the pattern.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 2:44 pm   
 
Glad everything works for everyone else all the time.

Normally I have the following in the caption which works just fine and frickin dandy any time the variable changes but its always the same color:

Code:
%if(@LeftBalance,Yes,No)


So I put this in:

Code:
%if(@LeftBalance, %if( %btncol( btn_lbal, green, black) == 0, Yes, ),%if( %btncol( btn_lbal, red, black) == 0, No, ))


Then I enter in the command line LeftBalance=0 and this happens:

Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Mar 01, 2008 4:58 pm   
 
OldGuy2 try my code in a blank session and see if it works for you. Beyond that, I'm not sure what else to suggest to you. You're running the latest version of the code right?

If you don't consider it proprietary (don't worry I don't even play the IRE muds), send me your package and I can see what kinds of results I get.
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Mar 03, 2008 4:58 am   
 
Well it works in a blank session. I don't understand it. Sigh... You can see what happens in mine in that screen shot. It makes it transparent on No and crashes.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Mar 03, 2008 5:18 am   
 
Can you paste the full XML for you gauge button, maybe there's some thing in it that we can recreate locally.
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Mar 03, 2008 5:27 am   
 
This is it normally:

Code:
<button name="btn_lbal" type="Separator" autosize="false" width="30" height="20" autopos="false" left="231" top="0" toolbar="2" toolstyle="true" transparent="false" color="black" textcolor="lime" priority="9890" id="581">
  <caption>%if(@LeftBalance,Yes,No)</caption>
</button>


This is it with the new code:

Code:
<button name="btn_lbal" type="Separator" autosize="false" width="30" height="20" autopos="false" left="231" top="0" toolbar="2" toolstyle="true" transparent="false" color="black" textcolor="#00B300" priority="9890" id="581">
  <caption>%if(@LeftBalance, %if( %btncol( btn_lbal, green, black) == 0, Yes, ),%if( %btncol( btn_lbal, red, black) == 0, No, ))</caption>
</button>
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Mar 03, 2008 5:42 am   
 
What do you think Tech? It just flat out refuses to use that caption. I just reinstalled CMUD and still crashes with that caption. It works in a blank session though. Why would it crash? There is nothing in my package that should cause it to crash. I have a couple triggers that change the balance variables from true to false and back to true and that is it! Any time you change the variable value with that caption though it turns the button to transparent and crashes. The ONLY difference is that I have set up the location of my buttons manually instead of autosize and autopositioning, which is what I used in a blank session by just creating a button.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Mar 03, 2008 6:01 am   
 
Quote:
operating system : Windows XP Service Pack 2 build 2600
system language : English
system up time : 4 days 8 hours
program up time : 5 minutes 11 seconds
processor : AMD Athlon(tm) 64 Processor 3800+
physical memory : 596/1023 MB (free/total)
free disk space : (C:) 165.53 GB
display mode : 1024x768, 32 bit
process id : $34e4
allocated memory : 31.30 MB
executable : cMUD.exe
exec. date/time : 2007-12-14 14:39
version : 2.18.0.0
madExcept version : 3.0b
callstack crc : $687c72d0, $f452e030, $f452e030
exception number : 1
exception class : EAccessViolation
exception message : Access violation at address 00D430A6 in module 'cMUD.exe'. Read of address 00000224.

Main ($3230):
00d430a6 +492 cMUD.exe PrefDat 8614 +83 ButtonRec.Invalidate
00c6f968 +0fc cMUD.exe PARENT 11680 +26 TParentForm.WMInvalidatePref
004a52c9 +021 cMUD.exe IniFiles 197 +1 TCustomIniFile.ReadBool
004e281f +1df cMUD.exe Controls 4645 +53 TControl.WndProc
004e654e +18e cMUD.exe Controls 6342 +33 TWinControl.WndProc
0050362c +478 cMUD.exe Forms 3098 +103 TCustomForm.WndProc
00c012cc +020 cMUD.exe DXSounds 2013 +9 TCustomDXSound.FormWndProc
00bfea28 +00c cMUD.exe DXClass 572 +1 TControlSubClass.WndProc
004e6120 +034 cMUD.exe Controls 6237 +3 TWinControl.MainWndProc
00480398 +014 cMUD.exe Classes 10966 +8 StdWndProc
7e41f658 +016 USER32.dll CallWindowProcA
006d7087 +0a7 cMUD.exe aqDockingUtils 1728 +7 CallDefWndProc
006d7175 +0dd cMUD.exe aqDockingUtils 1776 +41 TaqWindowEventFilter.WndProc
00480398 +014 cMUD.exe Classes 10966 +8 StdWndProc
7e4196c2 +00a USER32.dll DispatchMessageA
0050b6d4 +0ac cMUD.exe Forms 6873 +13 TApplication.ProcessMessage
0050b71b +00f cMUD.exe Forms 6892 +1 TApplication.HandleMessage
0050b9b6 +0a6 cMUD.exe Forms 6976 +16 TApplication.Run
00dce84c +088 cMUD.exe CMUD 344 +18 initialization
7c91312f +069 ntdll.dll RtlUnicodeStringToAnsiString
7c812b94 +0b6 kernel32.dll GetVersionExA

error details:
Changed LeftBalance value to 0 by typing LeftBalance=0 in the command line.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Mar 03, 2008 7:33 am   
 
Ok... OldGuy2, I think I figured out the problem.

The button you have (at least the code you posted) shows that the button type is 'Separator'. When it's set like that you get an error when you update it, (which makes sense because the separator shouldn't have a caption, although i think the bug should be caught and suppressed). You have to change the button type to 'Push' or some other proper button type. Since I had caused the error to occur the change did not take effect immediately. I had to save the change and restart CMUD just to make sure the update got picked afterwards. The code then worked as expected.

I know you've had issues with your packages in the past and I'm glad you have the tenacity to stick it through. If this fixes your problem, it might be good idea to audit the rest of your buttons etc. to make sure they type you think they are, are what they are really set to.
_________________
Asati di tempari!
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Mar 03, 2008 9:06 am   
 
Thats not it. I changed it to a push button and it still crashed. You should still be able to display the caption in a separator. The original caption I used works perfectly fine. There is something wrong with that caption code that you gave me that makes my system crash. I know it works for you, but it just flat out refuses to work for me, even if I make the button a push button. Type LeftBalance=0 in the command line immediately changes the button to transparent with a "No" caption and crashes CMUD as seen above.

Edit:

I don't know what to say. It's the code you have above that makes it crash. My code works fine, but as soon as I enter your code and change the value of the variable to 0 or 1 CMUD crashes. Are you using the Pro version of CMUD? If it works for you, why isn't it working for me? I just went to the variable in settings and changed the 0 to 1 and hit save and boom it crashed. I enter on the command line LeftBalance=1 and boom it crashes. I take out that code and put mine back and it doesn't crash. So how can it be me?
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon Mar 03, 2008 9:55 am   
 
Ah ha! It's because I have my toolbar in a separate module. Put the variable in one module and the button in another module and use your code in the caption. I did this in a blank session and it crashed. Both of my modules are in the same package though.

Edit: Actually its a being in a module period. I put them both in the same module in a blank session and it crashed. If I just create the variable and button without putting them inside a module, it doesn't crash and works in a blank session. I also put the variable in a module and didn't put the button in and it worked fine. Putting the button in the module makes it crash with your code.

Soooo WHY is it crashing just by having this button inside a module???
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Mar 03, 2008 11:20 am   
 
I have no idea why it is crashing with the button in a seperate module from the window. However it is a good find. Please write up a procedure to reproduce it in a blank session and post it in a seperate topic. That way it is right up top and Zugg will see it.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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