Page 1 of 2
Sort cards
Posted: Wed Nov 01, 2017 3:59 pm
by Tomalain
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
Re: Sort cards
Posted: Wed Nov 01, 2017 5:17 pm
by dunbarx
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
Re: Sort cards
Posted: Wed Nov 01, 2017 5:19 pm
by jmburnod
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
Re: Sort cards
Posted: Wed Nov 01, 2017 5:46 pm
by dunbarx
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
Re: Sort cards
Posted: Wed Nov 01, 2017 5:50 pm
by Tomalain
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.
Re: Sort cards
Posted: Wed Nov 01, 2017 6:39 pm
by jmburnod
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
Re: Sort cards
Posted: Wed Nov 01, 2017 6:47 pm
by jmburnod
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
Re: Sort cards
Posted: Thu Nov 02, 2017 10:51 am
by Tomalain
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
Re: Sort cards
Posted: Thu Nov 02, 2017 3:28 pm
by dunbarx
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:
Craig
Re: Sort cards
Posted: Thu Nov 02, 2017 6:08 pm
by jmburnod
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
Re: Sort cards
Posted: Thu Nov 02, 2017 6:10 pm
by jacque
"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.
Re: Sort cards
Posted: Thu Nov 02, 2017 8:24 pm
by Tomalain
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
Re: Sort cards
Posted: Thu Nov 02, 2017 10:18 pm
by dunbarx
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
Re: Sort cards
Posted: Thu Nov 02, 2017 10:22 pm
by jmburnod
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
Re: Sort cards
Posted: Thu Nov 02, 2017 10:23 pm
by Tomalain
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