How do I - know when I should use the Global property?

0 favourites
  • 9 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.
  • In another topic I asked "How do I keep my sprites/code/etc" consistently working between layouts, and I did get an answer that helped me.

    But this ended up actually breaking my game and causing all sorts of glitches due to the way I coded everything before hand.

    on /restart layout/ and /reset global variables/, replaying the same level after the game was over (either on a victory or defeat) would create artifacts from the previous game, and I realized that global causes sprites to not be destroyed on layout change / restart I guess.

    This is great for something like a platformer game, or I assume, 90% of every other situation.

    -----

    But what I needed was basically, a way that I could "Create another layout" without having to copy and paste everything from the first layout.

    It seems that, in order for my new layouts to work properly, unless I duplicate the first layout, things don't work 100% (assuming because there are things I move in and out of view of the player)

    But I was wondering, does this mean that every new layout needs you to spawn every object you have ever made onto the sides, and then simply destroy them all upon start of layout to conserve memory?

    tl;dr - do I have to copy paste every object every time I make a new layout to make sure things work - and is there a way I can just have one layout "read" the information that another layout contains so I don't have to load sprites and such?

  • Have you tried to duplicate layout?

  • Have you tried to duplicate layout?

    Hello again MadSpy and thank you again for your help in the past!

    Yes, I eventually learned I should just duplicate the layout.

    I was just wondering if this was "The best practice/correct" way to do it, and was wondering if this would cause some sort of memory leak or excess data or something weird down the line.

    I guess the issue with me was, I created my initial layout and used that as a training ground / sandbox / debug zone to test everything and make sure the ai ran as it needed to.

    I then proceeded to make new blank layouts and, of course, everything broke (either because I went back and set all my objects to global because I thought they would do something else, or because I did not have every sprite loaded into on the side of the layout so some things were not moving / spawning correctly / being represented)

    So, I was just wondering if this is the "proper" way people do these things, and if I'm missing some sort of "Load all information from X Layout" or some thing of the sort.

  • I prefer to have all my objects on 1 layout and use events to create those needed on the other layout .

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have a capx that I used to test the global objects capacity: https://drive.google.com/file/d/0B-xiqK ... sp=sharing

    Note: This requires rex rainbow's Hashmap plugin.

    Hopefully it helps out some?

  • I have a capx that I used to test the global objects capacity: https://drive.google.com/file/d/0B-xiqK ... sp=sharing

    Note: This requires rex rainbow's Hashmap plugin.

    Hopefully it helps out some?

    Thanks for the help but I think that went way over my head.

    I still have a lot of reading up to do, and plugins scare me haha.

  • The plugins are not too bad. You unzip them into the exporter folder for html and they appear as Objects in Construct to add.

  • The plugins are not too bad. You unzip them into the exporter folder for html and they appear as Objects in Construct to add.

    Getting them to work isn't my biggest problem, I think I just really fear the day that they stop working/aren't updated as quickly, and I've heard they could ruin your project until they're updated.

  • Ah yea, that does happen on occasion, but rex is very good about keeping his plugins working. I think Scirra develops around some of the more popular plugins to help prevent them from breaking too.

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