[Closed] Wrong with this code,but where it wrong?
Hi guys…i’m coming again…:wip:
I’m doing a test : rename a obj use “editext”, and i want to change its name same as max file’s.
But it not work. I tried to look “editext” in help, but…i really didn’t konw where it wrong.
rollout nam "Name"
(
button click1 "Pick" width:50 height:25 pos:[10,20]
button click2 "Rename" width:50 height:25 pos:[10,50]
edittext editx2 "" fieldWidth:120 pos:[62,20] labelOnTop:false
on click1 pressed do
(
max tool hlist
a = $.name
editx2.text = a
)
on click2 pressed do
(
nam1 = getfilenamefile maxfilename
nam2 = substring nam1 1 (nam1.count-5)
editx2.text = nam2 + "00"
on editx2 changed do
$.name = editx2.text
)
)
newroll=newrolloutfloater "-Square" 220 120
addRollout nam newroll
First of all, you were missing some brackets that were causing an error.
Secondly, the “on changed” function requires a variable to be inserted when you call it. This gets passed down inside the function, so you can access the text from the textbox easily.
Also, your “rename” button doesn’t actually change the name of the object. I’m not sure if that’s intentional so I didn’t modify that bit of code.
Here’s the fixed script:
rollout nam "Name"
(
button click1 "Pick" width:50 height:25 pos:[10,20]
button click2 "Rename" width:50 height:25 pos:[10,50]
edittext editx2 "" fieldWidth:120 pos:[62,20] labelOnTop:false
on click1 pressed do
(
max tool hlist
a = $.name
editx2.text = a
)
on click2 pressed do
(
nam1 = getfilenamefile maxfilename
nam2 = substring nam1 1 (nam1.count-5)
editx2.text = nam2 + "00"
)
on editx2 changed var do(
$.name = var
)
)
newroll=newrolloutfloater "-Square" 220 120
addRollout nam newroll[b]
[/b]
Yeah…ivanisavich…I forgot it , i want to rename two objs by “rename” button. and actually their name weren’t changed.
I amended it ,but the problem was still being…
rollout nam "Name"
(
button click1 "Pick" width:50 height:25 pos:[10,20]
button click2 "Rename" width:50 height:25 pos:[10,100]
button click3 "Pick" width:50 height:25 pos:[10,60]
edittext editx2 "" fieldWidth:120 pos:[62,20] labelOnTop:false
edittext editx3 "" fieldWidth:120 pos:[62,60] labelOnTop:false
on click1 pressed do
(
max tool hlist
a = $.name
editx2.text = a
)
on editx2 changed var do(
$.name = var
)
on click3 pressed do
(
max tool hlist
a = $.name
editx3.text = a
)
on editx3 changed var do(
$.name = var
)
on click2 pressed do
(
(
nam1 = getfilenamefile maxfilename
nam2 = substring nam1 1 (nam1.count-5)
editx2.text = nam2 + "00"
$.name = editx2.text
)
on editx2 changed var do
(
$.name = var
)
(
nam3 = getfilenamefile maxfilename
nam4 = substring nam1 1 (nam1.count-5)
editx3.text = nam4 + "01"
$.name = editx3.text
)
on editx3 changed var do
(
$.name = var
)
)
)
newroll=newrolloutfloater "-Square" 220 220
addRollout nam newroll
This part seems to be off to me:
on editx2 changed var do
(
$.name = var
)
(
nam3 = getfilenamefile maxfilename
nam4 = substring nam1 1 (nam1.count-5)
editx3.text = nam4 + "01"
$.name = editx3.text
)
You’ve already set up editx2 on the code before, and the second part seems to just be hanging on the middle of the rollout definition.