RPG Stats - temporary changes

Discussion in 'Game Development (Technical)' started by lordGoldemort, Jul 24, 2016.

  1. lordGoldemort

    lordGoldemort New Member

    May 26, 2016
    Likes Received:
    I'm writing a turn-based RPG, and have a small coding dilemma about stats. Specifically, it's about when you need to make temporary changes. Say the player has a speed which is currently 50, and the spell "slow" takes 10 off the speed. So it's reduced to 40, and in a few turns it has 10 added back so it's back at 50. Fine, cool with that.

    Now, suppose the speed is 5. I take the 10 off, but aha, can't be < 0, so I set it to 0. A few turns later I restore it, but now it goes back to 10, which is clearly wrong and an exploitable side-effect, so I don't want that to happen.

    I have 2 choices as I see it.

    1. Allow the speed to be negative, but whenever I use it, I clamp it to the range [0,100] (say). Note that the same goes for if the speed is 95, I allow it to go to 105 if the "fast" spell is used. I need to be very careful when coding this, because if I fail to clamp, things will go quite wrong and it will be a bit unpleasant to track down.

    2. Create an undo record that says "only increase by 5 when you put it back". This requires an architecture for storing the changes, but also needs quite a lot of care to ensure consistency and I am not 100% convinced it can be made to be consistent because other things can be messing with the stats inbetween the change and the undo. I rejected the "store the actual speed it goes back to" option for this very reason.

    So: am I missing other possibilities, or if not, which of the two appeals and why?
  2. LongRunGames

    LongRunGames New Member

    Jul 5, 2016
    Likes Received:
    I think it's down to what you think will work best with the rest of the game I.e. if the speed Is used in more than one place, then letting it go below zero may cause more issues, I would personally use two lists of stats, a base list which is your characters default and a difference list which is your current effects i.e if speed was reduced by ten you would check that the base speed is above 10, if not you would set the speed in the difference list to -the value in the base list, otherwise it would be -10. then when using the value you could say speed = base speed + difference speed, once the effect wares off you could set the difference speed to 0 and it would have no effect.
  3. kevintrepanier

    Original Member Indie Author

    Feb 14, 2006
    Likes Received:
    You could save the initial value in a temp variable and roll it back after the effect or just never affect it directly with the spells but have a stat modifier variable instead. In battle you use "base_stat + stat_modifier".
  4. Osmosis D. Jones

    Osmosis D. Jones New Member

    Jul 15, 2016
    Likes Received:
    I would say one question you need to answer before you decide is: do you know how much you have to remove. If the speed buff is allways plus 10, then the answer is yes. If you have different buffs and there are prozentual ones the the answer is no.
    If the answer is yes, the i would recommend the first solution. I would make one methode getSpeed() which return the speed in range. So you only have to program it once and if you notice a mistake at speed range it can only be at one place.
    If you have much different buffs, i would recommend to save them in a list, ether self updating with timers, or you save them with identifiers (like names) and then remove them using this. Then the method getSpeed() would always compute the actual speed. Or use a updateSpeed methode which calculates the speed and saves it for the usage of this round.

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer