Community Forum

Driven Distance

Forum Overview >> Scripting

CategoryScripting
Created02.03.2011 01:06


Timbertaz (timbertaz) 02.03.2011 01:18
Ive been trying to get the driven distance in to show on screen without success so i hope to get some help.

In steerable.lua i found this
g_currentMission.missionStats.traveledDistanceTotal = g_currentMission.missionStats.traveledDistanceTotal + self.lastMovedDistance*0.001; -- convert to km

So i assume self.lastMovedDistance is the distance driven
but when i print it.. print(self.lastMovedDistance*0.001);
It seems to give me pretty much numbers..it doesnt make sense to me.
What am i missing ?

Thomas H. (Patar) 02.03.2011 19:46
You must add (+) your "self.lastMovedDistance*0.001" to an own variable like that:

load:
self.traveledDistance = 0;

update:
self.traveledDistance = self.traveledDistance + self.lastMovedDistance*0.001
print(self.traveledDistance)

Stefan Geiger - GIANTS Software 14.03.2011 11:16
self.lastMovedDistance only stores the distance traveled since the last frame. So this normally is only a few millimeters.
As Thomas already wrote, you thus need to accumulate this value every frame to get a total traveled distance.


Note: Log in to post. Create a new account here.