Pass object to function using r151 AsJSON?

  • 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.

  • Do not do that, it will be incredibly slow! You can already pass objects to functions - just pass the UID.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • Do not do that, it will be incredibly slow! You can already pass objects to functions - just pass the UID.

    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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)