This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
VirtualBrain's profile picture

Chart problem

Started by VirtualBrain, 16 November 2016 - 03:37 PM
VirtualBrain #1
Posted 16 November 2016 - 04:37 PM
Hello,

I wrote this program http://pastebin.com/vLN0f4hq wich displays a real-time chart of production of a BigReactors reactor.
Here's the problem : http://www.noelshack.com/2016-46-1479313604-2016-11-16-17-25-18.png

The graph is very very strange, and I don't know why because the scale (named 'echelle') is correctly generated.
And if I replace the auto-generate scale by an user input, the graph works well.

Help me please !
Bomb Bloke #2
Posted 20 November 2016 - 05:01 AM
So what's the expected output look like? Knowing what numbers are going in to create that appearance, and how they should appear, would make it a lot easier to help you.

Where is "echelle" supposed to be "generated"? I can see where you assign it a value once (line 98, based on energy production at the time the script was started), but you never seem to update it… Did you maybe mean to assign it new values while the script was running? Or maybe it should be based on the reactor's max output?

If you want to find a single connected reactor but don't know its network number, use peripheral.find():

reac = peripheral.find(typePeripheralReacteur)

Typically you should not need your script to do this in a loop; once per execution is usually sufficient.

You could reduce your Abreger() function a bit with a simple table:

Spoiler
local affix = {"Y", "Z", "E", "P", "T", "G", "M", "K"}

local function Abreger(nb, idp)
	local mult = 10^ (idp or 0)
	
	for i = 1, #vals do
		local bigVal = 1000 ^ (9 - i)
		if nb >= bigVal then return (math.floor(nb / bigVal * mult + 0.5) / mult)..affix[i] end
	end
	
	return tostring(nb)
end