the num of controls <> the num of last control

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
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

the num of controls <> the num of last control

Post by jmburnod » Wed Oct 22, 2014 2:02 pm

Hi All,
I discover the num of controls <> the num of last control.
I presume the num of last control doesn't count the controls in groups.
I'm right ?
Best regards
https://alternatic.ch

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: the num of controls <> the num of last control

Post by Klaus » Wed Oct 22, 2014 3:22 pm

No, "controls" will also list objects in groups!

Just made a little test here, created some objects and grouped some other objects.
Then I added this script to a button:

Code: Select all

on mouseUp
   put the num of controls into tNum
   repeat with i = 1 to tNum
      put i & TAB & the name of control i & CR after neu
   end repeat
   put neu
end mouseUp
And got this in the message box, which is correct:
1 button "tb1"
2 button "tb2"
3 field "Field1"
4 group id 1016
5 field "Field"
6 button "Button"
7 scrollbar "Progress Scrollbar"

Controls 5 to 7 are part of grp 4.

However:
put the num of last control -> give me 1 (one!)?

But:
put the layer of last control -> gives me 7, which is correct.

Make you own conclusions! :D


Best

Klaus

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

Re: the num of controls <> the num of last control

Post by jmburnod » Wed Oct 22, 2014 11:14 pm

Hi Klaus,
OK. I understand better except:
put the num of last control -> give me 1 (one!)?
I remain reserved about conclusions :roll: but I noted that the layer is a trick
Thanks again
Jean-Marc
https://alternatic.ch

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: the num of controls <> the num of last control

Post by [-hh] » Thu Oct 23, 2014 12:31 am

Hi,
as far as I understand, the "layer" is in back to front order (highest is "top"). That's close to clear, sometimes it is clearer for me to use the synonym "partNumber" instead of "layer".

The "number of" is more 'difficult' for me, has sometimes inconsistencies.

Presumably "the num of last control" is always one (if there are controls) or zero (if there are no controls), because "the last control" is one object or zero objects.
In your example, the num of control 2 will also be 1 (because it is one control).
The syntax control 2 to 5 is not accepted, if so, their num would be 4.

In the context of controls:
I would need a tutorial about the numbering of images within the larger set of controls (I learned: images are also controls *IF* they are on the same card).
Is here the syntax, I occasionally use to be safe, "image 2 of this cd" or "the num of images of this cd" an *obligatory* one?
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: the num of controls <> the num of last control

Post by dunbarx » Thu Oct 23, 2014 3:40 am

Layers and numbers are interconnected. The best way to see how they work is to place four controls all overlapping each other but with each having a portion of itself visible at all times. It is best if there are, say, two buttons and two fields, because then the numbers can be seen to track the types of controls, even as the layers change, and also change the numbers in turn.

Name the controls "b1,b2,f1 and f2" (buttons and fields get b's and f's)

put this in the card script:

Code: Select all

on mouseUp
  set the layer of btn "b1" to random(4)
   repeat with y = 1 to the number of controls
      put the name of control y &&  "(#" & the number of control y && ", Layer" &&  the layer of control y & ")"  into line y of temp
   end repeat
   put return & return & "Last =" && the name of last  control &&  "(, #" &  the number of last control && ", Layer" && the layer of last control  & ")" after temp
   put temp
end mouseUp
The numbers of the controls track their layers, but the types of controls keep their own little worlds.

Craig

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

Re: the num of controls <> the num of last control

Post by SparkOut » Thu Oct 23, 2014 7:58 am

There is a distinction here between num as a reference to the control (based on its layer) and num as a count, surely?

The num of the last control will be one because there is only one of it. You're asking for the count, not the "number assigned as its order in the collection of controls". (Which, because it is a collection of one, is one anyway.)

Am I missing the point?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: the num of controls <> the num of last control

Post by [-hh] » Thu Oct 23, 2014 10:51 am

SparkOut, we are wrong with the interpretation as "the count" of a set. Look into the dictionary entry of the property 'number': "The number of a control is a control's layer on card".

But the dictionary is also wrong here because an important thing is NOT mentioned:

The number of a control is always the partNumber(Layer) *within its object type*.

So in Jean-Marc's first example

= the num of last control is one because there is only one scrollbar.
= If he deletes the scrollbar then the num of last control is three, because there are three buttons.
= If he deletes the last button then the num of last control is two because there are two fields.

So in this context, if last control is for example a button:

the num of last control = the layer(partNumber) of last button
= the number (as count) of buttons

whereas the number of controls = the layer of the last control (over *all* controls).

This is hard for a beginner ...
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: the num of controls <> the num of last control

Post by dunbarx » Thu Oct 23, 2014 3:02 pm

Right, Hermann.

It is what I meant, though probably I said it badly:
The numbers of the controls track their layers, but the types of controls keep their own little worlds.
Only practicing with a set of controls will make this clear. The distinction between layers and numbers is consistent, and can be used to advantage. But you are correct in saying it takes a little work to master.

Craig

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

Re: the num of controls <> the num of last control

Post by jmburnod » Thu Oct 23, 2014 3:17 pm

Thank at all,
And sorry for the hard point for beginners :oops:
That is now clear for me.
Jean-Marc
https://alternatic.ch

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: the num of controls <> the num of last control

Post by [-hh] » Thu Oct 23, 2014 5:56 pm

Bonjour Jean-Marc,

what a thread you opened here, in the beginners subforum:

The 'posters' made in sum over 11000 posts. I am the only real beginner here. Presumably one has to reach a certain number of posts to be able to see and have ready to hand the little worlds of Craig ... ;-)

Hermann
shiftLock happens

Post Reply