PDA

View Full Version : Trouble with the stat system I'm building for a simple RPG



TheHanna
December 29th, 2007, 10:16 PM
So, I decided to try and beef up my Actionscript skills by making an RPG. Everything started off ok (I actually used the tutorial here on kirupa.com to get my bearings), and I started working on the stat system recently. I can't seem to make it work how I want it to. I want the player to be able to collect weapons and spells, and then be able to select them from a ComboBox. Different weapons and spells will give different stats, of course. However, I'm just trying to get it to where when the player changes weapons and spells, the total power bonus they get is calculated correctly, and right now it isn't. When I initially set the variables (at 1), the function processes it correctly, but when the player switches weapons or spells, it doesn't change the total power, just the weapon and spell power. Here's my code:



var totalMoney = 0;

var weaponSwitch:Object = new Object();
weaponList.addEventListener("change", weaponSwitch);

weaponSwitch.change = function() {
weaponPower = weaponList.value;
}

var spellSwitch:Object = new Object();
spellList.addEventListener("change", spellSwitch);

spellSwitch.change = function() {
spellPower = spellList.value;
}

function totalPower(nA:Number, nB:Number, nC:Number):Number {
return(nA+nB+nC);
}

var basePower:Number = 1;
var weaponPower:Number = 1;
var spellPower:Number = 1;

var power:Number = totalPower(basePower, weaponPower, spellPower);
And here's a link to my FLA:
http://www.thehanna.com/game/runelord-engine.fla

PS: I'm just using filler graphics until I get the code working.

Charleh
December 31st, 2007, 10:34 AM
You need to make sure that the power variable is set to the result of the totalPower() function after you've set the new spell power and weapon power. Just because you've set the power to be the result of that function already doesn't mean it will automatically run that function to get the new values every time anything changes. You need to either add the call to power = totalPower(etc etc etc) to your change code or to make sure that you only call totalPower instead of using the power variables in your code

TheHanna
December 31st, 2007, 02:15 PM
Thanks! It's working perfectly. My next goal is to set up similar functions and variables for stamina, speed, intelligence, wits, and wisdom and apply them to calculating damage and defense.