Weapon Stats

I’m trying to add a combat system to my game, but to do what I have planned I need to know if there is a way to add stat values to items (Sword has higher damage than Dagger, but Dagger has higher attack speed etc.)

1 Like

You can. One method would be creating an attack, defense and agility and then increasing and decreasing the amount on which ever the player chooses. For example

*if Weapon_chosen = sword
    *set Attack +5
    *set agility -5
   *set attack -5
   *set agility +5
1 Like

so essentially I could use a gosub to a if/elseif/else string to determine the stat buffs based on the equipped weapon?

Technically yes, That’s one way of doing it.

A slightly more complex way, but much easier to maintain, is to use arrays. Array notation in choice script is a bit unique, but it would work like this. In startup.txt, define your weapons:

First, define the attributes for each weapon and give a default amount. This is the value you will ultimately use in your code.

*create attr_damage 0
*create attr_agility 0

Then, give a unique (constant) number to each weapon thus:

*create WEAPON_SWORD 1

Then create unique numbers for attributes

*create DAMAGE 1
*create AGILITY 2

Now define the attributes for each weapon, which is weapon_WEAPON-NAME_DAMAGE etc
The following defines sword is +5 damage, -5 agility; dagger is -1 damage, +5 agility

*create weapon_1_1 5
*create weapon_1_2 -5
*create weapon_2_1 -1
*create weapon_2_2 5

Now, this is a fair bit of work upfront, but you can then have a simple function:

*label set_weapon
*params p_weapon

*set attr_damage weapon[p_weapon][DAMAGE]
*set attr_agility weapon[p_weapon][AGILITY]


You can add new weapons to the weapon array to your heart’s content, but you never have to change the function and you don’t have to worry about keeping all the if statements in line.

All you have to do is:

*gosub set_weapon(WEAPON_SWORD)

You can then use the attr_damage and attr_agility variables in your combat system.


It’s more work to set up originally, however, it seems like it would be more convenient in the long run compared to using if/else statments. I’ll give it a shot.

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.