Global Variable problem

0 favourites
  • 13 posts
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.
  • 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.

  • Does the problem happened at your other projects?

  • No, only in this one. And it didn't do it from the beginning.

  • 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..

  • 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.

  • 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.

  • 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

  • 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.

  • Work it out with this demo

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • EzekielRage hey don't be upset or be feel dumb. we all make mistake. I made so many I cant remember. Everyone makes mistake and learn from. Even Ashley would have made mistake. Ask him or Tom, Julian, or our friend Kyatric, therefore learn from your mistake and keep your head high

  • 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

    If you only new how many sleepless nights I had because of the same kinds of errors. I was going to suggest the same thing because it happened to me once with my game.

  • Haha yes, we live and learn

    Still glad you all tried to help me with it, glad to see a nice community work so great

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