0 votes
by (2.3k points)

My game has several different characters in it starting with different items, such as:

<<set $playerInventory.micromecha = { name: "MiniRobo",
quantity:1,
charges: 20,
damage: 16,
description: "A mini-robot that helps protect the owner. While less damaging to enemies it's power charge capacity is smaller." }>>

<<set $playerInventory.machomecha = { name: "BigRobo",
quantity:1,
charges: 15,
damage: 25,
description: "A larger robot that helps protect the owner. It's power charge capacity is greater than the MiniRobo model." }>>

Now the issue is that in-game I want to eventually have them able to pick up replenishments / restorations to their items' charges.

However due to there being more than one character I won't know which one has the right maximum 'charge'.

So my question is, how do I have it so that when they pick up a replenishment / item it is going to be the right one? To basically have a set 'sub-variable' for the charges.

IE I have something along the lines of:

<<set $playerInventory.machomecha.charges to $maxmachomechacharges>>

???????

That way when it comes to pickups in the game they are at whatever the maximum is for that type of item.

1 Answer

0 votes
by (44.7k points)
We can't really answer this question since you haven't explained what "the right one" means.  You'll need to explain how you would determine what "the right one" is.

That said, if you can do that, then you've mostly answered your own question.
by (2.3k points)

Well it could be either depending on what the players chooses. They'll be eight different characters with different items but along the same array formating as shown.

I just want to know if I can add a generic item amount that is preset without using actual figures each time.

<<set $playerInventory.micromecha  ??????????????>> 

 

by (44.7k points)
edited by

"It could be either" what?  I don't know what you're referring to there by "it" or what the two options are there, so I'm still confused by your question.

If you're trying to set the item's "charges" property to that item's maximum charge, then you'll need to add a "maxCharges" property or something like that, so that the game knows what the maximum charge can be.  Something like this:

<<set $playerInventory.micromecha = {
	name: "MiniRobo",
	quantity: 1,
	charges: 20,
	maxCharges: 20,
	damage: 16,
	description: "A mini-robot that helps protect the owner. While less damaging to enemies it's power charge capacity is smaller."
}>>

Then, if you wanted to set an item to its maximum charges, you could do something like this:

<<set _item = "micromecha">>
<<set $playerInventory[_item].charges = $playerInventory[_item].maxCharges>>

You could set _item to any item's name, and the line after that would still set that item's charges to its maximum charges (assuming the item exists and has a "maxCharges" property).

If that didn't answer your question then you'll need to need to more clearly explain the question.

by (2.3k points)
I think that will work out. I'll let you know.
...