may be

\define my-actions(x)
<$set name="qTopic" value="""$x$""">
<$set name="qName" value={{$:/.user/temp/quiz!!givenName}}>

<$action-sendmessage $message="tm-new-tiddler" title=<<qName>> tags="Quiz" 
topic=<<qTopic>> list=<<getRandomisedSequenceOfTitles """$x$""">>/>

</$set>
</$set>
\end

Select a topic for quiz:
<$select tiddler="$:/.user/temp/quiz" field="selectedTopic">
<$list filter='[tag[Topic]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>

Enter a name for quiz:
<$edit-text tiddler="$:/.user/temp/quiz" field="givenName" 
default="QuizName" />

<$button >
<$macrocall $name="my-actions" x={{$:/.user/temp/quiz!!selectedTopic}}/>
Create Quiz
</$button>

On Sunday, February 25, 2018 at 8:23:25 PM UTC+1, passingby wrote:
>
> While making a small quiz app for myself I needed a macro/plugin which 
> would randomise a list of titles. Matthew Lauber's shuffle operator did 
> just this. 
> But then for learning purposes ( so that I use the opportunity to create 
> custom javascript macros), I decided to make a simple javascript macro for 
> myself.
>
> My plan is:
> 1. First step; add a topic to TW. Create a tiddler with topic name and 
> tagged as 'Topic'.
> 2. Second: Add question/answer tiddlers as children of this topic, tagged 
> with topic tiddler's name. Later on a question tiddler could have multiple 
> topic tags so that it can be included across the quizzes
> 3.Third: Have a [[Make Quiz]] form tiddler. It would have a dropdown 
> containing topics available and text field for the name of the quiz to be 
> created and a button which would create a quiz tiddler, which would have 2 
> fields: topic and a list field. The list field would contain a list of 
> shuffled titles for this quiz. The quiz tiddler would also have a 'Show 
> Quiz' button which when pressed would run a list widget with filter set to 
> its own list field and it would open all the quiz tiddlers in the list.
>
> So far so good.
> In order to shuffle the titles and store them in list field of quiz 
> tiddler I made a javascript macro [[getRandomisedSequenceOfTitles]] which 
> takes a tag name as a parameter and returns a list of titles shuffled in 
> order. I need to store this returned list into the list field of the quiz 
> tiddler being created.  Here is my [[Make Quiz]] tiddler:
>
> \define getTitles()
> <$macrocall $name="getRandomisedSequenceOfTitles" tag=$(qTopic)$/>
> \end
>
> \define my-actions()
> <$set name="qTopic" value={{$:/.user/temp/quiz!!selectedTopic}}>
> <$set name="qName" value={{$:/.user/temp/quiz!!givenName}}>
> <$set name="qTitles" value=<<getTitles>>>
> <$action-sendmessage $message="tm-new-tiddler" title=<<qName>> tags="Quiz" 
> topic=<<qTopic>> list=<<qTitles>>/>
> </$set>
> </$set>
> </$set>
> \end
>
> Select a topic for quiz:
> <$select tiddler="$:/.user/temp/quiz" field="selectedTopic">
> <$list filter='[tag[Topic]]'>
> <option value=<<currentTiddler>>><$view field='title'/></option>
> </$list>
> </$select>
>
> Enter a name for quiz:
> <$edit-text tiddler="$:/.user/temp/quiz" field="givenName" 
> default="QuizName" />
>
> <$button actions=<<my-actions>>>
> Create Quiz
> </$button>
>
> I have attached a sample tw which you can use to try out the code. The 
> problem as one can see is that I cannot do this:
>
>
> <$action-sendmessage $message="tm-new-tiddler" title=<<qName>> tags="Quiz" 
> topic=<<qTopic>> list=<<getRandomisedSequenceOfTitles <<qTopic>>>>/>
>
> The only way to pass an evaluated parameter to a macro is to use a 
> macrocall widget. But if we use that we have no way to catch the returned 
> value and store it somewhere. And what I have done above does not work 
> either, because the macrocall inside macro getTitles does not get 
> evaluated, it is treated just as text. 
>
>
> So I am stuck. What's the way out? Am I going about this is a non TW way? 
> How would I catch the returned string and store it in the list field of new 
> quiz tiddler being created?
>
>
>  
>

-- 
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 post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/2ef6b5f7-529b-4379-80cb-98f83dfecfc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to