0 Favourites

someObject = someObject = Impossible?

  • Hey everyone!

    I think the title says it all... Construct2 needs to be able to copy objects. Further It should also be able to copy shared instance variable through families. For ex:

    Bat (of family FlyingAnimals) = Eagle (of the same family)

    Behavior copying should aslo be allowed... ie:

    SomeObject.physics settings = someObject.physics settings.

    Construct 2 also needs to be able to pick any object and then test its type. With only 1 family (and since families are abstract you always need to refer to objects) things get difficult with complex objects.

    anyway...

  • I don't normally bump...

    but seriously - nobody has ever wanted a copy of an object instance during runtime... Nobody has wanted to copy behavior settings at runtime?

    If you have 30 variables on an object and you want a new instance to be the same you have to:

    1. create the new object, and store its uid

    2. store the UID of the object you want to copy

    then...

    then ignoring the mess of trying to pick the same object type and setting the correct one to the other correct one...

    Self.variable_A = Object.Variable_A

    Self.variable_B = Object.Variable_B

    Self.variable_C = Object.Variable_C

    Self.variable_D = Object.Variable_D

    Self.variable_E = Object.Variable_E

    Self.variable_F = Object.Variable_F

    Self.variable_G = Object.Variable_G

    Self.variable_H = Object.Variable_H

    ... and so one.... if you have complex objects, or compound objects, get ready to have a nightmare and no way around it...

  • Have you looked at all the 3rd party plugins? Maybe there's some there that can help. I'm an OO guy too, but C2 just isn't.. But something like 'clone' would have its uses for sure. In the meantime use family instance variables a lot (I'm thinking that for flexibility, they are the only type of instance variables that should be used) and have a clone() function for each family type. Just some ramblings before my first coffee.

  • From the manual a common expression is .asjson and there is also the common action "set from json".

    I haven't used it myself yet but I believe it can be used to clone object state.

  • There are times when you very well may want to clone an instance and its much faster and safer to do it in the engine that through the event sheet. With that said check out this plugin i found on github for you. If it does not do exactly as you want you can modify the plugin to get your desired effect.

    Search for "arcturial/sprite-factory" on GitHub

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I had the same issue. The only solution I found is to create a helper family with the object in it.

    Object.Variable = Family.Variable

  • From the manual a common expression is .asjson and there is also the common action "set from json".

    I haven't used it myself yet but I believe it can be used to clone object state.

    I'll check that out - If not, I didn't consider 3rd party plugins, but I'll check out the gthub example.

    Its a bit weird, but I have shyed away from working with custom plugins and behaviors (I don't even write them myself) - part of this is because If I am going to code I bust out unity, which I find more user friendly in that aspect. Perhaps I have not given construct 2 enough time. But Given there is very little documentation on writing plugins and or behaviors... idk.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Topic
0 Favourites
impossible in iphone
18 2,200
jayderyu's avatar
jayderyu
Topic
14 816
lennaert's avatar
lennaert
Topic
13 979
Nitro187's avatar
Nitro187