Javascript SDK template - r124 update

For developers using the Construct 2 Javascript SDK

Post » Tue Apr 02, 2013 8:04 pm

Hi all,

The Javascript SDK template has been updated for r124. Download here:

http://www.scirra.com/downloads/javascript-sdk-template.zip

Changes
- Plugin and behavior templates include saveToJSON() and loadFromJSON() template methods. You must implement these for your plugin or behavior to support full-state save/load or the Persist behavior. Usually this is relatively simple (see the comments - you just need to return a JSON object in the save method, then read from the same object in the load method).
- Plugin and behavior templates now include an onDestroy() method by default. You should drop references or recycle objects for GC in this method, since the runtime will keep the actual instance around for recycling.
- Some .c2addon samples are bundled, as well as the source folders to zip to create .c2addon files. This should help you easily create .c2addon packages.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Apr 03, 2013 1:00 am

@Ashley

I love the save/load system. I will support this feature as soon as possible.rexrainbow2013-04-03 01:01:07
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Wed Apr 03, 2013 4:41 am

@Ashley
I have a Photon Cloud multiplayer behavior on the go. Intuitively (which means I haven't thought through this in detail), I'd think it's not appropriate to implement save/load since the game state is not fully contained within any single client that might be wanting to do a save/load?
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Wed Apr 03, 2013 2:18 pm

As the r124 release notes pointed out, generally network stuff isn't included in savegames. Things like the AJAX object and WebSockets are completely skipped when saving and loading, because it doesn't really make sense to save or load them. The same goes for any multiplayer features - it really doesn't make sense to save on the client, since the server ought to have the only real instance of the game. So yes, no need to implement save or load there.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Apr 03, 2013 6:56 pm

[QUOTE=Ashley]... So yes, no need to implement save or load there.[/QUOTE]
Thanks for your confirmation, Ashley (and for saving (!) me a bit more work :) )
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Fri Apr 05, 2013 10:03 am

[code]var inst = this.runtime.getObjectByUID(uid);[/code]
It's cool~ C2 has a global UID to inst table now.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Apr 05, 2013 4:05 pm

@Ashley

Question:
Will it cause performance loss if I use "this.runtime.getObjectByUID(uid)" to get instance reference to replace saving instance reference directly?

In case of saving instance reference directly,
It need to check if the reference was destroyed in destroyed callback. And, this destroyed callback need to be released when this behavior/plugin had been destroyed.

In case of saving instance reference by UID then pick instance reference by calling "this.runtime.getObjectByUID(uid)",
It only need to check if the return reference is not null.
rexrainbow2013-04-05 16:11:21
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Sat Apr 06, 2013 2:33 pm

I'm not exactly sure what you're trying to do... and you should still do things like reset UIDs when the objects are destroyed as a good practice. However getObjectByUID should be fast (it's based on accessing object properties, if you look it up it's 1 line), and often storing instances by UID makes it easier to support saving/loading too.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Sat Apr 06, 2013 5:00 pm

@Ashley

"storing instances by UID makes it easier to support saving/loading"

Totally agree.

Anyway, thanks for giving me "getObjectByUID" method.rexrainbow2013-04-06 17:02:14
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Thu Apr 11, 2013 4:13 am

@Ashley

Array or dictionary objects could not add any behavior, how to "no save" these kinds of object?


BTW, it might be more flexible if plugin which is "object" type (for example, Array or dictionary) could be added behaviors.rexrainbow2013-04-11 04:31:35
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest