Minor edit

On Wednesday, September 18, 2019 at 10:59:50 AM UTC+10, TonyM wrote:
>
> Melvin,
>
> You could mimic the Javascript approach quite closely, Because my 
> Javascript is somewhat vague and it is more involved to add it to 
> tiddlywiki I always use other methods.
>
> \define list-of-messages() [[Message 1]] [[Message 2]] [[Message 3]] [[
> Message 4]]
>
> or even
> \define list-of-messages() 
> [[Message 1]]
> [[Message 2]]
> [[Message 3]]
> [[Message 4]]
> \end
>
> And then you can use the set widgets select attribute to choose which 
> message to display. Since it is zero based use the new maths operators to 
> subtract one.
> Maths operators work nicely inside the triple braces.
>
> So *Untested* example
> <code>
> <$set name=dd value=<<now DD>> ><!-- I did not check if this works -->
> <$set name=todays-message filter=<<list-of-messages>> select={{{ [<dd>
> subtract[1]] }}}>
> <<todays-message>>
> </$set></$set>
> </code>
>
> Regards
> Tony
>
> On Wednesday, September 18, 2019 at 10:20:58 AM UTC+10, Melvin wrote:
>>
>> This took me a while, but I found a way to create a message of the day 
>> generator which changes the message given on how many messages you have and 
>> what day of the month it is. 
>>
>> You add the messages in [[]] and the code will do the rest :D
>>
>> The current 'bug' is that it will only allow you to have about 30 
>> messages, as it cannot display more messages of the day than there are days 
>> in the month.
>>
>> Copy/paste this Tiddler and see what message of the day you get!
>>
>> <style>
>> .message-of-the-day {
>>   color: red;
>> }
>> </style>
>>
>> <$wikify mode="inline" name="dayofmonth_val" text=<<now DD>> >
>> <$set name="messages" filter="
>>
>>
>> [[Message 1]] 
>>
>>
>> [[Message 2]]
>>
>>
>> [[Message 3]]
>>
>>
>> [[Message 4]]
>>
>>
>> ">
>> <$set name="list_length" filter="[enlist<messages>count[]]">
>> <$set name="list_index" filter="[<dayofmonth_val>remainder<list_length>]">
>> <$list variable="result" filter="
>> [enlist<messages>nth<list_index>]">
>> <h1><span class="message-of-the-day">Message of the day: 
>> <<result>></span></h1>
>> </$list>
>> </$set>
>> </$set>
>> </$set>
>> </$wikify>
>>
>>
>> My question here is: is there any way to do this more efficient?
>> In JavaScript this is the equivalent of: 
>>
>> var messages = ["Message 1", "Message 2", "Message 3", "Message 4"]
>> var result = messages[new Date().getDate() % messages.length]
>> //and then display the result var in anyway you see fit
>>
>> Which would be so much easier to write.
>>
>> I guess I need to learn how to create JS macro's or something similar.
>>
>> What do you think?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/954d007b-133e-47af-8e5e-548c099fcc05%40googlegroups.com.

Reply via email to