Notifications
Clear all

[Closed] executing a concatenated string

I have a ui setup with a number edittext containers and im trying to access the data held in the edittext via a concatenated string pulled from an array.
something like

 
edittext mytext "text" text:"content"
 
--array holding edittext name
data = #("mytext")
 
holder = (data[1] + ".text")
print holder

Which results in mytext.text and not “content” which is held in mytext.text. I thought you could use the execute function to execute a string so i tried

 execute holder

But this returns an error. I have the feeling im doing something very simple wrong, any help would be greatly appriciated.

2 Replies

You’re doing a few things incorrectly, which is why the script isn’t acting like you want it to.

Mistake 1:

data = #("mytext")

You’ve created an array that is holding a string, not a reference to a control. Any time you put a value inside of quotes MAXScript will think you want it as a string.

2+2

will resolve to 4

"2+2"

will resolve to “2+2”

I’m assuming you are declaring your array named “data” inside of your rollout. If not I’d recommend that you do. If you don’t you’ll run into some rollout declaration and/or variable scope issues that will be confusing to decipher if you don’t know what is going on. Play it safe and declare your array inside of the rollout block.

The proper syntax is

data = #(mytext)

Mistake 2:

holder = (data[1] + ".text")
print holder

You don’t have to build a string. You can address the properties of an element in an array just as if you were addressing the item directly.

holder = data[1].text

is synonymous to

holder = mytext.text

as long as data[1] == mytext

If you want to save a variable declaration you could shorten your two lines to:

 print data[1].text

As for

execute()

to quote Larry Minton, “If you are using execute() you are probably doing it wrong.”

Putting it all together, your script can be expressed as:


rollout <rollout name> <string> width:<int> height:<int> 
(
editText mytext "text" text:"content"

data = #(mytext)
 
on rollout <rollout name> open do
(
[indent]print data[1].text

)

[/indent])

 
--or to display the text elsewhere in the code
print <rollout name>.data[1].text

awesome!
Thanks for the detailed reply just the answers i was after

What i was trying to figure out was part of a short script for creating a folder structure for a new project in max.
I’ve attached it below if anyone cares to test it or offer a more efficient method of tackling the script as im still pretty much a noob

anyway thanks again Jeff