![]() |
#271 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
You can pass variables to stored templates using the arguments function (read the documentation for more info)
|
![]() |
![]() |
![]() |
#272 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
That works! Can more than one argument be set per template? e.g. swapping "#aaaa" for "colourA" and then setting that in the external template.
Also, I found out the issue I was having with days_between -- I put the arguments in the wrong order and getting negative numbers which were all less than 1. I think I made this mistake before. Last edited by ownedbycats; 01-07-2022 at 01:40 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#273 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You can pass as many arguments as you want. You can also set it up so that arguments have default values. See the docs.
|
![]() |
![]() |
![]() |
#274 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I've got it.
![]() Code:
program: arguments(date, colourA, colourB, colourC); now = format_date(today(), 'yyyy-MM-dd'); if days_between(now,date) <= '1' then colourA elif days_between(now,date) <= '7' then colourB elif days_between(now,date) <= '14' then colourC fi Code:
program: colours_daysbetween($#lastread, '#1c7eff', '#538fff', '#2b5aa2') Last edited by ownedbycats; 01-08-2022 at 08:39 PM. |
![]() |
![]() |
![]() |
#275 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
edit: whoops, figured it out
|
![]() |
![]() |
Advert | |
|
![]() |
#276 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Try this: Code:
program: arguments(date, colourA, colourB, colourC); now = format_date(today(), 'yyyy-MM-dd'); days = days_between(now,date); if days <=# 1 then colourA elif days <=# 7 then colourB elif days <=# 14 then colourC fi |
|
![]() |
![]() |
![]() |
#277 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes I'll fix that.
Someone I know was learning Python and their program told them that the double of '5' was '55.' Which is correct... if you want to double the string '5' instead of the integer '5.' ![]() |
![]() |
![]() |
![]() |
#278 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question: Is undefined the same as '0' in a days_between?
Code:
program: read = $$#lastread; updated = $$#fanficupdated; if $$#percentread <# 100 && days_between (read, updated) <=# 0 then '#ffff7f' fi |
![]() |
![]() |
![]() |
#279 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I suggest that you don't depend on that, instead being explicit about what happens if dates are undefined. There are at least two ways to do it. The first is to use raw_field() with a default, for example Code:
read = raw_field('#lastread', today()); Another way, one that I prefer, is to test if the two dates are defined and do something explicit. Something like this: Code:
program: read = $$#lastread; updated = $$#fanficupdated; if read == 'none' || updated == 'none' then '#090909' elif $$#percentread <# 100 && days_between (read, updated) <=# 0 then '#ffff7f' fi Code:
program: read = $$#lastread; updated = $$#fanficupdated; if read == 'none' || updated == 'none' then days = -1 else days = days_between (read, updated) fi; if $$#percentread <# 100 && days <=# 0 then '#ffff7f' fi Last edited by chaley; 01-10-2022 at 03:34 PM. Reason: Fix typo |
|
![]() |
![]() |
![]() |
#280 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes, I was thinking of adding a test. Though just keeping it <# would work too for this specific case; I was checking that #fanficupdated was newer than #lastread (e.g. when a fanfic updates and I haven't read the new chapter yet).
|
![]() |
![]() |
![]() |
#281 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question: When using a stored template that returns 'True' if it matches certain criteria (psuedobools), I noticed these work the same:
Code:
program: if stored_returnstrueifvalid() == 'True' then 'output' fi Code:
program: if stored_returnstrueifvalid() then 'output' fi Also, is there any good way to test two templates getting same results on a set of books aside from shuffling it between the tester and Notepad? I don't believe there's a way to have two tester instances open. Last edited by ownedbycats; 01-11-2022 at 10:31 PM. |
![]() |
![]() |
![]() |
#282 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
Last edited by chaley; 01-22-2022 at 03:45 PM. Reason: Grammar |
||
![]() |
![]() |
![]() |
#283 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks
![]() I came across some strange behaviour with a new template (ignore the wonky indenting, I removed a lot of other if-thens): Code:
program: f = re($#chapters, '(.*)/.*', '\1'); s = re($#chapters, '.*/(.*)', '\1'); newpercent = round(multiply ((f / s), 100)); if newpercent < 99 then newpercent else 98 fi Basically: Divide F by S. Multiply it by 100. Round it to the nearest digit. If the number less than 99, use the new number; otherwise set it to 98. But on line 6 if I add a '#' to if newpercent < #98 for the numeric comparison I get this error: Code:
EXCEPTION: Formatter: Failed to scan program. Invalid input '#99 then newpercent \n\t\t\t\t\t\telse 98\n\t\t\t\t\tfi' near the end of the program EDIT: I misplaced a space. It should've been <# not < #. ![]() Last edited by ownedbycats; 01-13-2022 at 03:10 AM. |
![]() |
![]() |
![]() |
#284 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,452
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#285 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,037
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Yes it works.
![]() |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 225 | 08-04-2025 06:31 PM |
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates | Boilerplate4U | Development | 13 | 07-07-2020 02:35 AM |
Questions on Kobo [Interfered with another thread topic] | spdavies | Kobo Reader | 8 | 10-12-2014 11:37 AM |
[OLD Thread] Some questions before buying the fire. | darthreader13 | Kindle Fire | 7 | 05-10-2013 09:19 PM |
Thread management questions | meme | Feedback | 6 | 01-31-2011 05:07 PM |