Difference between revisions of "High Score Display (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Main Script)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| class="wikitable" style="width:100%"
+
{| class="ts" style="width:100%"
 
|-
 
|-
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
Line 8: Line 8:
  
 
== Instructions ==
 
== Instructions ==
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
+
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br />
2. Create a new interface '''score_interface'''.<br/>
+
2. Create a new interface '''score_interface'''.<br />
3. Create 8 buttons & name them like so: '''btn_inc''', '''btn_d1''', '''btn_d2''', '''btn_d3''', '''btn_d4''', '''btn_d5''', '''btn_d6''', '''btn_d7'''.<br/>
+
3. Create 8 buttons & name them like so: '''btn_inc''', '''btn_d1''', '''btn_d2''', '''btn_d3''', '''btn_d4''', '''btn_d5''', '''btn_d6''', '''btn_d7'''.<br />
4. Create & add the score interface background image to the properties section of the interface.<br/>
+
4. Create & add the score interface background image to the properties section of the interface.<br />
5. Set the absolute position of the interface; based on game default resolution.<br/>
+
5. Set the absolute position of the interface; based on game default resolution.<br />
6a. You need to create 12 png images with transparent backgrounds; the width/height of each should be exactly the same.<br/>
+
6a. You need to create 12 png images with transparent backgrounds; the width/height of each should be exactly the same.<br />
*b. 10 of the images should contain a single number; from ''0'' to ''9''.<br/>
+
*b. 10 of the images should contain a single number; from ''0'' to ''9''.<br />
*c. a single image should be left blank; this will be used to hide inactive digits.<br/>
+
*c. a single image should be left blank; this will be used to hide inactive digits.<br />
*d. The last one should contain a '''-'''; if the score value is a negative value then this will be shown before the first number.<br/>
+
*d. The last one should contain a '''-'''; if the score value is a negative value then this will be shown before the first number.<br />
*e. Save each of the number images, same as the number you added to them, like so: '''n_0''', '''n_1''', '''n_2''', etc...<br/>
+
*e. Save each of the number images, same as the number you added to them, like so: '''n_0''', '''n_1''', '''n_2''', etc...<br />
*f. Save the blank image as ''n_10''; the reason you are saving them like this is so that you can import them as a set animation, as opposed to having to add each animation frame one at a time.<br/>
+
*f. Save the blank image as ''n_10''; the reason you are saving them like this is so that you can import them as a set animation, as opposed to having to add each animation frame one at a time.<br />
*g. Save the '''-''' image as whatever you like.<br/>
+
*g. Save the '''-''' image as whatever you like.<br />
7. Create an animation for each of the buttons & name them like so: '''ani_d1''', '''ani_d2''', '''ani_d3''', '''ani_d4''', '''ani_d5''', '''ani_d6''', '''ani_d7''', '''ani_inc'''; the names should reflect the value after the ''btn_'' prefix.<br/>
+
7. Create an animation for each of the buttons & name them like so: '''ani_d1''', '''ani_d2''', '''ani_d3''', '''ani_d4''', '''ani_d5''', '''ani_d6''', '''ani_d7''', '''ani_inc'''; the names should reflect the value after the ''btn_'' prefix.<br />
8. Load the number animations into each of the numbered buttons, as a set.<br/>
+
8. Load the number animations into each of the numbered buttons, as a set.<br />
9. For the '''btn_ani''' animation create 2 frames & load in the blank image into the first frame, & the "'''<span class="red">-</span>'''" image into the second frame.<br/>
+
9. For the '''btn_ani''' animation create 2 frames & load in the blank image into the first frame, & the "'''<span class="red">-</span>'''" image into the second frame.<br />
10. Inside of the properties tab for each button set default animation to the animation you added to the button.<br/>
+
10. Inside of the properties tab for each button set default animation to the animation you added to the button.<br />
11. Add value "'''v_score''' to the ''value'' tab of the ''score_interface'' & set default value to '''0'''.<br/>
+
11. Add value "'''v_score''' to the ''value'' tab of the ''score_interface'' & set default value to '''0'''.<br />
 
12. To add to the current score, create an ''execute a script'' action containing...
 
12. To add to the current score, create an ''execute a script'' action containing...
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
setScore(n, true) -- replace n with number you want to add to the current score.
 
setScore(n, true) -- replace n with number you want to add to the current score.
 
</syntaxhighlight>
 
</syntaxhighlight>
 
13. To subtract from the current score, ''create an execute a script'' action containing...
 
13. To subtract from the current score, ''create an execute a script'' action containing...
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
setScore(n, false) -- replace n with number you want to subtract from the current score.
 
setScore(n, false) -- replace n with number you want to subtract from the current score.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
--[[
 
--[[
 
High Score (updated via function) [v2.1] (29/03/2014)
 
High Score (updated via function) [v2.1] (29/03/2014)
Line 71: Line 71:
 
  end
 
  end
 
end
 
end
</syntaxhighlight>
+
</syntaxhighlight>{{toc}}

Latest revision as of 15:27, 13 June 2018

Name Type By
High Score (updated via function) Definition AFRLme

This script allows you to create a high score interface & add/subtract score value; positive & negative score values are allowed.

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Create a new interface score_interface.
3. Create 8 buttons & name them like so: btn_inc, btn_d1, btn_d2, btn_d3, btn_d4, btn_d5, btn_d6, btn_d7.
4. Create & add the score interface background image to the properties section of the interface.
5. Set the absolute position of the interface; based on game default resolution.
6a. You need to create 12 png images with transparent backgrounds; the width/height of each should be exactly the same.

  • b. 10 of the images should contain a single number; from 0 to 9.
  • c. a single image should be left blank; this will be used to hide inactive digits.
  • d. The last one should contain a -; if the score value is a negative value then this will be shown before the first number.
  • e. Save each of the number images, same as the number you added to them, like so: n_0, n_1, n_2, etc...
  • f. Save the blank image as n_10; the reason you are saving them like this is so that you can import them as a set animation, as opposed to having to add each animation frame one at a time.
  • g. Save the - image as whatever you like.

7. Create an animation for each of the buttons & name them like so: ani_d1, ani_d2, ani_d3, ani_d4, ani_d5, ani_d6, ani_d7, ani_inc; the names should reflect the value after the btn_ prefix.
8. Load the number animations into each of the numbered buttons, as a set.
9. For the btn_ani animation create 2 frames & load in the blank image into the first frame, & the "-" image into the second frame.
10. Inside of the properties tab for each button set default animation to the animation you added to the button.
11. Add value "v_score to the value tab of the score_interface & set default value to 0.
12. To add to the current score, create an execute a script action containing...

setScore(n, true) -- replace n with number you want to add to the current score.

13. To subtract from the current score, create an execute a script action containing...

setScore(n, false) -- replace n with number you want to subtract from the current score.

Main Script

--[[
High Score (updated via function) [v2.1] (29/03/2014)
Written by AFRLme [Lee Clarke]
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * local variables * --
local score = getObject("Values[v_score]") -- store score value

-- * function used to set score value & determine which animations/frames should be displayed * --
function setScore(val, inc)
if inc then score:setValue(VValueInt, (score:getInt(VValueInt) + val)) else score:setValue(VValueInt, (score:getInt(VValueInt) - val)) end -- if true add val to current score else remove val from current score
if string.len( math.abs( score:getInt(VValueInt ) ) ) < 7  then -- check digit value less than 7 & if so, hide the invalid digits
 for i = (string.len(val) + 1), 7 do  -- actual digit value (+1) to max digit value
  getObject("ActiveAnimations[ani_d" .. i .. "]"):setValue(VAnimationFirstFrame, 11); getObject("ActiveAnimations[ani_d" .. i .. "]"):setValue(VAnimationLastFrame, 11) -- blank animation frame
  end
 end
 if score:getInt(VValueInt) >= 0 then -- if value is positive do positive block else do negative block
  for i = 1, string.len( score:getInt(VValueInt) ) do -- set the frame value to match the digit number
   getObject("ActiveAnimations[ani_inc]"):setValue(VAnimationFirstFrame, 1); getObject("ActiveAnimations[ani_inc]"):setValue(VAnimationLastFrame, 1) -- positive value; set blank frame
   getObject("ActiveAnimations[ani_d" .. i .. "]"):setValue(VAnimationFirstFrame, string.sub( score:getInt(VValueInt), i, i ) + 1) -- set linked animation first frame to digit value (+1)
   getObject("ActiveAnimations[ani_d" ..  i .. "]"):setValue(VAnimationLastFrame, string.sub( score:getInt(VValueInt), i, i ) + 1) -- set linked animation last frame to digit value (+1)
  end
 else for i = 1, string.len( - score:getInt(VValueInt) ) do -- set the frame value to match the digit number
  getObject("ActiveAnimations[ani_inc]"):setValue(VAnimationFirstFrame, 2); getObject("ActiveAnimations[ani_inc]"):setValue(VAnimationLastFrame, 2)  -- negative value; set negative frame
  getObject("ActiveAnimations[ani_d" .. i .. "]"):setValue(VAnimationFirstFrame, string.sub( - score:getInt(VValueInt), i, i ) + 1) -- set linked animation first frame to digit value (+1)
  getObject("ActiveAnimations[ani_d" ..  i .. "]"):setValue(VAnimationLastFrame, string.sub( - score:getInt(VValueInt), i, i ) + 1) -- set linked animation last frame to digit value (+1)
  end
 end
end