Stupid one - how do you rename a control?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Stupid one - how do you rename a control?

Post by admin12 » Thu Aug 11, 2011 10:15 pm

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

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

Post by shaosean » Thu Aug 11, 2011 10:17 pm

Take a look at the name property.

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Thu Aug 11, 2011 10:44 pm

grrr. I know. I tried.

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

does not work.

What is the proper syntax?

Mike

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Thu Aug 11, 2011 11:21 pm

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

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Thu Aug 11, 2011 11:50 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4012
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

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

Post by bn » Fri Aug 12, 2011 12:00 am

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

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Fri Aug 12, 2011 12:00 am

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

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Fri Aug 12, 2011 12:04 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4012
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

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

Post by bn » Fri Aug 12, 2011 12:05 am

Hi Mike,

could you try:

Code: Select all

clone graphic tRectangleToBeCloned
instead of
clone rect tRectangleToBeCloned
kind regards

Bernd

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Fri Aug 12, 2011 12:50 am

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”