[Plugin] instance bank2

Post your completed addons to share with the community

Post » Sat Oct 19, 2013 12:04 pm

Great work! I think there is a bug with the picked by saved UID.

After load all instances, picking by saved UID causes a duplication.

The javascript code I think is wrong is

[code]
InstBankKlassProto.LoadAllInstancesEpilogue = function()
{
        this._z_sorting.Sorting();
        hash_clean(this._saveduid2inst_map);
};
[/code]

The map of UIDs->saved instances is wiped after loading. I don't think this is the correct behaviour for using the pick by saved UID functionality after a load all instances.

Anyway, to fix I just commented out the hash_clean line. Works for my program although obviously I might not understand the intended full semantics of the plugin.

PS the duplication occurs because invalid pick params to pick by saved ID lazily creates an instance if none exists. I wonder if this is a bit dangerous, better to alert an error? tlarkworthy2013-10-19 12:13:33
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Sun Oct 20, 2013 6:53 pm

Clean bank does not clear saved instance map which can cause some weird bugs down the line. I suggest changing JS "CleanBank" to:-
[code]
InstBankKlassProto.CleanBank = function()
     {
        hash_clean(this._bank);
        hash_clean(this._saveduid2inst_map); //NEW LINE
     };
[/code]
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Wed Oct 23, 2013 2:19 am

Just learned today how insanely useful this is for level editors, especially when combined with the canvas plugin. Thanks man!!!
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sat Oct 26, 2013 1:45 am

Found another bug that the saved instance map doesn't get wiped after a loadBankFromJSON.

Its a fairly simple fix.

I people want the bug fixes I would consider putting it on githubtlarkworthy2013-10-26 01:46:04
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Wed Oct 30, 2013 3:13 am

@tlarkworthy

There is an official save/load feature, I though this instance bank might not be necessary anymore.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Wed Oct 30, 2013 3:30 am

[QUOTE=rexrainbow] @tlarkworthy

There is an official save/load feature, I though this instance bank might not be necessary anymore.[/QUOTE]


@rexrainbow I don't believe, it's hard to manage the selected instances, save and load does for everything including positions, it's annoying.


I made a suggestion thread



http://www.scirra.com/forum/suggestiOn-save-to-Object_topic78790.html
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Wed Oct 30, 2013 4:36 am

There was an official expression: AsJson and action: Load from Json feature, so please do not use saveloadstatus plugin.
Last edited by rexrainbow on Wed Feb 26, 2014 3:02 am, edited 1 time in total.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Wed Oct 30, 2013 5:36 pm

Thanks rexrainbow,

I think that plugin will work for me.

Note to future people: InstanceBank's JSON data won't work between exported websites and the development versions due to

https://www.scirra.com/forum/help-me-fix-instancebank-across-exports_topic78823.htmltlarkworthy2013-10-30 17:39:21
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Wed Oct 30, 2013 10:20 pm

HALLELUJAH!!!!!

4 and a half hours later I have it working!

The only holdup with SaveLoadStatus is that is does not like transferring data between layouts. The internal SDK loadInstanceFromJSON check the layer, and kills the instance if it can't find the correct layer to put the instance in. This is unfortunately is always the case when you load instance data from a different layout than you use the data :s

Anyway I altered rexrainbow's SetStatus to overwrite the JSON data when loading, so the instance will be recreated *except* the layer info.

[code]
    Acts.prototype.SetStatus = function (obj_type, status)
     {     
        if (!obj_type)
            return;
        status = JSON.parse(status);
          console.log("loading...", status);
         //if (obj_type.sid != status["sid"]) //removed, protection against instanciating in different layers
        var insts = obj_type.getCurrentSol().getObjects();
        var i, cnt=insts.length;
        for (i=0; i<cnt; i++){
               status["w"]["l"] = insts.layer.sid //force loaded object into layer of containing instance
            this._set_status(insts, status);   
          }
     };   
[/code]

(It looked like in the code you knew this Rex but it did not work for my use case.)
B
14
S
5
G
1
Posts: 60
Reputation: 1,052

Post » Thu Oct 31, 2013 12:29 am

wow thank you so much
B
13
S
3
G
1
Posts: 51
Reputation: 971

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 3 guests