Pass object to function using r151 AsJSON?

Discussion and feedback on Construct 2

Post » Tue Nov 26, 2013 9:13 pm

In the r151 change log, Ashley mentions this about the new AsJSON expression:

"...as well as other useful things like setting one object's state to another's."

If I'm thinking about this correctly, could we simulate passing an object to a function by doing this:

1) Store AsJSON data of object to a string.
2) Delete object.
3) Call Function, passing AsJSON string as a parameter.
4) Inside the function, create replacement object from AsJSON data.
5) Manipulate new object based on whatever it is the function is designed to do.

Of course, I'll be experimenting with this, but I'm too impatient to wait until I'm home from work. Thought I would toss it out there for others to comment on :) Thanks.



ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355

Post » Wed Nov 27, 2013 1:10 pm

Do not do that, it will be incredibly slow! You can already pass objects to functions - just pass the UID.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Wed Nov 27, 2013 3:24 pm

Unless something has changed in the latest builds, I don't think you're able to create an object using an expression. If you create try to create an action from System -> Create Object, you'll have to pick it manually.
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Wed Nov 27, 2013 8:30 pm

[QUOTE=Ashley] Do not do that, it will be incredibly slow! You can already pass objects to functions - just pass the UID.[/QUOTE]

Seems I learn the right way to do things by process of elimination... :)

Also, @andreyin , I was thinking create a new object and then on the next line import all the properties from the saved JSON string, effectively making a clone in two steps. Clearly, this is the long way of doing it!clrammer2013-11-27 20:33:56
ImageImageImage
B
38
S
5
G
4
Posts: 79
Reputation: 5,355


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 18 guests