Okay, so today I decided to mess around with Gwen, and specifically, I wanted to make a simple quiz. I’ve dabbled with Gwen a bit before, but nothing too serious, so this was a good way to get my hands dirty.
Getting Started
First things first, I fired up my trusty text editor and created a new file, “*”. I always start super basic, so I just wanted to see if Gwen was even working.
I typed in some really simple stuff:
Label { Text = "Hello, world!" }
I run it, it displayed the “hello,world”.Yup, that worked! A little “Hello, World” box popped up. Great, Gwen’s alive and kicking.
Building the Quiz Structure
Next, I needed to think about how the quiz would actually work. I figured I’d need:
- A question.
- Some answer options.
- A way to check if the answer was right.
So, I started laying out the basic elements. I used a Label for the question, and Buttons for the answers. Seemed logical enough.
Label { Name = "QuestionLabel" Text = "What is 1 + 1?" }
Button { Name = "OptionA" Text = "1" }
Button { Name = "OptionB" Text = "2" }
Button { Name = "OptionC" Text = "3" }
I gave each element a Name so I could refer to them later. Made sense at the time, and it turned out to be a good idea.
Making it Interactive
Of course, the quiz wouldn’t be much fun if nothing happened when you clicked the buttons. So, I needed to add some actions.
Button { Name = "OptionA" Text = "1"
Clicked = function()
* = "Wrong!"
end
Button { Name = "OptionB" Text = "2"
Clicked = function()
* = "Correct!"
end
Button { Name = "OptionC" Text = "3"
Clicked = function()
* = "Wrong!"
end
I added a Clicked event to each button. When you click a button, it runs the little function() inside. For now, I just made it change the question label to say “Correct!” or “Wrong!”. I am very smart.
Adding More Questions…
One question isn’t much of a quiz, is it? I wanted to add a few more. I could have just copied and pasted the whole thing, but that seemed messy. So I wrapped all my quiz elements into a function like this:
function CreateQuestion(questionText, optionAText, optionBText, optionCText, correctAnswer)
--all element codes here.
end
After a few hours of tinkering and plenty of trial and error, I had a basic, working quiz! It wasn’t the prettiest thing in the world, but it did what I wanted it to do.I run it, it is working, awesome!
Final Thoughts
This little project was a fun way to get more familiar with Gwen. I learned a lot about how to structure things, how to handle events. I can show this quiz game to my friends, and they may think I am a super genius, lol.