Your browser lacks required capabilities. Please upgrade it or switch to another to continue.
<<set $url to "https://opentdb.com/api.php?amount=">>\
<<set $url_cat to "">>\
<<set $url_dif to "">>\
<<set $url_que to "1">>\
<<set $cats to {}>>\
<<set $round to 0>>\
<<set UIBar.stow()>>\
<<set $score_correct to 0>>\
<<set $score_fail to 0>>\
<<if visited() == 1>><<getsession>>Generated session token $session_token<<else>>Resuming session $session_token<</if>>
<<loadtdb>><<button 'Confirm'>><<create_tdb_url>><<goto 'game'>><</button>>
!Questions
<<textbox "$url_que" "1">>
!Category
* <label><<radiobutton "$url_cat" "" checked>> Any</label>
<<for _i, _n range $cats.trivia_categories>>\
* <label><<radiobutton "$url_cat" _n.id>> _n.name</label><</for>>
!Difficulty
* <label><<radiobutton "$url_dif" "" checked>> Any</label>
* <label><<radiobutton "$url_dif" "&difficulty=easy">> Easy</label>
* <label><<radiobutton "$url_dif" "&difficulty=medium">> Medium</label>
* <label><<radiobutton "$url_dif" "&difficulty=hard">> Hard</label>
<<button 'Confirm'>><<create_tdb_url>><<goto 'game'>><</button>><<button 'Back to main menu'>><<goto 'Main'>><</button>>
<<set $round to $round + 1>><<pullQuestion>>
Round: $round / $url_que | Difficulty: $difficulty | Category: $category
<b>$question</b>
<<for _i, _n range $answers>><<capture _n>><<button '_n'>><<set $submitted to _n>><<goto 'check'>><</button>><</capture>> <</for>>
$question
The correct anser was... $correct.
You guessed $submitted.
<<if $submitted == $correct>>
You got it right.
<<set $score_correct to $score_correct + 1>>
<<else>>
You got it wrong.
<<set $score_fail to $score_fail + 1>>
<</if>>
<<if $round < $url_que>>
<<button 'Next round'>><<goto 'game'>><</button>>
<<else>>
<<button 'Finish'>><<goto 'end'>><</button>>
<</if>>
You got $score_correct out of $url_que correct.
<<button 'Back to menu'>><<goto 'Main'>><</button>><<link 'About Coded Trivia'>>
<<dialog 'About'>>\
Welcome to Coded Trivia!
This is a simple trivia game.
Questions sourced from the Open Trivia Database.
Credits:
Kaiser - Programming, concept
ChapelR - Macros
Mog - Initial tests, design suggestions
Additional testers - WIP
Designed with Twine engine and SugarCube template.
Copyright © 2019 Kaiser (kaiser7@gmx.com)
All rights reserved.
<</dialog>>
<</link>><a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fcodedthoughts.github.io%2Ftrivia%2F&src=sdkpreparse&display=popup">Facebook</a>
<a href="https://twitter.com/intent/tweet?url=https%3A%2F%2Fcodedthoughts.github.io%2Ftrivia%2F&text=Come play Coded Trivia!&via=technomancer7&hashtags=trivia">Twitter</a>