Manipulating Layouts that aren't the 'active' Layout

Get help using Construct 2

Post » Thu Jul 14, 2016 2:19 pm

Hey all,

TL;DR - Can I make stuff happen on a layout that's not the "current" layout. IE - set variables and read from them on an "inactive" layout.

I was wondering if anyone knew anything about changing things on a layout that isn't the current displayed layout?

What I have currently, is a layout that is the "game world" and a second layout I'm using as a map. I want to be able to have events happen on the map while that layout isn't being "run" at the time.

It would still need to be able to read/write global and instance variables and (maybe) a dictionary object specific to the layout, but no collisions or anything like that (though they would be a bonus)... would setting the layout to GLOBAL simply be enough to do what I want? I'm hesitant to go through the process of changing the way a bunch of event sheets interact just to test it - unless nobody else knows the easy answer - I've kind of set myself up in a dumb way with event sheet inclusions that would take a bit of work to de-spaghettify. xD

If by chance this ends up being not possible... I have an idea on how to save and load the relevant data between layouts, but I'm having nightmares already thinking about how complex it would end up being in the near future when things get more complicated in my game. Hoping not to have to go that way.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Thu Jul 14, 2016 2:33 pm

I tried to accomplish something similar before on a test project. I didn't really get to finish any working prototype with it, but some things i tried out was was using a regular layer as the Map, and setting the layer to be global (But hidden)except when in the map layout. I remember a bit, but It was about 2 years ago or so, so I don't remember really how far i got on it, but I was getting close. I also tried saving the game to store the positions on the global layer, and loading the game again to restore it to the save state. Unfortunately I don't have any capx of that prototype left as it was on my old computer that broke down. Maybe something like that could work.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,028
Reputation: 13,353

Post » Thu Jul 14, 2016 2:37 pm

Ahhh crapola.

I kind of felt like that was going to be the answer... thanks @tunepunk I will make the changes soon to head in that direction. I knew I should have just made the map in the same layout, I was just worried about performance due to the number of tiles to be drawn on the map and the potential loops running to calculate stuff.

I don't know of a better way than to have shared timers on each layout that are set from a global clock... then to quickly compute "time jumps" between the layouts being open using hard drive committed data (using a dictionary or an array).

FARK D:

I'm hating myself right about now, but I'm up for the challenge...

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Thu Jul 14, 2016 3:03 pm

https://dl.dropboxusercontent.com/u/205 ... tsave.capx

Pont and click to move the blue dot

This seemed to work. Saving positions to localstorage. Maybe you can use for each on the layer, to save all the things, then for each load as well.

/
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,028
Reputation: 13,353

Post » Thu Jul 14, 2016 3:22 pm

Thanks @tunepunk

I'm using NWjs with a nested dictionary save system, in JSON.

I know how I can do what I need to do now since there's no "easy way" but it's going to be a little hellish, mostly due to the way my map tiles are generating. I think I may need a better over-all approach to how I'm doing the map, or come up with some "creative" way around my issue.

I will need to be able to track the positions of (potentially several) objects as well as monitor "random events" that happen on the map - then interpolate them from the clock based calculations made on the "main" layout where most of the game takes place. It's almost like I need to have two separate things running at the same time and talking to each other... but without all of the draw calls and loops mashed into a single room.

I do have a "creative" method in mind for working around the issue and possibly establishing a (maybe fun/maybe boring) mechanic in to the game - whereby the player actually discovers the map manually using some sort of "magnifying glass" and then visits any discovered locations that are already "discovered" - rather than being able to send out a rally point to unexplored (not-yet-generated) areas and having it generate on the fly.

I'm starting to wonder if I make any sense anymore? xD

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Thu Jul 14, 2016 3:31 pm

Sounds complicated. Seems like the global layer seems to be the approach though. Then just update on layout switch. I can't really think of any other way to have an inactive layout being modified, unless it's all happening in an array by numbers, and somehow transfer the whole array from one layout to another.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,028
Reputation: 13,353

Post » Thu Jul 14, 2016 3:44 pm

tunepunk wrote:Sounds complicated. Seems like the global layer seems to be the approach though. Then just update on layout switch. I can't really think of any other way to have an inactive layout being modified, unless it's all happening in an array by numbers, and somehow transfer the whole array from one layout to another.


That's essentially what I'm doing now using nested dictionaries (then saving a JSON file with NWjs)... transferring data between each layout... but it's about to get a whoooole lot more complicated xD

I think I'm going to have to make some "ghost objects" on my main layout that will dummy as data-clones to my second layout. This way I will have a few invisible objects that I can store the same instance variables and positioning data in, then save and load that onto the map; almost like a reverse mini-map.

I'm still not sure how to handle tile based "random events" though if the tile data isn't directly accessible without changing layouts. I'm not sure that I could really go with using a "map layer" and just turning it on and off, because of the sheer amount of objects between my main "game layout" and the map - it would implode something I think. ARGH!

*EDIT*
Bugger it, I'm going to try and merge the layouts using a global layer and just if if catches on fire or not - there's only one way to find out right?

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Thu Jul 14, 2016 4:54 pm

Absolutely, you won't know until you tried. ;) Let me know how it works out.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,028
Reputation: 13,353

Post » Fri Jul 15, 2016 5:27 am

I've half converted everything over to be on the main layout using a global layer from the map layout - but now I have to re-work how I was saving and loading data since there is no layout changes anymore (so the layout isn't "clearing" itself automatically between data calls).

So far so good, but the real test will be when there is a lot of action going on AND I open the map up... I have a feeling this is going to impact performance quite a bit once things are in high gear.

I can't really see any other real way around it though, since I need such fine control over the map at all times - because that will be I guess "really" where the game takes place. The side-view screen where the characters are is really only a small part of it all. Oh well, I spent a few hours yesterday (while thinking about how to approach this issue) doing some more optimisations on the event sheets and found quite a bit of wasted CPU time, which I have now (mostly) fixed.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Fri Jul 15, 2016 7:02 am

I have no encountered one annoying problem now...

My map layout is set to "unbounded scrolling" but using the layer as global in my main layout still uses the bounded scrolling attribute from the main layout.

Any ideas how I can get around that? :/ I guess I need to make the main layout unbounded as well - then add some artificial camera bounds somehow unless the map is open?

*EDIT*
Nevermind, I answered my own question here...

Anyway it seems pretty good so far - I have a map that has generated about 5000 tiles (which isn't many compared to the possibilities but it's still a good test I think) and about 80 marionette/characters with a stable 60fps still - when I open the map however with that many characters there's noticeable fps drop so I will have to see what I can do about that, but at least I can have full control over things now.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Next

Return to How do I....?

Who is online

Users browsing this forum: Bootfit, Yahoo [Bot] and 22 guests