ZBrushCentral

Dynamically changing an IButton's "Button Text"

Hi,
I need an answer for my first ZScript.
I have an [color=Blue]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?

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 "]
[VarDef,OnOff,0]

//initialize code to set appropriate button text:
[If,[MemGetSize,GM_textchange],
  [VarSet,OnOff,[MVarGet,GM_textchange,0]]
	[If,[Var,OnOff],[VarSet,text,"Second text"]
        ,//else
	[VarSet,text,"First text "]
        ]//end if
,//else
[MVarDef,GM_textchange,1][MVarSet,GM_textchange,0,0]
]//end if



[IButton,text,"Info text",
[Note,"Hello world"]
]


[IButton,"Change button text",,	
//code for changing text follows. This could be in a routine.
	[If,[MVarGet,GM_textchange,0],
		[MVarSet,GM_textchange,0,0],
	[MVarSet,GM_textchange,0,1]]		
		[IPress,zscript:reload]
]

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 . 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.

Thanks marcus,
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. :smiley:

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.

I look forward to seeing what you do with it! :slight_smile: Just remember to write to memory ALL variables that have had values set (other than with VarDef).

Marcus,
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?

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]:


Loop,10,
[Note,[StrMerge,"Counting :",[Val,loopvariable]]]
,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,""].

Hi Marcus,

Here’s a scrap of code… It only gives me one button - placed where the last one is written.

[IConfig,2.0]
  [IShowActions,0]
  
  [Loop, 5, 
   [IButton, i, [StrMerge,"TEST-",i]	   [Note, "Test"]  ]
  ,i
  ]
  

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:


[VarDef,text(5),""]
[VarDef,popup(5),""]


[Loop, 5, 
[VarSet,text(i),[Val,i]]
[VarSet,popup(i),[StrMerge,"TEST-",[Val,i]]]
 ,i]
 
[IButton,text(0),popup(0),
 	[Note,[StrMerge,"This is button : ",text(0)]]
]

[IButton,text(1),popup(1),
 	[Note,[StrMerge,"This is button : ",text(1)]]
]

[IButton,text(2),popup(2),
 	[Note,[StrMerge,"This is button : ",text(2)]]
]

[IButton,text(3),popup(3),
 	[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.

Oh well…it is what it is. :wink:

Can I place my ZScript buttons in the right or left tray – or are ZScript interface objects pretty much reserved for the bottom tray?

You can’t have zscript buttons anywhere other than the zscript window - well, that’s not quite true but it amounts to that! :wink:

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. :slight_smile:

Marcus,
Thanks for all the help! :+1:

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.

Any suggestions?

You’re welcome. :slight_smile:

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.

Decrypting/copying/evaluating set for TM ( DS1990A, DS1991, DS1425)

1. Crack and copy DS1991 & DS1425.

2. Read the ROM of all TM (touching memory) to recognize which type of iButton.

3. Reading and writing programs for DS1961S & D1991.

Please view our website: www.setchief.com, fax or call to 0086-20-85662866, e-mail to: shichengdz@163.com.

Simulation or Replacement of TM/iButton (DS1990, DS1991, DS1425, DS1996, DS1992)

1. Simulate ROM ID, multi keys and memories by a microprocessor.

2. Replace multi iButtons by our set.

Please view our website: www.setchief.com, fax or call to 0086-20-85662866, e-mail to: shichengdz@163.com.