Score did not update?

StoneclipseStoneclipse Member, PRO Posts: 130
edited April 2012 in Working with GS (Mac)
I have an integers attribute called coins, and i have a store to purchase items. I uses custom font for the number of coins. However, in the store, when i purchase an item, i have it change coins attribute to coins-500. But the number of coins in the scene did not change? It will only change when i change scene and then go back to that scene. Any help to make it change automatically without changing scene?

Best Answer

  • MotherHooseMotherHoose Posts: 2,456
    Accepted Answer
    the coinActor in the scene is not updating with the purchase …
    though it is updating in the game … as it shows when you change scenes

    somehow you have to code the coinActor to update during runTime

    on coinActor:
    add Attribute: currentCoins (index type!)
    Rule: when
    Attribute: self.currentCoins ≠ game.Coins
    -changeAttribute: self.currentCoins To: game.Coins

    and, have the display for coins use the self.currentCoins instead of game.Coins

    image MH

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You need to make your coins attribute a game-level attribute (game.coins) instead of a scene attribute. That way it will carry through from scene to scene.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • StoneclipseStoneclipse Member, PRO Posts: 130
    Hey thanks! I just figured out i made a mistake! I had the rule in the custom font numbers as change attribute self.image, instead of constrain attribute, that's why it never change when i buy something. LOL i kept mixing up change attribute and constrain attribute. :))

    Anyway what's the difference between index and integer?
  • MotherHooseMotherHoose Member Posts: 2,456
    in GS … lua … the type of integer (number) allocates memory bits/bytes for value storing

    indexTypes stores only positive whole numbers … allots the least bits/bytes for storage

    for numbers such as coins/score/lives which you never want to be a negative number… use index
    (all mathematical operations on index, integer, real type of numbers are handled the same
    … but the storage for the valueRange is different …
    for integer and index the computer rounds-off the values before storing)

    EX:
    indexType: coins = 1 … when changed to coins-3 … will result in 0
    integerType: coins = 1 … when changed to coins-3 … will result in -2

    image MH
Sign In or Register to comment.