Can Not Get Global Variable Updating

This forum is currently in read-only mode.
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I can not seem to get one of my global variables, BookCount (goes with text OBJECT "Text_BooksIndicator"), to update. As far as I know, I made it just as the one for the game's score. Even cloned and pasted from is OBJECT, Text_ScoreIndicator. But whenever the collision happens, the BookCount stays 0.

    + System: Always (every tick)

    -> Text_HealthIndicator: Set text to "Health: " & Hero ('Health')

    -> Text_ScoreIndicator: Set text to "Score: " & Text_ScoreIndicator ('score')

    -> Text_BooksIndicator: Set text to "Books: " & Text_BooksIndicator ('BookCount')

    -> System: Set global variable 'Score' to Text_ScoreIndicator ('score')

    -> System: Set global variable 'BookCount' to Text_BooksIndicator ('BookCount')

    Then down in where the OBJECT "BibleDrop" collides with the ship:

    + Hero: On collision between Hero and BibleDrop

    -> System: Add 1 to global variable 'BookCount'

    -> BibleDrop: Destroy

    I am not sure what I am missing. I have it copied like other items, like the health packs.

    Thanks for any assistance.

  • I might misunderstand something here, but from what you posted from your events, it is normal behavior.

    You are setting the global 'BookCount' to the value of the private 'BookCount' of Text_BooksIndicator at every tick.

    So whatever you add to the global in the collision event, the value will be replaced by the value of the private variable right afterwards. It will keep its value for just one tick (which you won't notice)

    Example

    Text_BooksIndicator('BookCount') = 0

    global('BookCount') = 0

    Tick 120

    Collision event, global set to 1

    Tick 121

    global set to Text_BooksIndicator('BookCount') = 0

  • tulamide, thank you for replying back. I am looking at it and I must be missing something. It looks the same as how the score is. May I send you a link to take a look at it and point out my error?

  • Sure, I'll do my best :)

  • Thanks. I sent you a link to the CAP file.

  • Sent you a pm.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here is tul's solution which worked.

    I just had a look at it and I don't see why you have that private variables for Text_ScoreIndicator and Text_BooksIndicator at all? They have no meaning, and they aren't used in any part of your code, apart from event 1, where it makes no sense.

    If you just change these two lines in event 1 from

    -> Text_ScoreIndicator: Set text to "Score: " & Text_ScoreIndicator ('score')

    -> Text_BooksIndicator: Set text to "Books: " & Text_BooksIndicator ('bookcount')

    to

    -> Text_ScoreIndicator: Set text to "Score: " & global('Score')

    -> Text_BooksIndicator: Set text to "Books: " & global('BookCount')

    then everything works fine and as one would expect. Don't make it too complicated, get rid of those both pv and refer to the globals instead.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)