Class Project - Quiz Type Game
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 3
- Joined: Mon Sep 08, 2014 5:09 pm
Class Project - Quiz Type Game
In class at the moment we are just starting to learn the LiveCode language. We have been asked to go home and create something using the Package and present it to the class. I want to create a quiz type game. I have the questions and such all done, and understand how to use else and if statements and things, but I was wondering if there was a way to add a number of "points" to a variable if the answer is correct.
What I mean is, if I have a variable called "user_score", everytime there is a correct answer how would I add "1" to the variable "user_score" and at the end, the user can see their score, out of whatever many questions/points there is.
Thanks
PS. Sorry for the noobness :p
What I mean is, if I have a variable called "user_score", everytime there is a correct answer how would I add "1" to the variable "user_score" and at the end, the user can see their score, out of whatever many questions/points there is.
Thanks
PS. Sorry for the noobness :p
Re: Class Project - Quiz Type Game
Hi,
You can use the add command to increase the value of a variable and the subtract command to reduce the value of a variable:
You can also use operators:
Because you have to read a variable and store a new value into this variable, this is generally slower than the add and subtract commands, which only modify the stored value.
Probably, you want your variable to be global. Add
to the top of your script (one time, above all handlers).
Kind regards,
Mark
You can use the add command to increase the value of a variable and the subtract command to reduce the value of a variable:
Code: Select all
add 1 to user_score
subtract 1 from user_score
Code: Select all
put user_score + 1 into user_score
Probably, you want your variable to be global. Add
Code: Select all
global user_score
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 3
- Joined: Mon Sep 08, 2014 5:09 pm
Re: Class Project - Quiz Type Game
Thanks Mark!
If I wanted to display the users score at the end? Would I just echo out the value of the variable user_score?
If I wanted to display the users score at the end? Would I just echo out the value of the variable user_score?
Re: Class Project - Quiz Type Game
Hi,
Echo is something from PHP or shell. In LiveCode, we use the put command. In the IDE, you can use the put command to display a value in the message box or to store a value in a variable, field or other control.
See page 30 and after of my book.
Kind regards,
Mark
Echo is something from PHP or shell. In LiveCode, we use the put command. In the IDE, you can use the put command to display a value in the message box or to store a value in a variable, field or other control.
Code: Select all
put myVar --> message box
put myVar into fld 1 --> first field
put myVar into fld "My Field" --> into field with the name "My Field"
put myField into gUserScore --> variable
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 3
- Joined: Mon Sep 08, 2014 5:09 pm
Re: Class Project - Quiz Type Game
Okay thanks! I have encountered a weird error with my game.
To fix, I thought to reset the user_score variable everytime the game is run, I was wondering if this is done with the "set" or "setProp" commands?
Like I said, Im a little clueless and only understand the basics of LiveCode and would love to learn more!
To fix, I thought to reset the user_score variable everytime the game is run, I was wondering if this is done with the "set" or "setProp" commands?
Like I said, Im a little clueless and only understand the basics of LiveCode and would love to learn more!
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Class Project - Quiz Type Game
You can use "put" :
--Sefro
Code: Select all
on QuizReset
put 0 into user_score
end QuizReset
Re: Class Project - Quiz Type Game
Hi,
The set command is for setting properties, the setProp keyword defines a property handler, just like "on" defines a command handler and "function" a function handler.
To reset the counter, you can use the put command, similar to the use of the put command in my previous examples.
You can also make a variable completely empty:
but probably this isn't what you want.
Kind regards,
Mark
The set command is for setting properties, the setProp keyword defines a property handler, just like "on" defines a command handler and "function" a function handler.
To reset the counter, you can use the put command, similar to the use of the put command in my previous examples.
Code: Select all
put 0 into gUserScore
Code: Select all
put empty into gUserScore
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode