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

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Main Script)
Line 5: Line 5:
 
| High Score (updated ''via'' function) || Definition || AFRLme
 
| High Score (updated ''via'' function) || Definition || AFRLme
 
|}
 
|}
This script allows you to add/subtract from a score GUI; positive & negative score values are allowed.
+
This script allows you to create a high score interface & add/subtract score value; positive & negative score values are allowed.
  
 
== 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. to do...
+
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/>
 +
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/>
 +
6a. You need to create 12 png images with transparent backgrounds; the width/height of each should be exactly the same.<br/>
 +
6b. 10 of the images should contain a single number; from ''0'' to ''9''.<br/>
 +
6c. a single image should be left blank; this will be used to hide inactive digits.<br/>
 +
6d. The last one should contain a '''-'''; if the score value is a negative value then this will be shown before the first number.<br/>
 +
6e. Save each of the number images, same as the number you added to them, like so: ''n_0'', ''n_1'', ''n_2'', etc...<br/>
 +
6f. 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/>
 +
6g. 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/>
 +
5. Add value "'''v_score''' inside of the ''score_interface'' & set default value to '''0'''.<br/>
 +
6. to do...
  
 
== Main Script ==
 
== Main Script ==

Revision as of 20:44, 27 March 2014

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.
6b. 10 of the images should contain a single number; from 0 to 9.
6c. a single image should be left blank; this will be used to hide inactive digits.
6d. The last one should contain a -; if the score value is a negative value then this will be shown before the first number.
6e. Save each of the number images, same as the number you added to them, like so: n_0, n_1, n_2, etc...
6f. 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.
6g. 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.
5. Add value "v_score inside of the score_interface & set default value to 0.
6. to do...

Main Script

--[[
High Score (updated via function) [v2] (27/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( score:getInt(VValueInt ) ) < 7 or string.len( - score:getInt(VValueInt) ) 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) -- blank animation frame
  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