Probleme mit Values

  • #1, by EksamSaturday, 22. March 2014, 18:27 10 years ago
    Ich bastel gerade etwas an einem kleinem Testprojekt herum, und wollte etwas wie einen "Score" einbauen.
    Ich habe mir ein Value erstellt und lasse mir dieses mit My Score: <v=Score> als Objekttext anzeigen.

    Dies klappt auch ziemlich gut, nur wollte ich nun zu Testzwecken einen "Button" einfügen, welcher das Value, das angezeigt wird, bei jedem Links klick, um 1 addiert.
    Und hier liegt auch das Problem, dieses wird nämlich nicht erhöht.
    Der Wert erhöht sich (Oder eben auch nicht...) folgendermaßen:

    Value 'Score' + 1

    Die Frage ist nun, wie bekomme ich es hin, das sich mein Value erhöht?

    Danke schon einmal für jede Hilfe..

    Newbie

    5 Posts


  • #2, by afrlmeSaturday, 22. March 2014, 18:51 10 years ago
    if you are adding the <v=Score> to a display text, display speaker text, or display object text action then you would need to close/open the display text on each new value change. I believe it requires a refresh to display the new value. You could create a Lua script or possibly use the jump to action part in the editor to create a loop which can be used to refresh/reload/display the score value in real time.

    Imperator

    7278 Posts

  • #3, by EksamTuesday, 25. March 2014, 15:14 10 years ago
    Hey, thanks for your answere,
    i am still a beginner in VS/Lua, so i have another question for you/others,
    how would a script like this looks like?

    Newbie

    5 Posts

  • #4, by afrlmeTuesday, 25. March 2014, 16:50 10 years ago
    Actually on consideration I do not think it's the best of ideas to use the display text option. The object text for instance is placed specifically at x,y coordinate of the scene you assign it to... Also the other downside is that the text will be displaced if the scene scrolls as opposed to being in a fixed position on the actual screen itself.

    For me I would recommend using animations & Lua. Technically you wouldn't actually have to use a loop handler at all. You could just call a function which you add the + score value to it which then updates which animation frames would be displayed.

    I would need a bit of time to sort out the script/example though. However there is an script I wrote ages ago for displaying scores but it's not the cleanest of code, as I know a lot more now than I did then. smile

    http://www.visionaire-studio.net/wiki/article/keeping-score-... - if I wrote this script again it would probably be about half or even a 3rd of the size.

    Imperator

    7278 Posts

  • #5, by afrlmeThursday, 27. March 2014, 18:22 10 years ago
    A'llo again... As (not) promised: here is a script I have written the day which allows you to create a 7 digit high score. It also allows negative (-38787) scores.
    --[[
    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
    

    I've just added the script for now & some screen shot attachments to show it working. Keep an eye out for this wiki article, as I will be adding the script & some instructions on how to setup/use it; later on the day.

    Imperator

    7278 Posts