It looks like you're new here. If you want to get involved, click one of these buttons!
<<widget "evaluate">> <<set $level to $args[0]>> <<set $rightAnswer to $args[1]>> <<set $userAnswer to $args[2]>> <<set $focus to $args[3]>> <<if $userAnswer eq "">> <<<<print "Please answer question!">> <<elseif $userAnswer eq $rightAnswer>> <<set $level +=1>> <<set $nextPassage = $level + "x" + $round >> <<goto $nextPassage>> <<else>> <<set $level -=1>> <<set $nextpassage = $level + "x" + $round >> <<goto $nextPassage>> <</if>> <</widget>>
<<set $level to 1>> <<set $rightAnswer to "Option A">> <<set $focus to "Partizipien">> Choose the right option! <<radiobutton "$userAnswer" "Option A">>Option A <<radiobutton "$userAnswer" "Option B">>Option B <<radiobutton "$userAnswer" "Option C">>Option C <<button "next round">> <<evaluate $level $rightAnswer $userAnswer $focus>> <</button>>
Comments
Only need 2 <<, not 4.
This is causing the first error message and then the widget is not defining $useranswer properly as a follow on of confusing it with the extra <<, causing the second error.
If you get an unexpected token error it means you've put the extra stuff it says in somewhere and should first remove the offending characters.
Beyond that, you don't actually need to use <<print>> there at all. You could write that bit like the following:
Anyways - I expanded my widget and encountered more problems. Could you guys give me a push in the right direction? Here is what my widget is supposed to do:
1. Check, whether $userAnswer matches $rightanswer.
2. If yes, add "true" to the $answerLog array.
3. If no, add "false" to the $answerLog array.
4. Check the last two elements of $answerLog: if both of them are true, increment $level, if both of them are false, decrement $level.
5. Set $nextpassage to $round+"x"+$level (passage names are ie. 1x2, 1x3, 2x1, 2x4,...
6. go to $nextpassage.
My widget now reads as follows
There must be something wrong adding elements to $answerlog.
Try something like the following:
So I thought the correct thing to do would be to pack everything into and <<if>> macro, which won't <<goto>> if the user input is"". Apparently, one or some of the <<if>>-macros aren't properly closed, can you spot the error?
You can't split macros with silently. You'll note that TheMadExile's example doesn't do this. He didn't put a global if around a silently macro.
Remove line spaces by condensing the lines to all be on the same line instead.
@richVIE: Yes, sorry. Here's a version with the nested <<if>> macros and the <<nobr>> removed—since it's not really necessary now: n.b. One other suggestion is to change any story variable inside the widget which only exists to hold a temporary value into a temporary variable. For example, say that $lastIndex is not used outside of the widget. In that case, it would be better to make it a temporary variable via changing all instances of its sigil from $ to _ (i.e. dollar sign to underscore; e.g. $lastIndex to _lastIndex). Temporary variables are not added to the story variable store and do not live past the passage in which they're used. By not using a story variable to hold temporary values, you save yourself some history bloat.
I have one passage tagged "widget", the only thing inside is TheMadExile's widget from the last post, so the problem can't be there.
My starting passage looks like this, I can't spot an error there either: Can you?
sorry, me again. I had time for some extensive testing and noticed, that the widget still doesn't react properly to an empty user input:
does not print anything.
So my idea was that if you pass an empty variable to the widget, it would think it got only three arguments (instead of four) and therefore wouldn't work.
So I changed the code to but it doesn't work either. Do you have any suggestions on how to prevent empty user inputs?
An additional issue is, that the rest of the widget continues working fine, so each time it is triggered, it evaluetes the user input as false, decrements the $level counter and then links to an inexistent passage.
As noted by its documentation, the <<button>> macro is silent. You cannot simply call your widget via the <<button>> and expect to see output.
As one suggestion, you could change your <<button "next round">> code to look something like the following: Which would allow your <<evaluate>> widget code to be simplified thus:
I tried your button code on several different occasions. It seems it works just fine with text inputs, so
works perfectly (when leaving the textbox empty).
But when I use radio buttons, such as here
The <<if $userAnswer eq "">> conditions doen't seem to be met when leaving the three radiobuttons unchecked, it directly calls the macro.
Can you think of a way to deal with that behaviour?
Since you will likely be reusing $userAnswer multiple times, it would be better to simply initialize it to the empty string. You'll need to do something similar before asking each question anyway. It's likely best done where you set the correct ($rightAnswer) for each question. Simply do them both at the same time. For example: