Notifications
Clear all

[Closed] dynamic Button caption?

Anyone know if there’s a way to change the caption on a Button when it’s pressed? I’m thinking of a Boolean-type situation, where clicking the Button alternates the Boolean state between true and false. So the caption would read “Click for true” or “Click for false” depending on the Boolean state. Many thanks.

8 Replies

Problem solved…

(
rollout test "test" (

button pressthis "Press for true"

on pressthis pressed do
(
   text1 = pressthis.text
   if text1 == "Press for true" then
   (
	  pressthis.text = "Press for false"
   )
   else pressthis.text = "Press for true"
)
)
createdialog test
)

Have you looked into CheckButtons, they could esaily do this.

This is a little exemple with buttons


local bState = false;
on btn_Button pressed do 
(
___bState = not(bState);
___btn_Button.caption = ("Click for " + ((not(bState)) as string));
) 

That’s a neat alternate solution, Eric. Thanks!

I suppose it’s obvious, but I just realized this method can also make labels dynamic…

rollout test "Dynamic Label"
(
label lbl "Apples"
button btn "Comparison"
local Lstate = false
 
on btn pressed do
(
Lstate = not Lstate
if Lstate then lbl.text = "Oranges" else lbl.text = "Apples"
)
 
)
 
createDialog test
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Welcome to the wonderful world of… captions
Generally, all captions are dynamic, but there are some caveats in controls like Spinners where the caption is NEXT to the editable field – MAXScript seems to reserve a specific amount of space for the caption of the spinner and if the new caption is longer, it might get clipped a bit. If you intend to use longer captions in spinners, be sure to add some spaces in the initial string to pre-initialize the size correctly.

In contrast, in earlier version of Max, the tooltips were static and not dynamically changeable. This has been somewhat improved in Max 9 where the .tooltip property was introduced for buttons/pickbuttons/checkbuttons. In Max 2009, tooltips were added to some rather unsuspecting controls like dropdownlists and checkboxes. Not only that, but long tooltips will now be warped automatically into mutli-line tooltips, making them much easier to read and a lot cooler!

Thanks for filling out the picture, Bobo. This is a little gem of a feature, IMHO, that I couldn’t find any reference to in the Reference.

The logic is this:

Anything that is a Read/Write PROPERTY is dynamic and can be changed at any time after the UI control has been created. This includes all common properties like .caption, .pos, .enabled and .visible and the own properties like .checked in checkboxes or .items in a dropdownlist.

And then there are the CONSTRUCTION PARAMETERS which are often duplicated by the properties but not always. For example, the align:#left can only be specified as a construction parameter for MAXScript to figure out the alignment when initially building the rollout, but not as a property to change the alignment later. Some construction parameters like the .tooltip were exposed later as properties to make them dynamic based on userbase wishes…

The construction parameters are given in the Constructor syntax (the big blue box on top of the UI Control’s page), they are also listed in detail below it. Then the properties are listed and finally the handlers. If a Construction Parameter does not appear on the Properties list, it is not dynamically changeable.

Got it. Many thanks!