Dynamic labels

Hey there!!

i got a litte question regarding maxscript.
i`m trying to change the text of a label. i found a lot of results with google
but none of them works...
everywhere they tell to create a label:
-> label lbl_A "text"
and then "just" change the text by:
-> lbl_A.text = "new text"
but i always get "unknown property: "text" in undefined!?
anyone knows why?

greetings

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
docJones's picture

Hey, thanks for the answer.

Hey,

thanks for the answer. It works that way, but if I put the
"jakisLabel.text = "label text AFTER change: "" into a function, it`s unknown.
Gotta find another way...
Thx!

Greetings

brttd's picture

If you put it in a function,

If you put it in a function, none of the rollout's content is usable(unless the function is in the rollout). The label in the rollout is similar to a variable, and you can't do anything with it outside of its scope (http://docs.autodesk.com/3DSMAX/16/ENU/MAXScript-Help/index.html?url=fil... has more about local/global scope). For example:

a = 1
b = a + 2
--both of those can be accessed anywhere in the script.
(
   c = b
   b = 8
   --b can be accessed in here, aswell as c
)
print b
print a
print c (will be undefined)
--c can no longer be accessed, but a and b still can.

Unless you set a variable as global, it can only be read/written after the opening "(" and before the closing ")" which it was declared in.
Rollouts are similiar, you can't get/set values for a item in a rollout, unless you are doing that within the rollout.
There are ways to get around this, you can give the function another variable to be called with, and give it the rollout item (functions can access whatever variables they are given):

function fn1 item = 
(
   item.text = "lol"
   --because the function has been called with with the label as a parameter, it can read/write to that parameter, in this case changing the text.
)
rollout test "test"
(
   button change "change"
   label label "label"
   on change pressed do
   (
      fn1 label --the function is being called, and it is given the actual label as one of the parameters.
   )
)
createDialog test

You can also access the actual rollout, but I'm not quite sure how that works, sorry.
Sorry for the long post, hopefully it helps.

docJones's picture

hey, didn`t know / think

hey,

didn`t know / think about that rollouts have a scope!
Works now!
Thx a lot!

greetings

Drathir's picture

it should work. Check where

it should work. Check where you calling lbl_A.text = "newText"...check this and tell if its work:

val_inc = 0
rollout testX_rollout "chyzyZwawyRollout" width:350 height:150
(
	label jakisLabel "label text BEFORE change"
	button jakisButton "change Label Text"
 
	on jakisButton pressed do 
	(	
		val_inc+=1
		jakisLabel.text = "label text AFTER change: " +val_inc As String
	)
)
createDialog testX_rollout

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.