Eureka! WoWPedometer!

Eureka!  WoWPedometer

WoWPedometer is finally ready to be released into the wild! You can download your copy at http://5h0cktr00px0rz.org/?q=node/94. Some people have even suggested I make the AddOn available at Curse Gaming. I think they are silly but if I can, I will, just for the giggles. ;)

I made some changes to the final code in order to make everything work as I had originally envisioned it. One change I made was to...

WoWPedometer_UpdateInterval = 0.1

...where previously the update interval was 1. A one second interval made for an awkward flow, causing the calculated totals to jump up in value in a "unnatural" manner. 0.1 seconds gave the AddOn a feel that was more akin to watching the odometer on your car.

I also made some changes to the way the totals were calculated. Rather then trying to do everything on one line of code, I broke things up a bit. The new OnUpdate function looks like this...

function WoWPedometer_OnUpdate(self, elapsed)
self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed
if self.TimeSinceLastUpdate > WoWPedometer_UpdateInterval then
local speed = GetUnitSpeed("PLAYER") -- the characters speed in yards/second. It is passed this through the GetUnitSpeed("UId") API
if speed > 0 then
local distance = calculateDistance(speed, self.TimeSinceLastUpdate)
total_distance = total_distance + distance
local steps = calculateTotalSteps(distance, calculateStepRate(speed, calculateSpeedModifier(speed)))
total_steps = total_steps + steps
calories = calculateTotalCaloriesBurned(calculateCaloriesBurnRate(calculateSpeedModifier(speed)), self.TimeSinceLastUpdate)
total_calories = total_calories + calories
WoWPedometer_UpdateText()
end
WoWPedometer_UpdateText()
self.TimeSinceLastUpdate = 0
end
end

...where each calculation now has an interval calculation as well as a totaling calculation. This seemed to clean things up enough that the calculations were not getting too confusing to follow. It also helped with the debugging code so that I could find out exactly where my code was faulty.

After I got everything working as intended, I went back and modified some of the variable names in the functions in order to make them more generic...

-- This function calculates the distance covered at a given speed and time interval. It returns the distance value.
-- distance - the distance value in yards as determined by the speed in yards/second multiplied by the time interval.
function calculateDistance(speed, time_interval)
local distance = speed * time_interval
WoWPedometer_UpdateText()
return distance
end

...and...

-- This function calculates the fraction of the current speed as compared to a standard speed, 7 yards per second. It is passed a speed value and it returns the modifier.
-- standard_speed - a standard speed in yards per second.
-- modifier - a variable which is the "decimal percentage" of the difference between the actual speed and the standard speed
function calculateSpeedModifier(speed)
local standard_speed = 7
local modifier = speed / standard_speed
return modifier
end

...and...

-- This function calculates the steps per yard at a given speed and a speed_modifier. It returns a rate as steps per yard.
-- rate - the rate at which a player character travels in steps per yard
function calculateStepRate(speed, speed_modifier)
local rate = speed / (speed * speed_modifier)
return rate
end

...and...

function calculateTotalSteps(distance, step_rate)
local steps = distance * step_rate
WoWPedometer_UpdateText()
return steps
end

...and..

-- This function calculates the calorie burn rate as determined by the standard calorie burn rate of 0.39 calories burned per unit of time (seconds) traveled multiplied a modifier (to account for changes in travel speed).
-- calorie_burn_rate_standard - a constant variable of 0.39, the aproximate rate at which an avarage human being will burn calories if running at 7 yards per second
-- calorie_burn_rate_modifier - a modifier which accounts for the changes in players traveling speed, as determined by the speed modifier
-- calorie_burn_rate - the theoretical rate at which the player would burn calories
function calculateCaloriesBurnRate(speed_modifier)
local calorie_burn_rate_standard = 0.39
local calorie_burn_rate_modifier = speed_modifier
local calorie_burn_rate = calorie_burn_rate_standard * calorie_burn_rate_modifier
return calorie_burn_rate
end

...and last but not least...

-- This function calculates the calories burned at a given rate and time interval.It returns the calories burned in calories.
-- calories_burned - the theoretical calories burned by the player
function calculateTotalCaloriesBurned(rate, time_interval)
local calories_burned = rate * time_interval
-- WoWPedometer_UpdateText()
return calories_burned
end

Note to self, the WoWPedometer_UpdateText() function call can most probably removed from these functions. ;)

So now that I am done, what does that mean? Well, I've written my first functional AddOn from scratch (actually, and sadly after so much educational expenses, my first program, period). Now that I have some confidence in myself, I would now like to tackle more complicated (and useful) AddOns. A guild alliance system of some sorts is my first idea. What does the future hold for WoWPedometer? In reality, probably not much, though, it would be nice to go back and tweak the AddOn. Flying, for example, is not discounted from the calculations in the current version and I'd also like to see a reset button of some sort that would allow the user to reinitialize the values back to zero. Whether or not this will happen, only time will tell. Perhaps if my friends bug me enough for such things, I will do so on their behalf. ;)

Comments

@ Curse.com

I was able to upload the AddOn to Curse Gaming. You can see the project page at http://wow.curse.com/downloads/wow-addons/details/wowpedometer.aspx. :)