Page 1 of 1

Stupid one - how do you rename a control?

Posted: Thu Aug 11, 2011 10:15 pm
by admin12
In the property inspector, there is a NAME category.

When I clone a block, I want to change the name - so rectDrum would be cloned and renamed to rectDrum2, etc.

How is this done. Is this a bad idea? Eventually, I am going to want to mix all the blocks of all the drags into a two track wave file. I am sure it is better to put everything into an array. Someone helped me out with that, I just have to understand how to apply it. Arrays are so different in Live Code. I just don't get them yet.

Mike

Re: Stupid one - how do you rename a control?

Posted: Thu Aug 11, 2011 10:17 pm
by shaosean
Take a look at the name property.

Re: Stupid one - how do you rename a control?

Posted: Thu Aug 11, 2011 10:44 pm
by admin12
grrr. I know. I tried.

set name of rect "rectDrum" to rect "rectDrum2"

does not work.

What is the proper syntax?

Mike

Re: Stupid one - how do you rename a control?

Posted: Thu Aug 11, 2011 11:21 pm
by mwieder
You know, I was gonna send you back to the documentation again, but I just looked and the examples there aren't really that straightforward. The crux of the matter is that you have to set the name to a string. Giving an object reference isn't enough. So in your example you'd want

set name of rect "rectDrum" to "rectDrum2"

but given what you're trying to accomplish you will probably want to end up with something more like

Code: Select all

clone rect "rectDrum"
set the name of it to "rectDrum2"
or

Code: Select all

clone rect "rectDrum"
set the name of it to "rectDrum" & tDrumNumber
or even

Code: Select all

put "rectDrum" into tRectangleToBeCloned
clone rect tRectangleToBeCloned
set the name of it to (the name of tRectangleToBeCloned) & tDrumNumber

Re: Stupid one - how do you rename a control?

Posted: Thu Aug 11, 2011 11:50 pm
by admin12
I assume I have to global tDrumNumber

and then add one to it each time?

Thank you for your help. Yes, the examples in the dictionary and guide don't help.

Mike

Re: Stupid one - how do you rename a control?

Posted: Fri Aug 12, 2011 12:00 am
by bn
Hi Mike,
did you try:

Code: Select all

set name of grc "rectDrum" to  "rectDrum2"
instead of
set name of rect "rectDrum" to rect "rectDrum2"
rect is not an object, it is a property or a tool.

Kind regards

Bernd

Re: Stupid one - how do you rename a control?

Posted: Fri Aug 12, 2011 12:00 am
by admin12
I get an error:

on mouseDown
add 1 to tDrumNumber
put "rectDrum" into tRectangleToBeCloned
clone rect tRectangleToBeCloned
set the name of it to (the name of tRectangleToBeCloned) & tDrumNumber
end mouseDown

in the line: put "rectDrum" into tRectangleToBeCloned

The name of the rectangle is "rectDrum"

What is wrong?

Mike

Re: Stupid one - how do you rename a control?

Posted: Fri Aug 12, 2011 12:04 am
by admin12
grc does not work and this code below does not work:

on mouseDown
add 1 to tDrumNumber
put "rectDrum" into tRectangleToBeCloned
clone tRectangleToBeCloned
set the name of it to (the name of tRectangleToBeCloned) & tDrumNumber
end mouseDown

How do I make it work - seems very logical to me. This Live Code syntax is so tough to get a hold of after programming other languages.

Mike

Re: Stupid one - how do you rename a control?

Posted: Fri Aug 12, 2011 12:05 am
by bn
Hi Mike,

could you try:

Code: Select all

clone graphic tRectangleToBeCloned
instead of
clone rect tRectangleToBeCloned
kind regards

Bernd

Re: Stupid one - how do you rename a control?

Posted: Fri Aug 12, 2011 12:50 am
by admin12
And the winner is . . .

on mouseDown
add 1 to tDrumNumber
put "rectDrum" into tRectangleToBeCloned
clone graphic tRectangleToBeCloned
--set the name of it to (the name of tRectangleToBeCloned) & tDrumNumber
set name of it to "rectDrum" & tDrumNumber
end mouseDown

That works.

Mike