Can you store a damage range in an array and then use it in a variable?

For context, I am experimenting with Eventing a Battle System and it is going pretty well, surprisingly.

As the title says, I am experimenting with storing information about weapons in an array. A piece of that information is a damage range for each weapon.

I have been trying to figure out how to take that damage range and assign it to a Variable, like a random value.

I have figured out a workaround, but it requires manually assigning the damage range based on the weapon being used, rather than reusing a Variable for whatever weapon is chosen.

So, for instance, the array contains the Weapon Type, Weapon Name, Weapon Damage Range (1-4, 1-6, 2-8, etc.), and the Critical Value for each weapon. Such as [1, "Dagger", 1-4, 4, 2, "Sword", 2-8, 8].

I allow the player to select a weapon to attack with, which sets Variables to the values of the applicable positions in the array.

But I can't figure out if I can actually pull a damage range from the array, like 1-8, and put that in a Variable as if I was making a Variable with a random number from 1-8.

Again, I can manually assign the damage range with Conditional Branches based on the Weapon Type. But I wanted to try to have a single Variable assigned to whatever damage range is applicable from the array to make the Eventing simpler.

I'm not sure if I am explaining this well.

Instead of setting Variable 5 to a Random Number from 1-8, I would like to set Variable 5 to the value of the damage range from the array.

But I am starting to wonder if you can even store information like that in an array. I am storing the value 1-8 for instance, but I am thinking there might not be a way to translate that into a Variable with a random value from 1-8.

I hope this makes sense and I appreciate any help that you can provide.
You could have a standard formula for all weapons, and store the input values for each weapon. E.g.

min + Math.randomInt(max - min + 1)
Then store 2 values per weapon: min and max.

Also, note that the expression 1-8, as written, equals -7.

[Edit: forgot a minus sign on the 7. 😴]
You could have a standard formula for all weapons, and store the input values for each weapon. E.g.

min + Math.randomInt(max - min + 1)

Then store 2 values per weapon: min and max.

Also, note that the expression 1-8, as written, equals -7.

[Edit: forgot a minus sign on the 7. 😴]
Ah, I think I actually understand that and I know how to test it. Thanks! I will give that a try.

The curious thing about the 1-8 stored in the array, when I set that to a Variable, it displays 1-8 instead of -7. So it displays the value rather than the math result.

So when I say Variable 5 set to $gameVariables.value(10)[2] where [2] is 1-8, then in text \V[5], it shows 1-8.

Is it supposed to show -7 instead?

Just curious since I am going to try the min/max value in the array instead, but I would still like to understand about the 1-8 in the array to avoid unintended problems.

Thanks!
Ah, I think I actually understand that and I know how to test it. Thanks! I will give that a try.

The curious thing about the 1-8 stored in the array, when I set that to a Variable, it displays 1-8 instead of -7. So it displays the value rather than the math result.

So when I say Variable 5 set to $gameVariables.value(10)[2] where [2] is 1-8, then in text \V[5], it shows 1-8.

Is it supposed to show -7 instead?

Just curious since I am going to try the min/max value in the array instead, but I would still like to understand about the 1-8 in the array to avoid unintended problems.

Thanks!
Nah, the way you've assigned it, it's being treated as a string. If you passed it to eval() it would give you -7 though.

I would recommend having that element of the array be an array containing [min, max] instead of representing the range the way you're doing currently. Less parsing required.
Nah, the way you've assigned it, it's being treated as a string. If you passed it to eval() it would give you -7 though.

I would recommend having that element of the array be an array containing [min, max] instead of representing the range the way you're doing currently. Less parsing required.
Thanks! I am going to give that a try next.

EDIT: For anyone who searches for this same topic, I tried the math suggestion and it works perfectly. Just put that formula in the Script of a Variable and replace the Min and Max entries with the appropriate Variables that you set up. Like $gameVariables.value(100) or whatever your Variable is.

Huge thanks to @caethyril and @Trihan for the assist and teaching me something new!

Original thread: https://forums.rpgmakerweb.com/threads/can-you-store-a-damage-range-in-an-array-and-then-use-it-in-a-variable.154147/