Can Not Get Global Variable Updating

For questions about using Classic.

Post » Wed Jan 11, 2012 1:24 pm

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.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Jan 11, 2012 3:19 pm

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
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Jan 11, 2012 6:10 pm

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?
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Jan 11, 2012 10:37 pm

Sure, I'll do my best :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jan 12, 2012 4:31 pm

Thanks. I sent you a link to the CAP file.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Thu Jan 12, 2012 5:26 pm

Sent you a pm.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Jan 12, 2012 8:50 pm

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.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests