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

Get help using Construct 2

Post » Wed Jan 20, 2016 12:00 pm

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.
B
14
S
3
Posts: 55
Reputation: 912

Post » Wed Jan 20, 2016 12:19 pm

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.
B
41
S
20
G
31
Posts: 684
Reputation: 20,189

Post » Wed Jan 20, 2016 11:34 pm

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.
B
14
S
3
Posts: 55
Reputation: 912

Post » Thu Jan 21, 2016 1:48 am

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.
B
41
S
20
G
31
Posts: 684
Reputation: 20,189


Return to How do I....?

Who is online

Users browsing this forum: COGames, Meqara and 4 guests