PDA

View Full Version : Formatting text for script controller


scrimski
03-23-2009, 07:56 PM
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.

Piflik
03-23-2009, 08:12 PM
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')

scrimski
03-23-2009, 08:26 PM
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?

Piflik
03-23-2009, 08:51 PM
Yeah....

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


should print out

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

scrimski
03-23-2009, 08:58 PM
Zing!
Everything I see is MaxScript code. Enough for today.

PiXeL_MoNKeY
03-23-2009, 08:58 PM
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

scrimski
03-23-2009, 09:08 PM
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
That'S even better. Just missed the + in the string part.

Thanks again to both of you.

CGTalk Moderation
03-23-2009, 09:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.