How do I save an object type to an array and recreate it later?

0 favourites
  • 5 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hey folks :)

    So i have designed an enemy, which consists of a lot of different parts working in a particular way together. The only way to do this economcly was in the layout editor. Everything is fine so far, so now i want to save this whole anemy to an array to recreate it later on without using another layout or resetting ths layout.

    what i want to do now, is to set a 4th value, of which object type to spawn actually spawn. in other words pick the right sprite for the job. Is there some kind of system expreassion to save the actual object type, or do i have to write an "tranlator" ala

    if id = 1 pick sprite1, if id = 2 pick sprite2 [...]

    as there are many parts it seems kind of unflexible. also because of the nature of this i cant just work with one sprite (and then just set the animation frame) as i have to build the whole enemy in the normal layout editor by hand. Is there any good way to do this? Do i miss something or is it not possible to save an object type to an array?

    Kind regards

    Joschi

  • In C2 you can't create objects by string name, so the only option is to use just one sprite with many frames/animations, or do a bunch of events like if id = 1 pick sprite1, if id = 2 pick sprite2 [...]

    In Construct 3 you can create objects by name.

    Instead of saving each property (x, y, angle, width etc..) separately in the array, I suggest saving the entire object state as JSON string. So, for example you put Leg.AsJSON into the array. Then when needed you create Leg sprite and do "Leg Set from JSON".

    .

    Also, take a look at Spriter addon:

    construct.net/en/blogs/construct-official-blog-1/spriter-support-construct-803

  • Hey dop2000

    In Construct 3 you can create objects by name.

    Finally a valid reason for me to switch to construct 3 :D I might have to do so soon... Basically i just wait for the offline version to be more polished, not a big fan of the new version yet...

    So, for example you put Leg.AsJSON into the array. Then when needed you create Leg sprite and do "Leg Set from JSON".

    i have already experimentred with this, it makes a lot more sense then savong all the variables seperatly...

    Also, take a look at Spriter addon

    i have to take a closer look at this, never knew you could use those directly... but i think it wont help me with this particular project...

    For now i will rethink the whole process, maybe i find another viable solution :)

    Thanks again dop2000, i appreciate it!

  • Finally a valid reason for me to switch to construct 3 :D I might have to do so soon... Basically i just wait for the offline version to be more polished, not a big fan of the new version yet...

    C3 Desktop build works quite well. I am not sure though if you can use it completely offline (without Internet connection).

    C3 now has tons of new features, it's much more advanced than C2 and it definitely worth switching over to.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Mostly i have internet, so thats no problem, i read somewhere that you need to connect every 7 days or so which is fine... thing is how i use constrcut it is quite pricy for me... Most likely i will never make any real moneys from my games, so i do it mostly for fun, and 1 or 2 month a jear (when i have time for it besides of my main job). I would happily subscribe if i could switch the subscription on / off on a monthly basis (as i can with every other subscription i have) problem is nowdays, everything is subscription based, so you really have to keep an eye on it... Jea construct alone is not much and it might be fairly priced, but so are the 6 other services i use and bam, you pay 300$ a month worth of subscriptions... (Sorry for offtopic)

    I will take another look at the free version of 3 and just programm a little bit in it to see if i can get used to the interface... i might switch, or give up making games hahaha :D

    Thanks again for pointing me in the right direction

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