View Full Version : string as variable in stringstream

09 September 2009, 12:25 AM
Hi, after trying to figure this out for about 2 hours i thought its about time to ask it here :)

I'm working with a dynamic rollout (used a example i found here and altered it) and trying to
create a variable when a button is pressed. Now if the variable is an integer it works, but if i try to create it as a string the script errors.

this is what works:
format "\texecute (\"global objecttext_3=4\")\n" to:s

and this doesnt:
format "\texecute (\"global objecttext_3=\"stringtext\"\")\n" to:s

and this is the error:
>> MAXScript Rollout Handler Exception: -- Type error: Call needs function or class, got: "global objecttext_3=" <<

I hope someone can help me with this :)

09 September 2009, 02:39 AM
format "\texecute (\"global objecttext_3=\"stringtext\"\")\n" to:s
stringtext is a string within a string within a string:

format "< first string starts here
format "\texecute (\"< second string -- escaped using \
format "\texecute (\"global objecttext_3=\"< third string -- so you'll need to escape once again

The following should work:
format "\texecute (\"global objecttext_3=\\\"stringtext\\\"\")\n" to:s

09 September 2009, 10:10 AM
Thanks a lot!

this really helped me getting further with my script. Never did anything with those \ escapes before so this is quite a challenge :)

here is the latest piece of code im using in my script:
format "\texecute (\"global objecttext_\"+ rolloutCounter as string+\"=\"+\"\\\"stringtext\\\"\")\n" to:s
this allows me to create a unique variable whenever a new rollout is created.

Thanks again for the fast response!

CGTalk Moderation
09 September 2009, 10:10 AM
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.