Global Variable problem

Get help using Construct 2

Post » Tue Sep 09, 2014 5:51 am

Note: Due to NDA, I can't post the capx file. Sorry!

I try to explain this as good as I can. So I have a game, 2D sindescrolling style. So the idea is it that if you pick up item, you add +1 to said item.

lets say i pick up one nail, i add +1 to the global variable for the nail. so i should have 1 nail. that always worked for the last few weeks until now. I don't know why, but suddenly, every time i pick up a nail, i get 2. the debog mode tells me that yes, there is one nail instance (so i don't accidentally pick up two) and when i pick it up i get two nails.

now at first i thought it is a timing issue, that he runs the action twice before destroying the initial obejct, but that is also not the case. so i thought that another variable or object interferes with the global variable, so i togge disabled everything except the functions for the player picking up the nail - same result. then i did a word search for the variable because i figured if there is an interference somewhere i can find it that way - no roblem there, everything is set up the way it was.

so i have no clue why i have this problem. the thing is, i could easily set picking up said object to 0.5 instead of 1 so i get my 1 nail, so to speak. but that does nto solve the underlying problem and i have no clue what that might be...

edit: maybe it helps if i tell you that it happens to at least two variables, both are pickup items, butit does not happen to all pickup items. the code for the item drops anditems pickups are the same, just with their corresponding images. one of those images is animated, one isn't so that's also not a factor.
Last edited by EzekielRage on Tue Sep 09, 2014 6:08 am, edited 1 time in total.
B
7
S
2
Posts: 66
Reputation: 720

Post » Tue Sep 09, 2014 6:00 am

Does the problem happened at your other projects?
B
23
S
9
G
3
Posts: 114
Reputation: 3,794

Post » Tue Sep 09, 2014 6:03 am

No, only in this one. And it didn't do it from the beginning.
B
7
S
2
Posts: 66
Reputation: 720

Post » Tue Sep 09, 2014 10:36 am

Can you reproduce the problem in a capx you can share..
If not the issue must lie within your eventsheet and it's almost impossible to solve without seeing those events..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Sep 09, 2014 11:19 am

Unfortunately i can't. If I could reproduce it, I would have found the error by now. Every time i copy the part of the code that's needed to a new file the error is gone. but even if i disable everything else in the main project, the error persists.
B
7
S
2
Posts: 66
Reputation: 720

Post » Tue Sep 09, 2014 11:48 am

Without a .capx to analyse, I'm afraid being able to assist would be akin to searching for a needle in a haystack, made of other needles with similar colours, and all facing outwards towards our hands.
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Tue Sep 09, 2014 11:51 am

Just delete everything else until it's so barebones that you are not violating NDA by sharing, if the error still persists, share it with us, if not, you've just discovered where the problem lies :) In some of the things that you've just deleted.
Good luck
B
37
S
6
G
1
Posts: 301
Reputation: 2,860

Post » Tue Sep 09, 2014 12:09 pm

as said if i delete everything the error is not reproducable if i strip everything. it is reproducable if i just disable everything. so either the disable function does not disable everything as it should or something on my system is interfering with the variable in a different way...

the thing is, by deleting and disabling i got even more confused. i now know that the error occurs when certain cireteria are met, but there is absolutely nothing in said code, consisting of TWO events, that are even remotely related to the issues at hand. as in, i have an issue with a global variablebut if i disable the event that loads a different variable that is not connected to the other in any way with a background music the thing screws me over. weird^^

Further Testing reveals that he only does this on one layout. If i change NOTHING and simply go to a different layout, everything works as it should.
B
7
S
2
Posts: 66
Reputation: 720

Post » Tue Sep 09, 2014 2:48 pm

Work it out with this demo
You do not have the required permissions to view the files attached to this post.
B
245
S
37
G
15
Posts: 1,940
Reputation: 40,089

Post » Wed Sep 10, 2014 1:40 pm

I finally managed to locate and fi it! And the error was so dumb, so incredibly stupid that I almost feel ashamde :p

Turns out I had a second player instance on the layout. I dropped it ther accidentally, behind all layers so it was invisible, and that caused the error. I found and deleted it and now everything works as it should.

Thanks for the help, ideas and al that. Thanks a lot :)
B
7
S
2
Posts: 66
Reputation: 720

Next

Return to How do I....?

Who is online

Users browsing this forum: Madave96, RobertMKD, Yahoo [Bot] and 7 guests