View Full Version : Dynamically changing an IButton's "Button Text"
06-17-05, 11:49 PM
I need an answer for my first ZScript.
I have an IButton which I would like to "Dynamically" change the Button Text. It seems that even if I use a Global Variable and change the value using code - once it's painted on the screen, the Button Text won't change.
Is this possible, and if so how?
06-18-05, 04:19 AM
This is possible but you have to reload the script. If you're new to scripting then it might be best to avoid this method until you feel more confident. The main reason is that all your variables will be lost unless you write them to memory so that they are available to the script when it reloads. If you want to give it a go, have a look at TVeyes' suggestions on memory blocks in the code samples thread at the top of this forum.
Here's some code to get you started:
[VarDef,text,"First text "]
//initialize code to set appropriate button text:
[VarSet,text,"First text "]
[IButton,"Change button text",,
//code for changing text follows. This could be in a routine.
I find it useful when testing code of this sort to add a temporary button to delete the memory block so that if I reload the script after changes it starts afresh. Otherwise you have to restart ZB to clear the memory.
EDIT: an alternative way of dealing with this would be to use a note interface. Check out Digits' post in this thread (http://www.zbrushcentral.com/zbc/showthread.php?t=22826) . Using a note interface means you don't have to reload the script. Depending on what you're trying to achieve it may be a better way to go. My HEXcolor script (see sig.) is another example.
06-18-05, 10:43 AM
This is exactly what I needed. The reload seems to work remarkably fast. I'll just have to see how it performs with more than one button. :D
Being new to ZScript syntax (and having a buttload of weekend activities) it will probably be a couple days before I finish and share the ZScript with the community.
06-19-05, 12:44 AM
I look forward to seeing what you do with it! :) Just remember to write to memory ALL variables that have had values set (other than with VarDef).
06-19-05, 03:04 AM
Can an IButton statement/declaration be placed in a [Loop] ?
I'm trying to condense the code for 10 buttons I'm creating by using a loop.
I'm only seeing the last button of the loop.
Is there a restriction or something?
06-19-05, 06:32 AM
I'm not quite sure what you're trying to achieve. Can you post a bit of code for the loop? If you'e using the loop variable in your code in a string, then use [Val,loopvariable]:
Depending on what you're doing, you should be able to put your loop inside a routine and call that from a button or on initialization. Also, string variables often fail unless you declare them thus: [VarDef, mystringvariable,""].
06-19-05, 10:22 AM
Here's a scrap of code... It only gives me one button - placed where the last one is written.
[IButton, i, [StrMerge,"TEST-",i] [Note, "Test"] ]
06-19-05, 10:41 AM
Ah, no you can't do that. Buttons are top level and shouldn't be placed inside other commands. You'll have to code your buttons separately:
[Note,[StrMerge,"This is button : ",text(0)]]
[Note,[StrMerge,"This is button : ",text(1)]]
[Note,[StrMerge,"This is button : ",text(2)]]
[Note,[StrMerge,"This is button : ",text(3)]]
Note that the loop counter starts at 0. This can return errors if you're not expecting it.
You don't really need [IConfig,2.0] and only have [IShowActions] if you want people to see what you're doing.
06-19-05, 10:58 AM
Oh well....it is what it is. ;)
Can I place my ZScript buttons in the right or left tray -- or are ZScript interface objects pretty much reserved for the bottom tray?
06-19-05, 11:18 AM
You can't have zscript buttons anywhere other than the zscript window - well, that's not quite true but it amounts to that! ;)
In order to allow users to place buttons elsewhere on the interface (by Ctrl+dragging and then storing the configuration) you have to write a plugin - but I suggest you leave doing that for a little while. :)
06-19-05, 07:36 PM
Thanks for all the help! :tu:
BTW, I'm trying to use Dynamic Text with the Image Button Color method.
That doesn't seem to work, though.
The .PSD appears to overlay whatever text has been defined for the IButton.
06-19-05, 11:43 PM
You're welcome. :)
Yes, that's right, the image blanks out the text so there's no point in using the dynamic text method unless there's another reason for doing so. Your .psd will need to include the text to identify it. You can swap out the images though, using the same method so it doesn't make any difference. Just use a variable for the image name.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.