0 Favourites

How do I save the instance variables of a deleted object.

  • Hi everyone,

    I am working on a project where the player will get multiple guns throughout the game, if I put all the guns under a family and give the family instance variables like; clip, ammo, fire rate, damage, etc. then I can delete the guns family and then spawn the one I want, then I can subtract clip and ammo and use the fire rate and damage variables from the family, and because only one weapon is active it will use its variable. This all works fine and potentially I could add hundreds of weapons and expand the game really easily.

    I have tested it and it is by far the simplest way to do this. But, when the object is deleted and respawned it resets all its variables, this is bad. This is the neatest, fastest and simplest way to handle hundreds of weapons with minimal coding since I only need to substitute the weapons variables in to one template and It will work for all the weapons, firing, reloading, damage, etc.

    If anyone knows how to solve this or another way that it is kind of the same but could still handle multiple weapons please let me know.

    Thanks in advance for anyones help.

  • 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'm afraid local variables will always be reset. The next easiest way would be to use global variables since they won't reset. A more organized but tedious method would be to use arrays.

  • The problem with that is I need to do a set of code for each weapon, I cant just substitute it in and use a template for firing or reloading. But I still have limited knowledge of construct 2 so if anyone does know how to do something like this please let me know.

  • That the most effective method that I can think of is using arrays. Save the values for each weapon in an array slot, than when a new weapon is created, check to see if the slot for that weapon is empty, if not, load the value in it to the local variable.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
204 2,616,215
Kyatric's avatar
Kyatric Construct Team Support
Unread hot topic
99 10,152
karshinkoff's avatar
karshinkoff
Unread hot topic
167 14,513
DMT2005's avatar
DMT2005