Sort cards

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

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Sort cards

Post by Tomalain » Wed Nov 01, 2017 3:59 pm

Hello,
beginners with LC, I got a problem with a handler which was working well, but after some updates (which ones?) does not function anymore.
Clicking the button to sort, nothing happening

The script is:
on mouseUp
Answer "Séquence de tri des cartes bibliothèque:" with "Année" or "Auteur"
or
"Numéro"
If it = "Année" then sort cards by field "Année" of bg "BG-Livre"
else
if it = "Auteur" then sort cards by field "Auteur" of bg "BG-Livre"
else sort cards by field "No" of bg "BG-Livre"
end if
beep
ask "Fin du Tri "&it
end mouseUp

Could it deal with Group?
Thanks for any help

Tomalain

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

Re: Sort cards

Post by dunbarx » Wed Nov 01, 2017 5:17 pm

Hi.

Your handler compiles without issue.

Is the group present on all cards? It has to be.

But I have no idea what is in the fields that the "sort" command is using as a sortKey, so I have no idea how they should work. The contents of those fields ("Année" and "Auteur") , whether in a group or not, will determine the nature of the resultant sorting. That is why the referenced fields have to be on every card in the sort, otherwise any card without that field will be neglected.

Sometimes you want to neglect certain cards, but that is another story.



Craig Newman

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

Re: Sort cards

Post by jmburnod » Wed Nov 01, 2017 5:19 pm

Welcome to this forum, Bienvenue (I speak french and a little bit "Lemanic's english)
I tried your script and i discover it works with "group" instead "bg". I also replaced ask with answer at the end

Code: Select all

   on mouseup
   Answer "Séquence de tri des cartes bibliothèque:" with "Année" or "Auteur" or "Numéro" or "Annuler"
   if it = empty then exit mouseup
   If it = "Année" then sort cards by field "Année" of group "BG-Livre"
   else
      if it = "Auteur" then sort cards by field "Auteur" of group "BG-Livre"
      else sort cards by field "No" of group "BG-Livre"
   end if
   beep
   answer "Fin du Tri "&it --
end mouseup
Clicking the button to sort, nothing happening
What about "script debug mode" of "Development" menu ?
Best regards
Jean-Marc
https://alternatic.ch

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

Re: Sort cards

Post by dunbarx » Wed Nov 01, 2017 5:46 pm

I tried your script and i discover it works with "group" instead "bg".
Jean-Marc.

These are synonyms, no? Did it NOT work with "group"?

Craig

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Wed Nov 01, 2017 5:50 pm

thank you jean-marc for your suggestions, I am afraid it's a problem with Groups.
I had to modify the original group adding more controls, and it's rather a nightmare.
It may happen that not all cards have the same bg definition ?

I will try the debug mode

I tried to attach the stack but this is rejected.

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

Re: Sort cards

Post by jmburnod » Wed Nov 01, 2017 6:39 pm

Group can work like a background (background behavior = true) or not and shared or not,
If it background behavior = true this group is placed automaticaly when you create a new cd (it become also shared in this case).
If you modify a background, it will modified in all card which have this background.
Please note that the script of a background commes between cd script and stack script in the messages hierarchy.
I believe you can post a zip of a stack after you posted 10 messages
Best
Jean-Marc
https://alternatic.ch

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

Re: Sort cards

Post by jmburnod » Wed Nov 01, 2017 6:47 pm

Hi Craig,
These are synonyms, no? Did it NOT work with "group"?
I thought but it doesn't work without error when i use "bg" instead "group" (LC 8.1.6)
Jean-Marc
https://alternatic.ch

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Thu Nov 02, 2017 10:51 am

Hi
Reply to Craig's advices,
Thank you Craig, The field "Année" contains Year on 4 digits, while "Auteur" is the Author of the book, alphanumeric.
The field "No" is a number , from 1 to 1000, normally numeric, but some field contain left space.
Presently the sort command does not work at all, neither on field "No" nor "Auteur".

Is the some property in the Group that prevent its field to be seen by the sort command?

I believe the best I have to do is to write a Handler which export all cards (about 1000) and another one to reload the stack.
Then can I be sure that every card will have the same (correct?) background.
Alain

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

Re: Sort cards

Post by dunbarx » Thu Nov 02, 2017 3:28 pm

No, don't do anything rash quite yet. Sorting by the contents of a field is old magic.

LC will use the contents of each field on each card as a sortKey. If a field does not appear on a card, it is ignored. This can either be useful or annoying.

It is the field reference that matters; it makes no difference to which group that field belongs to or not.

So the field "Annee" contains a plain four digit number? If in the message box:

Code: Select all

sort cards numeric by field "Annee"
what happens? Try again with field "Auteur" (no numeric). What happens?

You can scramble the card order at any time so that you can see if the above commands do their job by:

Code: Select all

sort cards by random(999)
Craig

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

Re: Sort cards

Post by jmburnod » Thu Nov 02, 2017 6:08 pm

Hi Alain,
Then can I be sure that every card will have the same (correct?) background.
You may verify this with a script which get the id of group "BG-Livre" in each cd.
Craig,
Yes it also works with fld "Auteur"
Jean-Marc
Last edited by jmburnod on Thu Nov 02, 2017 6:13 pm, edited 1 time in total.
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Sort cards

Post by jacque » Thu Nov 02, 2017 6:10 pm

"Group" and "bg" can be interchangeable sometimes but are not always synonyms. Group refers to the card level and bg to the stack level. Asking if there is a grp x or there is a bg x will both return true if there is a shared group with background behavior on the current card. You'll get different responses if the group isn't currently placed on the card: there will not be a grp x but there will be a bg x.

Sorting cards requires inspecting the groups on each card, which is why "bg" won't work here.

There is also a difference in the message path. Groups with background behavior receive messages after the card gets them, while card groups get messages before the card does.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Thu Nov 02, 2017 8:24 pm

tested "sort cards by random(999)" using the message box,... works well, ... cards get random
try then my handler, called from a "Home" card, nothing happens, as the sort would be ignored. The handler is launched. Same for all 3 sort options.

One question,
is it necessary to specify that field "No" belongs to bg 'BG-Livre"
some trial show that it works as well without

sort card by field "Auteur" behave as sort card by field "Auteur" of bg "BG-Livre"
(when the sort operates !

Alain

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

Re: Sort cards

Post by dunbarx » Thu Nov 02, 2017 10:18 pm

Tomalain

With all the information you have, you should know that sorting by using a field reference will work, regardless of whether that field belongs to a group or not, and whether or not that group is a backGround group.

The sortKey is the field itself.

If you are having issues, it must be that the field is not present on all cards. Such cards will sort before any others that do indeed contain the sort field. LC will sort such a card as if the field was there, but was empty.

Or perhaps the data in that field is not what you expect?

What do you see when you try the handler? Is there simply no sort at all, or a sort different from what you expect?

Craig

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

Re: Sort cards

Post by jmburnod » Thu Nov 02, 2017 10:22 pm

Alain,
is it necessary to specify that field "No" belongs to bg 'BG-Livre"
No, if you have only one fld "no"
Please, replace "bg" with "group" in your script
Jean-Marc
https://alternatic.ch

Tomalain
Posts: 8
Joined: Wed Nov 01, 2017 3:49 pm

Re: Sort cards

Post by Tomalain » Thu Nov 02, 2017 10:23 pm

Hello Graig,

Thanks
there is no sort at all
I tried with the Handler i Posted, but also from the message box
and from a button specially created on a card

Nothing

The only sort I got is the random one from the message box

Post Reply