Page 1 of 1

Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 5:14 pm
by Vintage_Gamer
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

Re: Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 5:59 pm
by Mark
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:

Code: Select all

add 1 to user_score
subtract 1 from user_score
You can also use operators:

Code: Select all

put user_score + 1 into user_score
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

Code: Select all

global user_score
to the top of your script (one time, above all handlers).

Kind regards,

Mark

Re: Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 7:53 pm
by Vintage_Gamer
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?

Re: Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 8:00 pm
by Mark
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.

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
See page 30 and after of my book.

Kind regards,

Mark

Re: Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 8:24 pm
by Vintage_Gamer
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!

Re: Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 8:40 pm
by sefrojones
You can use "put" :

Code: Select all

on QuizReset
put 0 into user_score
end QuizReset
--Sefro

Re: Class Project - Quiz Type Game

Posted: Mon Sep 08, 2014 8:44 pm
by Mark
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.

Code: Select all

put 0 into gUserScore 
You can also make a variable completely empty:

Code: Select all

put empty into gUserScore
but probably this isn't what you want.

Kind regards,

Mark