Notifications
Clear all

[Closed] Formatting text for script controller

Hi everyone,

hitting a wall here.

What I need to do is create a bunch of objects with script controllers. I intend to use a for loop
like in the sample code.

for i = 1 to 3 do
(
	theBox = box()
	theBox.position.controller = position_script ()
	theScript = (i as string),(i as string),(i as string)
	theBox.position.controller.script = theScript
)

I’m stuck at the point where I try to insert the index from the for loop into the script controller like in line theScript = (i as string),(i as string),(i as string). I know it is wrong, I tried a lot of combinations but with no success.
Can anyone shed a light on this?

Thanks in advance.

6 Replies

You can use format and ‘%’ to place values in a string:


theScript = format "%,%,%" i i i --(don't know if you really need three 'i')

Danke.
No tripple i, was just an example.
How would I go inserting an index into text like “theArray[i]” but a value instead of i. Same way?

Yeah…

for i in 1 to 3 do
(
text = format "theArray[%]" i
print text
)

should print out

theArray[1]
theArray[2]
theArray[3]

Zing!
Everything I see is MaxScript code. Enough for today.

Your first would work, but you need to put everything as a string inside the theScript var.

for i = 1 to 3 do
 (
 	theBox = box()
 	theBox.position.controller = position_script ()
 	theScript = "["+(i as string)+","+(i as string)+","+(i as string)+"]"
 	theBox.position.controller.script = theScript
 )

Format will error, AFAIK, because it is not assigning the string, but is returning the results of it to the listener or a stream. So the result of format is theScript = OK and not your desired string. For your question about array same thing applies:

"theArray["+(i as string)+"]"

-Eric

1 Reply
(@scrimski)
Joined: 11 months ago

Posts: 0

That’S even better. Just missed the + in the string part.

Thanks again to both of you.