Posted: Sun Mar 17, 2019 3:33 am Post subject: How to find out the sum of values and improve the code?
How to find out the sum of values and improve the code? Character can equip 15 items with 6 stats parameters. The following code works, but it is too big.
Anything you call more than once can be placed inside a function,
You could place matefftable[...] inside a function and only supply readbytes address.
Code:
function getV(rb,index)
return matefftable[eqmattable[readBytes(rb)]][index or 1]
end
S1 = getV(0x009E8664)
And since you hold 16 variables and offsets are pretty much static you could do
Code:
s={} -- similar to var names but you access it via table s[1],s[2]...s[15]
sum = 0
for i=0,14 do
local v = getV(0x009E8664+i*4)
s[i+1]= v
-- _G['s'..tostring(i+1)] = v -- a dirty way to set global variables ... s1,s2....s15 like in your example... better use tables as it much better than accessing global scope.
sum = sum + v
end
labelName = sum
Hope it helps, used phone so its not so clean but gives you the idea _________________
I'm rusty and getting older, help me re-learn lua.
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