LiveCode Lessons question

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: Klaus, FourthWorld, heatherlaine, kevinmiller

bsnipes
Posts: 12
Joined: Mon Jul 23, 2018 10:12 pm

LiveCode Lessons question

Post by bsnipes » Wed Aug 29, 2018 3:01 am

While going through the lessons, I see in a few places a line referencing "field 1" such as:

Code: Select all

set the visible of field 1 to true
Is "field 1" to mean the name of the field is actually "1" or does that reference the first field on the card? I know it isn't the field id but want to clarify in my mind to make sure I am not missing another way of referencing fields. I would assume that in real world applications no one would name a field "1".

ClipArtGuy
Posts: 206
Joined: Wed Aug 19, 2015 4:29 pm

Re: LiveCode Lessons question

Post by ClipArtGuy » Wed Aug 29, 2018 3:21 am

I think it has to do with what "layer" the field is on.

Try this. Drag out 3 fields and a button. Put this into the button.

Code: Select all

on mouseup
   put "1" into fld 1
   put "2" into fld 2
   put "3" into fld 3
end mouseup
You will see that the numbers correspond to the order in which the fields were created. BUT, (and it's a big one) If you were to say, type this into the message box:

Code: Select all

set the layer of fld 1 to 2
and then press your button again, the number of your fields has changed. I'm not absolutely sure what is going on behind the scenes, but as far as I can tell it's safest to use the field name or ID, and if you need them numbered, to use a naming scheme like "myFld1", "myFld2", etc

bsnipes
Posts: 12
Joined: Mon Jul 23, 2018 10:12 pm

Re: LiveCode Lessons question

Post by bsnipes » Wed Aug 29, 2018 3:28 am

Thanks for the clarification. I do name my fields (probably poorly but consistently :D ). I can't say I like the way the number is used for the lessons without an explanation of it. I wonder if the numbers correspond to the object layer list for the stack. Oh well... LiveCode is SO different from Python. But at least I now have an easy crossplatform app environment to work with :D

ClipArtGuy
Posts: 206
Joined: Wed Aug 19, 2015 4:29 pm

Re: LiveCode Lessons question

Post by ClipArtGuy » Wed Aug 29, 2018 3:39 am

At the risk of being totally off-topic, I've thought for some time now that it would be cool if we were somehow able to integrate a python interpreter into LC, and choose between LC script or python on a by object basis. I have no idea how difficult something like that would be to actually implement, but if it was possible, might help bring a lot of new users over.

bogs
Posts: 2373
Joined: Sat Feb 25, 2017 10:45 pm

Re: LiveCode Lessons question

Post by bogs » Wed Aug 29, 2018 11:40 am

bsnipes, you had it right in the question, AND ClipArtGuy has how you can change it correct :wink:

Just for the record -
Selection_003.png
About Number...
bsnipes wrote:
Wed Aug 29, 2018 3:28 am
Thanks for the clarification. I do name my fields (probably poorly but consistently :D ).
Consistency is important. When I'm naming something, I use an old technique that tells me right away what the object is by pre-pending 3 letters of the object type to the object goal, in camel case.

So, for instance, buttons execute commands lets say. My button names all start with 'cmd', i.e. - cmdExit.
Windows are frmName, cards are crdName, groups are grpName, labels are lblName, text entry fields txtName, and so on.

When creating a loop to go through a series of controls, it makes it a lot easier to target a specific set just by writing something like

Code: Select all

if characters 1-3 of the short name of control x = "txt" then put empty into control x
// clears the field
Hope that helps :)

*Edit - I should probably have mentioned the above naming convention also practically eliminates the possibility that you will accidentally choose a reserved word for a name.
Image

bsnipes
Posts: 12
Joined: Mon Jul 23, 2018 10:12 pm

Re: LiveCode Lessons question

Post by bsnipes » Wed Aug 29, 2018 10:19 pm

So, my LiveCode Lesson for this week is "look in the Dictionary or Help for the answer before posting" :-) Thanks for your responses.
Many, many, many moons ago, I bought Visual Basic 2.0 (on floppies of course) and LiveCode lessons bring back memories of going through its programming guide that came with it. LiveCode has really done a very good job.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5613
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: LiveCode Lessons question

Post by dunbarx » Wed Aug 29, 2018 10:25 pm

A corollary to all this is the following:

NEVER NAME AN OBJECT WITH A NUMBER

Ahem. Sorry.

Because if you try to put "X" into fld 1, is LC to assume you mean the first field, or the one named "1"?

SEE??? JUST DON'T.

Sorry.

Craig Newman

ClipArtGuy
Posts: 206
Joined: Wed Aug 19, 2015 4:29 pm

Re: LiveCode Lessons question

Post by ClipArtGuy » Wed Aug 29, 2018 10:37 pm

bsnipes wrote:
Wed Aug 29, 2018 10:19 pm
So, my LiveCode Lesson for this week is "look in the Dictionary or Help for the answer before posting" :-)
The dictionary is definitely a great place to start. I read through the "layer" entry a couple times, but I probably never would have thought to search "number". I'd say that "number" should be added in the related section of the "layer" entry in the same way that "layer" IS in the related section of the entry for "number".

bogs
Posts: 2373
Joined: Sat Feb 25, 2017 10:45 pm

Re: LiveCode Lessons question

Post by bogs » Wed Aug 29, 2018 11:00 pm

dunbarx wrote:
Wed Aug 29, 2018 10:25 pm
A corollary to all this is the following:
NEVER NAME AN OBJECT WITH A NUMBER
That really is good advice, but I would say that if you really want to use a number, spell it out, i.e. [txtOne]. Otherwise, only use them to differentiate when you hit a naming block, like [txtName1][txtName2] etc.
ClipArtGuy wrote:
Wed Aug 29, 2018 10:37 pm
bsnipes wrote:
Wed Aug 29, 2018 10:19 pm
So, my LiveCode Lesson for this week is "look in the Dictionary or Help for the answer before posting" :-)
The dictionary is definitely a great place to start. I read through the "layer" entry a couple times, but I probably never would have thought to search "number". I'd say that "number" should be added in the related section of the "layer" entry in the same way that "layer" IS in the related section of the entry for "number".
Isn't it?
And the Lc Dictionary wrote: layer
Type: property
Syntax:
set the layer of object to {layerNumber | top | bottom}
Synonyms:
partNumber
See Also: number Function, control Keyword, ungroup Command, group Command, mouseControl Function, intersect Function, tabGroupBehavior Property, relayerGroupedControls Property, relayer Command
Of course, my dictionaries are quite old :P So I went and looked in the newer one...
Selection_003.png
Gasp!
All joking aside, though, yes the dictionary and help guides *are* great to look in but unless you have some idea of how the language works, they can also be an exercise in frustration :lol: If you get stuck for the words to look for, I'd say feel free to drop in and ask (lord knows I did :P ). Likely as not, someone else has asked the self same questions and will guide you along :)
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5613
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: LiveCode Lessons question

Post by dunbarx » Wed Aug 29, 2018 11:30 pm

I frequently use such monikers as "fld1" or btn4". As long as naked integers are never used.

Craig

ClipArtGuy
Posts: 206
Joined: Wed Aug 19, 2015 4:29 pm

Re: LiveCode Lessons question

Post by ClipArtGuy » Wed Aug 29, 2018 11:39 pm

bogs wrote:
Wed Aug 29, 2018 11:00 pm

Isn't it?
:oops: Indeed it is. Not sure how I missed it. I must have only looked at the properties, as that's kind of what i expected it was.



EDIT: Which I guess I could be forgiven for, considering the last line of the description says
Changing the layer of an object also changes its number property.

bogs
Posts: 2373
Joined: Sat Feb 25, 2017 10:45 pm

Re: LiveCode Lessons question

Post by bogs » Thu Aug 30, 2018 12:40 pm

ClipArtGuy wrote:
Wed Aug 29, 2018 11:39 pm
bogs wrote:
Wed Aug 29, 2018 11:00 pm
Isn't it?
EDIT: Which I guess I could be forgiven for, considering the last line of the description says
Changing the layer of an object also changes its number property.
Why would you have to be forgiven? Of course it says that, which is why I said way up there -
bogs wrote:
Wed Aug 29, 2018 11:40 am
... AND ClipArtGuy has how you can change it correct...
...and so we've come full circle :mrgreen:

(I hope we didn't loose anyone along the way :twisted: )
Image

cowtrax3
Posts: 5
Joined: Mon Sep 24, 2018 1:34 am

Re: LiveCode Lessons question

Post by cowtrax3 » Tue Oct 09, 2018 8:02 pm

I have a screen with 10 fields displayed. I want them to progress from top to bottom but their "order" is not correct. When i tab it goes all over the place. How do you set the "tab order" of fields on the screen so as they progress correctly? Thanks.

SparkOut
Posts: 1822
Joined: Sun Sep 23, 2007 4:58 pm

Re: LiveCode Lessons question

Post by SparkOut » Tue Oct 09, 2018 8:27 pm

Tab order can be affected by a couple of things like whether the traversalOn property is set, but basically the order is set by the layer number from lowest to highest.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5613
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: LiveCode Lessons question

Post by dunbarx » Tue Oct 09, 2018 8:45 pm

Hi.

This is a change of subject, no?

Anyway, there are two ways to do this:

1- Relayer the fields so that they automatically allow a tab to open the next field in layer order.

2- Explicitly select the text of the "next" field of interest. This can be useful, though perhaps tedious, when the fields change in some way, but you want them to tab in a predefined order:

Code: Select all

on tabkey
  select text of fld "nextFieldDesired"
  end tabKey
Each field would have its own handler, unless you can set up a routine in the card script that uses the target to determine the next field desired.

Craig Newman

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”