How to destroy object using Browser -> execute JavaScript

Get help using Construct 2

Post » Tue Oct 17, 2017 3:58 pm

Hello) I find this function in the code of fade behavior:
Code: Select all
this.runtime.DestroyInstance(this.inst);

Question: what I need to write instead "this", to delete sprite using Browser -> execute JavaScript
B
12
S
3
G
4
Posts: 14
Reputation: 2,272

Post » Tue Oct 17, 2017 4:43 pm

I solved this!!!!!! :D :D

Code: Select all
"this.runtime.DestroyInstance(this.runtime.objectsByUid[2]);"


instead "2" you need to write object's UID that you want to destroy)
B
12
S
3
G
4
Posts: 14
Reputation: 2,272

Post » Tue Oct 17, 2017 5:21 pm

Have you really thought this through?
B
179
S
50
G
208
Posts: 8,723
Reputation: 128,814

Post » Tue Oct 17, 2017 8:52 pm

newt wrote:Have you really thought this through?

Yes, I am. I spend a lot of time reading source code of C2. I need it because I want make action that unload unnecessary animations from memory. So I started from picking certain sprite. To make question easier to understand I chose "destroy" function.
I hope that I understood the question correctly, because English isn't my native language)
Удачи)
B
12
S
3
G
4
Posts: 14
Reputation: 2,272

Post » Tue Oct 17, 2017 10:44 pm

We already have a destroy action.
You know that, right?
B
179
S
50
G
208
Posts: 8,723
Reputation: 128,814

Post » Wed Oct 18, 2017 9:46 am

This isn't a good idea. Minifying the script changes all the names so will break any cases you make runtime calls by executing JS.
Scirra Founder
B
415
S
248
G
92
Posts: 25,295
Reputation: 200,984

Post » Wed Oct 18, 2017 1:50 pm

Ashley wrote:This isn't a good idea. Minifying the script changes all the names so will break any cases you make runtime calls by executing JS.

Well, could you give me advice on how to unload unnecessary animations from memory. I now create a fairly large space simulator, accordingly I have lots of large animations (gas planets and stars), and they take up a lot of RAM, although they do not use everything at the same time. I already did a selective download of animations, but now I need to do their unloading
P.S thank you so much for such a cool engine
B
12
S
3
G
4
Posts: 14
Reputation: 2,272

Post » Wed Oct 18, 2017 1:55 pm

newt wrote:We already have a destroy action.
You know that, right?

Yes I know. I chose this function to facilitate the issue. It was important for me to understand how to use the "execute JavaSript" to call a function from the c2runtime.js
B
12
S
3
G
4
Posts: 14
Reputation: 2,272

Post » Wed Oct 18, 2017 2:34 pm

I don't think highjacking a function will get you where you want. Normal unloading is done layout by layout.
Also, you would have some issues with using the uid like that. Those ids get recycled.
B
179
S
50
G
208
Posts: 8,723
Reputation: 128,814

Post » Wed Oct 18, 2017 3:28 pm

newt wrote:I don't think highjacking a function will get you where you want. Normal unloading is done layout by layout.
Also, you would have some issues with using the uid like that. Those ids get recycled.

UID is not problem. Because we can pick certain sprite and then:
Code: Select all
"this.runtime.DestroyInstance(this.runtime.objectsByUid["&Sprite.uid&"]);"

Ashley is right, after minimizing the code, I can not call the functions that I need. I will try to create a plug-in or behavior that will do this.
B
12
S
3
G
4
Posts: 14
Reputation: 2,272

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest