http://pastebin.com/C8QszcsH
helps appreciated.
Mistamadd001
percent = math.floor(arg1/arg2*100)
or if you want to the second decimal place
percent = math.floor(arg1/arg2*10000)/100
The one you are using would give 100% if the full, however, when it should be 10% it would read as 1000%, 1% would be 10000% and zero would end up being infI am not sure if this is the cause of whatever error you are getting, but change your percentage calculation toor if you want to the second decimal placepercent = math.floor(arg1/arg2*100)
The one you are using would give 100% if the full, however, when it should be 10% it would read as 1000%, 1% would be 10000% and zero would end up being infpercent = math.floor(arg1/arg2*10000)/100
No, what he has will give you 100 when full, 0 if not. math.floor( 0.99 ) = 0
percent = math.floor(math.floor(arg2/arg1)*100)
Check for division by zero (if arg == 0 then percent = 0 else your code end). I don't know if that's what causes your error, but it will eventually if you don't handle this.term.write(currentFuel..'mB / '..maxFuel..'mB = '..percentage(currentFuel,maxFuel)..'%')
tickPower = reactor.getEnergyProducedLastTick
term.write(currentPower..'RF / '..maxPower..'RF = '..percentage(currentPower,maxPower)..'% '..tickPower..'RF/t')
Line 139:term.write(currentFuel..'mB / '..maxFuel..'mB = '..percentage(currentFuel,maxFuel)..'%')
Per the error, you're trying to concatenate a string with a function. Only, none of these values are a function…
Reading further up, on line 81 we see:tickPower = reactor.getEnergyProducedLastTick
Since you forgot the brackets, you're not setting "tickPower" to the result of calling reactor.getEnergyProducedLastTick(), you're setting it to the actual function reactor.getEnergyProducedLastTick points to.
Thus on line 135:term.write(currentPower..'RF / '..maxPower..'RF = '..percentage(currentPower,maxPower)..'% '..tickPower..'RF/t')
… you produce the error.
Really, though, you don't want to use the tickPower variable at all. When you set it to the result of reactor.getEnergyProducedLastTick(), it'll stay on that value until you set it to something else - it won't automatically change as time goes by. So ditch the variable and perform the function call directly within the loop, so that you get an up-to-date result on every iteration.
I think the problem with CC is it wont produce any part of a line that has an error in it. If the computer wrote out everything up to the tickPower it would be much easier to see my error.
term.write(tostring(currentPower)..'RF / '..tostring(maxPower)..'RF = '..percentage(currentPower,maxPower)..'% '..tostring(tickPower)..'RF/t')
local prefix = {"","k","M","G","T","P","E","Z","Y"}
local function condenseNum(num)
local counter = 1
while num > 1000 do
counter = counter + 1
num = num / 1000
end
return tostring(math.floor(num*10) / 10)..prefix[counter]
end
term.write(condenseNum(reactor.getEnergyProducedLastTick()).."RF/t")
17,376 --> 17.4k not 17k
or
25,204 --> 25.2k not 25k
or
26,752 --> 26.8k not 27k
I suppose you could do something like this:local prefix = {"","k","M","G","T","P","E","Z","Y"} local function condenseNum(num) local counter = 1 while num > 1000 do counter = counter + 1 num = num / 1000 end return tostring(math.floor(num*10) / 10)..prefix[counter] end
You'd then be able to do something like this:term.write(condenseNum(reactor.getEnergyProducedLastTick()).."RF/t")
Take another look, I ninja'd you with an edit. ;)/>