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

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "{| class="wikitable" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | High Score (updated ''via'' ...")
 
Line 9: Line 9:
 
== 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...
  
 
== Main Script ==
 
== Main Script ==

Revision as of 18:31, 27 March 2014

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

This script allows you to add/subtract from a score GUI; 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. 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) >= 1 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 animation frame to digit value (+1)
   getObject("ActiveAnimations[ani_d" ..  i .. "]"):setValue(VAnimationLastFrame, string.sub( score:getInt(VValueInt), i, i ) + 1) -- set animation 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 animation frame to digit value (+1)
  getObject("ActiveAnimations[ani_d" ..  i .. "]"):setValue(VAnimationLastFrame, string.sub( - score:getInt(VValueInt), i, i ) + 1) -- set animation frame to digit value (+1)
  end
 end
end