|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
MrGentle How do I cheat? Reputation: 0
Joined: 29 Sep 2015 Posts: 7
|
Posted: Tue Aug 23, 2016 6:12 pm Post subject: Averaging values in a lua table |
|
|
So what i'm trying to do is:
Whenever the player starts a stage, the value of the character object speed is added to a table each tick until the player reaches the end of the stage.
At the end of the stage i want to stop adding stuff to the table, and instead average all the values. I want to output this value to a d3d text container in-game.
The code snippet:
Code: | if asMeter~=nil then asMeter.destroy(); asMeter = nil; end
asMeter=d3dhook_createTextContainer(fontmap,-1,640,"Average speed last run: N/A")
averageSpeed = {}
asTableLoop = 1;
calculateAverage = false
--calculate average speed
--This part of the code runs inside a timer
if (gameMode == 1) then
if(calculateAverage == false) then
calculateAverage = true
end
averageSpeed[asTableLoop] = playerSpeed
asTableLoop = asTableLoop+1
elseif (gameMode == 2) then
if (calculateAverage == true) then
local sum = 0
local ave = 0
local elements = #averageSpeed
for i = 1, elements do
sum = sum + averageSpeed[i]
end
ave = sum / elements
d3dhook_textcontainer_setText(asMeter, [[Average speed last run: ]] .. ave)
asTableLoop = 1;
averageSpeed = {}
calculateAverage = false
end
end |
The current effect:
Regardless of gameState the asMeter text container always displays: "Average speed last run: N/A"
So what am i doing wrong? Would really appreciate it if anyone could point me in the right direction!
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Wed Aug 24, 2016 6:01 am Post subject: |
|
|
Check PlayerSpeed, or verify that each input inside your table is actually is a number, I believe your table contains bad inputs or somehow the calculation corrupts the desired output.
Try to print all table information (for key,value in pairs..), post it here, and also how do you set playerSpeed?
_________________
|
|
Back to top |
|
|
MrGentle How do I cheat? Reputation: 0
Joined: 29 Sep 2015 Posts: 7
|
Posted: Wed Aug 24, 2016 8:15 am Post subject: |
|
|
Thanks DaSpamer, but i figured it out! gameMode was stored as a string for some reason, so i had to do a tonumber operation on it.
i was already using playerSpeed for several other functions, so that couldn't have been the problem. I should've been more specific in my explanation.
You can close this thread if you want to!
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|