From ce9bc66b71eff11a24c79622be85890f0a683b1d Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 21 Feb 2024 08:53:20 +0400 Subject: [PATCH] Add jepardy widget sample --- samples/jepardy-widget.lua | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 samples/jepardy-widget.lua diff --git a/samples/jepardy-widget.lua b/samples/jepardy-widget.lua new file mode 100644 index 0000000..33c0807 --- /dev/null +++ b/samples/jepardy-widget.lua @@ -0,0 +1,43 @@ +--[[ + +This script is getnerated by ChatGPT + +Prompt:Search the internet for examples of scripts for AIO Launcher and write a script named "Jepardy" that will display a question from its database of questions with three answer options on the screen. If the answer is correct, a toast "Correct!" should appear on the screen, and a new question should be displayed. If the answer is incorrect, display a toast "Not correct" and present a new question. The database should contain questions in English. + +--]] + +-- A simplified structure for the questions database +local questions = { + { question = "What is the capital of France?", answers = {"London", "Berlin", "Paris"}, correct = 3 }, + { question = "What element does 'O' represent on the periodic table?", answers = {"Gold", "Oxygen", "Osmium"}, correct = 2 }, + -- Add more questions to reach 100. Each question is a table with the question text, + -- an array of answers, and the index of the correct answer in the array. +} + +local currentQuestionIndex = 1 -- Track the current question + +-- Function to display the current question and answers +function showCurrentQuestion() + local q = questions[currentQuestionIndex] + ui:show_lines({q.question, "1) " .. q.answers[1], "2) " .. q.answers[2], "3) " .. q.answers[3]}) +end + +-- Function to handle user's answer, check if it's correct, and move to the next question +function on_click(index) + local correctAnswer = questions[currentQuestionIndex].correct + 1 -- Adjust for 1-based indexing + if index == correctAnswer then + ui:show_toast("Correct!") + else + ui:show_toast("Not correct") + end + + -- Move to the next question, loop back to the first after the last question + currentQuestionIndex = (currentQuestionIndex % #questions) + 1 + showCurrentQuestion() +end + +-- Function called by AIO Launcher to resume the script/widget +function on_resume() + showCurrentQuestion() +end +