How to create a "score" system
Posted: Fri Feb 09, 2007 5:44 am
16. How to create a "score" system?
First you need to create a new integer variable that will hold the score. To do so, click the "Variables..." button that is under the VBScript text field in the "Hotspot Properties" window and click "New Integer Variable...". Let's call the new variable MYSCORE.
To increase the value of the score by 1, simply use the following code:
MYSCORE = MYSCORE + 1
If you want to tell the player what his or her score is, use the following code:
msgbox MYSCORE
If you want to use a sentence such as "Your score is:", then use the following code:
msgbox "Your score is: " + cstr(MYSCORE)
The reason why the cstr function is used is that you can only add two variables of the same type. Since "Your score is:" is a string and MYSCORE is an integer, you need to convert it to string (with the cstr function) before you can use the "+" operation.
If you want to say "You have not completed the game" if the score is lower than, say, 1000 points, use the following code:
if MYSCORE < 1000 then msgbox "You have not completed the game."
17. How to make the score appear on all the frames?
This question assumes that you have already created a variable contains the score (see the previous question), and that the variable is called MYSCORE.
The following steps will show you how to display the value of MYSCORE on all the frames.
1. Create a new frame, called for example MyScoreFrame.
2. Double-click to get to the frame editor.
3. Right-click to create text.
4. Type the text: "score". Position it where you want the score to appear on all the frames. Close the frame.
5. Click the link for Runtime Frames Merging.
6. You must select each frame that you want to merge with the hotspot in the frame. Use <shift> or <ctrl> to select multiples. Next use the pull-down menu to the frame called MyScoreFrame.
7. Now each of the frames will share the text box, but they don't know what to do with it. Open the Project Properties, go to the Advanced tab, check the option "Execute some VBScript code every time that a frame is loaded", and type in the following code:
i = Action.GetMergedTextIndex
Text(i).Caption="Score: "+CStr(MYSCORE)
See project files zip how to do one.
First you need to create a new integer variable that will hold the score. To do so, click the "Variables..." button that is under the VBScript text field in the "Hotspot Properties" window and click "New Integer Variable...". Let's call the new variable MYSCORE.
To increase the value of the score by 1, simply use the following code:
MYSCORE = MYSCORE + 1
If you want to tell the player what his or her score is, use the following code:
msgbox MYSCORE
If you want to use a sentence such as "Your score is:", then use the following code:
msgbox "Your score is: " + cstr(MYSCORE)
The reason why the cstr function is used is that you can only add two variables of the same type. Since "Your score is:" is a string and MYSCORE is an integer, you need to convert it to string (with the cstr function) before you can use the "+" operation.
If you want to say "You have not completed the game" if the score is lower than, say, 1000 points, use the following code:
if MYSCORE < 1000 then msgbox "You have not completed the game."
17. How to make the score appear on all the frames?
This question assumes that you have already created a variable contains the score (see the previous question), and that the variable is called MYSCORE.
The following steps will show you how to display the value of MYSCORE on all the frames.
1. Create a new frame, called for example MyScoreFrame.
2. Double-click to get to the frame editor.
3. Right-click to create text.
4. Type the text: "score". Position it where you want the score to appear on all the frames. Close the frame.
5. Click the link for Runtime Frames Merging.
6. You must select each frame that you want to merge with the hotspot in the frame. Use <shift> or <ctrl> to select multiples. Next use the pull-down menu to the frame called MyScoreFrame.
7. Now each of the frames will share the text box, but they don't know what to do with it. Open the Project Properties, go to the Advanced tab, check the option "Execute some VBScript code every time that a frame is loaded", and type in the following code:
i = Action.GetMergedTextIndex
Text(i).Caption="Score: "+CStr(MYSCORE)
See project files zip how to do one.