View Full Version : Remove the quotes marks from a string how.?
gmlealll 01-16-2008, 05:29 PM I want to make a script that changes material properties base on what the user type on the edittext dialog
So the user types in an edittext the material property like mat.texmap_reflection.ior = 0
But the result from the edittext.text is
“mat.texmap_reflection.ior = 0”
and I need
mat.texmap_reflection.ior = 0
Any ideas?
see this sample please.
rollout test "test" width:300
(
edittext edi_Custom "mat." fieldWidth:165 align:#left across:2
spinner spn_Custom "%" range:[-1000,1000,0] align:#right
button go "Go"
on test open do
(
edi_Custom.text = "specularLevel"
)
on go pressed do
(
format "what:% value:% \n" edi_Custom.text spn_Custom.value
theChange = edi_Custom.text
meditMaterials[1].theChange = spn_Custom.value
)
)
createdialog test
Thanks,
Guillermo Leal
|
|
Eric-Harvey
01-16-2008, 05:51 PM
Not sure if this will help but you can evaluate a string as though it were a statement by using the execute command.
gmlealll
01-16-2008, 06:09 PM
thanls Eric for your replay,
i did try the execute and it works on a single item but not in an array. see the two samples.
this works.
rollout test "test" width:300
(
edittext edi_Custom "mat." fieldWidth:165 align:#left across:2
spinner spn_Custom "%" range:[-1000,1000,0] align:#right
button go "Go"
on test open do
(
edi_Custom.text = "specularLevel"
)
on go pressed do
(
--format "what:% value:% \n" edi_Custom.text spn_Custom.value
str = "meditMaterials[1]." + edi_Custom.text + "=" + spn_Custom.value as string
execute str
)
)
createdialog test
this dosen't
rollout test "test" width:300
(
edittext edi_Custom "mat." fieldWidth:165 align:#left across:2
spinner spn_Custom "%" range:[-1000,1000,0] align:#right
button go "Go"
on test open do
(
edi_Custom.text = "specularLevel"
)
on go pressed do
(
--format "what:% value:% \n" edi_Custom.text spn_Custom.value
TheMaterials = sceneMaterials
numOfMatInScene = TheMaterials.count
for i = 1 to numOfMatInScene do
(
--print TheMaterials[i]
str = TheMaterials[i] as string + "." + edi_Custom.text + "=" + spn_Custom.value as string
execute str
--print str
)
)
)
createdialog test
Guillermo Leal
Jon-Huhn
01-16-2008, 06:33 PM
In order to troubleshoot your code, I recommend you try to do the same exact execute command with each version (the single versus the array). You're doing enough different stuff in the one that's not working that it would be worth your while to mimick the one that IS working first.
Eric-Harvey
01-16-2008, 06:44 PM
Ok I have broken down the issue here. basically when you execute TheMaterials[i] it returns the name and type of that material instead of an index of the material. So the best soultion is to use scenematerials[i] directly to get your materials. Also you have to include the index number seperately and include the square bracke s in the surrounding strings. Im not sure if this makes sense, but here is the code that works.
rollout test "test" width:300
(
edittext edi_Custom "mat." fieldWidth:165 align:#left across:2
spinner spn_Custom "%" range:[-1000,1000,0] align:#right
button go "Go"
on test open do
(
edi_Custom.text = "specularLevel"
)
on go pressed do
(
--format "what:% value:% \n" edi_Custom.text spn_Custom.value
for i = 1 to sceneMaterials.count do
(
--print TheMaterials[i]
str = "sceneMaterials["+ (i as string) + "]." + edi_Custom.text + "=" + spn_Custom.value as string
execute str
--print str
)
)
)
createdialog test
gmlealll
01-16-2008, 08:04 PM
Eric,
Cool, that did the trick! thanks a lot.
Guillermo M Leal.
RustyKnight
01-17-2008, 01:08 AM
This is probably a stupid statement, but couldn't you use filterstring??
sText = “mat.texmap_reflection.ior = 0”
aText = filterString sText "/"" -- #("/“", mat.texmap_reflection.ior = 0, "/"”)
sValue = aText[2] //mat.texmap_reflection.ior = 0
Shane
RobGalanakis
01-17-2008, 03:56 AM
Please delete, double post
RobGalanakis
01-17-2008, 03:58 AM
Rusty, isn't the issue that even with filtering a string, you still have to execute it... the "'s aren't the problem, the fact that it is a string is, which is taken care of by executing it.
The thread title is not really what the OP wanted to do...
CGTalk Moderation
01-17-2008, 03:58 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.