PDA

View Full Version : [AS3] Statistics for a Flash Game (question)


GoDziOTHC
11-30-2011, 03:25 PM
I've already implemented stats in as3 but they do not refresh when I make a change within a running app (using +/- buttons that are implemented aswell). The thing is that the secondary stats should be calculated using the main ones. All the calculations already sit there, f.ex.

var FFGP:Number = (PHSQ* 0.3 + RSPN* 0.5 + WSDM* 0.2);

The display looks like that

addEventListener (Event.ENTER_FRAME, FFGPShow);
function FFGPShow (event:Event){FFGPDisplay.text = String (FFGP);}

In short whenever i raise/lower any of the 3 main skills in-game, the secondary ones remain unchanged and when I change values directly in AS its all calculated correctly.

I was thinking about creating an array for all secondary skills and then refreshing all of them whenever a +/- button is pressed but no idea where to start

One of the forum users suggested using getters and setters to calculate it all dynamically but....

Really wish to continue the project, so all help greatly appreciated
Matt

BeerOclock
11-30-2011, 05:04 PM
One of the forum users suggested using getters and setters to calculate it all dynamically but....


But what?
I like that idea too.

In fact, I'd make a separate stats class.

You can expose all the stats you want as properties.

You can make the GET property of your secondary stats, use the current value of your main stats every time you access the GET, so everything is always up to date.

Definetly the cleanest way to do it that I can think of.

If you dont know what I mean by GET and SET properties, just look it up, its dead simple.