Global variable taking junk values

Get help using Construct 2

Post » Sun Jul 19, 2015 4:48 pm

Hi,

In my game I am using a global variable for scoring named "Score". Everytime a collision event occurs "Score" should increase by 1. But when I run the game the variable gets set to random values everytime collision event occurs.

Attaching screenshot. Please help.

Image
B
7
S
1
Posts: 19
Reputation: 466

Post » Sun Jul 19, 2015 6:14 pm

I'm not positive about this, but it might be that its reading more than one collision each time it hits.

Can you put in a "trigger once while true" condition?
I'm not certain that will fix it.

It also seems like collision always works best if you have a perfect rectangle hitting another perfect rectangle.

Hope that helps, but its likely another issue.
B
10
S
2
Posts: 37
Reputation: 688

Post » Sun Jul 19, 2015 6:15 pm

Oh sorry. It probably isn't that, because you're destroying the ball as soon as it hits.

Maybe worth a try still.
B
10
S
2
Posts: 37
Reputation: 688

Post » Sun Jul 19, 2015 6:20 pm

We have too few information to answer your question, imo.

Does score appear anywhere else in your code?
What is meant with random values - which numbers are you seing? Are the differences only small or are you getting huge, unrealistic numbers?
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Mon Jul 20, 2015 4:16 am

Score only appears at above shown location in my code. It takes random values on collision like -

2,12,17, 37,54
4, 11,29,35

Tried the "trigger once condition" but it didnt work.
B
7
S
1
Posts: 19
Reputation: 466

Post » Mon Jul 20, 2015 5:02 am

You need to post your code. The numbers are all incrementing, so you are getting multiple hits.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Mon Jul 20, 2015 5:23 am

It's possible that your bullet is colliding with multiple wall objects at the same time, so the event is running for each collision. There's some strange behavior to be aware of when you destroy an object -- relating to when it actually ceases to exist -- but I don't remember what it is off the top of my head.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » Mon Jul 20, 2015 5:42 am

Colliding with multiple walls at the same time is most likely. You probably don't want multiple walls stacked onto each other for performance issues, but to solve the problem you can set an instance variable to mark whether the ball has been "scored" and check that before adding score. That way only the first collision will add to the score for that ball.

Something like:

On collision and ball scored = 0: Set ball scored to 1, add 1 to Score, set text to Score and Destroy ball.
B
10
S
2
Posts: 33
Reputation: 710

Post » Tue Aug 25, 2015 7:18 am

Thanks tgfcoder. That worked
B
7
S
1
Posts: 19
Reputation: 466

Post » Mon Dec 14, 2015 12:40 am

hgambhir
could you please tell me how you solve that with steps
i'm facing the same problem
B
2
Posts: 1
Reputation: 152


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo, lahbach, ST314 and 22 guests