Referencing Objects by Name

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Referencing Objects by Name

Post by townsend » Sun Feb 13, 2011 8:59 pm

Just getting started here-- day 1.

After 10 years with Visual Basic, I've done extensive evaluations on: AlphaFive, Morfik, & WaveMaker.
LiveCode seems to be the best yet! Hopefully-- now-- I can get some work done.

Ordinarily I like to use descriptive names for my objects. For example, two text objects might be called: firstName and lastName.
This makes remembering the names very easy.

But now, with LiveCode, it seems that I can only reference these two text objects as, Field 1, and Field 2.
When I have a dozen or more object in window-- in a stack-- this could become quite cumbersome, remembering objects by their assigned number.

I must be missing some simple here. Thanks-- I appreciate any guidance.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Referencing Objects by Name

Post by bn » Sun Feb 13, 2011 9:13 pm

Hi Townsend,

welcome to the forum.

usually you dont refer to objects by their number. I would discourage this except for a quick test stack you then delete.

The number of an object is not persistent. It depends on where the object is. By moving a field more to the front relative to other fields (in the inspector -> size and position) you change the field number.

You name the objects in the inspector or properties inspector. There is a field for the name of the object.

And referencing an object by name you should always put the name within quotes. Which you are probably used to from your prior experience. In Livecode you dont have to but it is faster and less errorprone to quote literals.

And you might want to know that if you refer to an object like

Code: Select all

put 5 into field "myFieldName" 
you imply that you mean the current card and livecode internally adds that.
By giving the full path

Code: Select all

put 5 into field "myFieldName" of card "myCardName" of stack "myStackName"
you can address fields and other objects on other cards or even in other open stacks.

Kind regards

Bernd

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Referencing Objects by Name

Post by jmburnod » Sun Feb 13, 2011 9:14 pm

Hi Towsend,
But now, with LiveCode, it seems that I can only reference these two text objects as, Field 1, and Field 2.
You can rename all objects how you want in the basic properties of the object inspector
Best
Jean-Marc
https://alternatic.ch

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: Referencing Objects by Name

Post by townsend » Sun Feb 13, 2011 10:14 pm

Thanks guys-- that's it!

One more thing-- some strange behavior here-- as a test. I set up a button called Reset, and went to clear my two text fields with:

Code: Select all

on mouseUp
   put "" into field "firstName"
end mouseUp
But for some reason, every time I try to put the second line of code in there...

Code: Select all

put "" into field "lastName"
The Script Editor closes down. (??) It's as though it will only allow me to put that one line of code in.

Then I downloaded a sample app from the RevOnline window, and there too-- when I went to add a line of code, the Script Editor closed down.

Also, I tried the "Reset All Preferences to Defaults" -- That wasn't it.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Referencing Objects by Name

Post by bn » Sun Feb 13, 2011 10:18 pm

Hi Townsend,

I dont know what happened but if you hit the enter key the first time the script compiles if you hit the enter key a second time the editor closes.

Could it be this, what you see?

Kind regards

Bernd

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: Referencing Objects by Name

Post by townsend » Sun Feb 13, 2011 10:33 pm

Okay-- Shift + Enter does see to work.

Maybe it's a Windows 7 quirk?

Thanks for your help bn--

Post Reply