HELP. Advanced instance variable help needed. [Solved]

Get help using Construct 2

Post » Fri Jan 22, 2016 11:21 am

In the game I'm making the player will get many different weapons. The easiest way to manage a lot of weapons with minimal coding is to put something to use as an object that will not be deleted in a family and give the family instance variables like; damage, clip, ammo, fire rate, reloading, active, etc.

What happens is when you select a weapon it deletes all the weapon sprites and spawns in the selected sprite and sets the "data holding objects" active variable to 1 and all others to 0. Then I can just use 1 template for all the weapons but it needs to detect which weapons is active and use its stats.

I have done this before but I deleted it, now I need it again and I can't work it out.

Shortened: test for which weapon is active and use its variables. But it needs to select one from multiple objects with the same instance variables by seeing which one is 'active'.

Thank you to anyone who can help me, or anyone who can figure out an easier way.
Last edited by currypuff on Sun Jan 24, 2016 10:44 am, edited 1 time in total.
B
14
S
3
Posts: 55
Reputation: 912

Post » Fri Jan 22, 2016 6:15 pm

You can do instance variables on individual sprites too.

I would look at using JSON to layout all of your weapons ahead of time and load it into a rex_hash then just pull values to populate your sprite instance variables. (presuming that the stats don't change dynamically).
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Fri Jan 22, 2016 11:47 pm

Thanks but the instance variables on the weapons which I think your talking about wont work because of two reasons, instance variables reset when their object is deleted and the stats will change throughout the game.
B
14
S
3
Posts: 55
Reputation: 912

Post » Sat Jan 23, 2016 12:42 am

At risk of sounding a bit off of what your actually asking for, have you thought of having one sprite with multiple frames, setting each frame to a variable number (or name for that matter) for that spite and simply using that as all of the possible weapons (Or is that what you're referring to now)? You could use that in tangent with an array to keep track of ammo etc.

Alternatively, I imagine you could also set the weapons variables to the player sprite and use those to spawn the correct weapon sprites or delete them (or change frames as mentioned above).
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Sat Jan 23, 2016 9:04 am

The problem with that is that I want to have about 100 weapons and this method would be very time consuming my way of having all the variables in a family and setting one weapon active and only choosing the stats from the active weapon would be the easiest and smallest way, only if I could figure out how to use the stats from the active object.
B
14
S
3
Posts: 55
Reputation: 912

Post » Sat Jan 23, 2016 9:26 am

currypuff wrote:The problem with that is that I want to have about 100 weapons and this method would be very time consuming my way of having all the variables in a family and setting one weapon active and only choosing the stats from the active weapon would be the easiest and smallest way, only if I could figure out how to use the stats from the active object.


if you have to make 100 weapons and you don'w want to use one sprite for all of theme (considering 2 animation per weapon) you are right, will be very confusing.

if you use a similar weapons, you can choose different way to achieve that, one for example is just make an invisible sprite with all variables that spawn just another sprite with the design of the weapons.

you can also divide the weapons for typology. like make 5 sprite for all weapons... for the variables, you can put into the family and make there.

it depends how you make the weapons... so I suggest you to try without any graphics, just make a square with different frame of fire/reload and try the best method for you
B
21
S
9
Posts: 298
Reputation: 2,967

Post » Sat Jan 23, 2016 11:04 am

Why not just save the active UID to some global variable (let's call it activeWeapon)? Now whenever you need to read or save data from/to instance variables you simply pick by UID and do whatever is needed.
ImageImageImage
B
31
S
19
G
82
Posts: 1,038
Reputation: 46,205

Post » Sat Jan 23, 2016 11:14 am

The problem with that though is that I want the weapons to have clips, ammo and be able to be reloaded, these weapons don't just spawn in and get deleted they need their info saved and altered, so that's why I can't transfer the info into a 'template', I need to take it directly from the original data holder. Like every time you empty a clip it subtracts that amount from the overall ammo and stuff like that. So this is why I need to figure out how to only use variables from an 'object'. I might eventually put up a simple capx that better describes this later.
B
14
S
3
Posts: 55
Reputation: 912

Post » Sat Jan 23, 2016 12:13 pm

If you pick from weapons family by UID you grab te particular weapon, and you are able to manipulate instance variables for this particular weapon.
ImageImageImage
B
31
S
19
G
82
Posts: 1,038
Reputation: 46,205

Post » Sat Jan 23, 2016 12:38 pm

I've made a quick example.

Image

1. currentlySelectedWeapon holds the UID of the weapon object
2. weapons family contains all weapons
3. once you pick family member by UID all actions made on family objects affecting that particular object with UID you provided so you can add/remove ammo etc.

Note that instance variables must be family instance variables.
ImageImageImage
B
31
S
19
G
82
Posts: 1,038
Reputation: 46,205

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests