How do I get instance_vars[0] real name?

For developers using the Construct 2 Javascript SDK

Post » Sat Sep 29, 2012 11:50 pm

I'm trying to check for overlap of a solid with:

var collobj = this.runtime.testOverlapSolid(this.inst);

Then check a instance variable of the overlap instance. The following works, but i want to reference by its name, not index.

collobj.instance_vars[0]

Any help would be appreciated.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Sun Sep 30, 2012 1:53 pm

I got around it by checking all instance variables if they are strings and if it is a string, check for a certain string which then allows my behavior to disable the solid behavior just for my behavior.

What I did was make a behavior that allows the player to walk through a wall that is solid but blocks all enemies.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Sun Sep 30, 2012 2:52 pm

From what I've learned, you can't access the instance vars by name, because the minifier converts all full variable names to minified names. You can access them using an index number, as you mentioned in the OP, but that can be an unreliable solution. If instance vars get added or removed, then your index changes.

If your solution works, then that is probably the best way.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Sun Sep 30, 2012 6:06 pm

For the record, the runtime actually removes the names of variables when exporting, it's not to do with the minifier.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sun Sep 30, 2012 7:09 pm

Thanks for the replies. It has helped in making my behavior. I hope to release it soon as it is useful with the game i'm making.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests