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

Get help using Construct 2

Post » Wed Aug 12, 2015 6:23 am

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?
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Aug 12, 2015 7:04 am

Have you tried to duplicate layout?
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Wed Aug 12, 2015 7:13 am

MadSpy wrote: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.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Aug 12, 2015 7:15 pm

I prefer to have all my objects on 1 layout and use events to create those needed on the other layout .
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Wed Aug 12, 2015 9:00 pm

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?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Thu Aug 13, 2015 4:42 am

gumshoe2029 wrote: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.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Thu Aug 13, 2015 4:01 pm

The plugins are not too bad. You unzip them into the exporter folder for html and they appear as Objects in Construct to add.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Thu Aug 13, 2015 9:50 pm

gumshoe2029 wrote: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.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Fri Aug 14, 2015 3:38 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822


Return to How do I....?

Who is online

Users browsing this forum: ivanski1983, KTML5, XavierOrionGames and 5 guests