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

Code questions

Started by Cybertwin1, 16 August 2014 - 12:50 PM
Cybertwin1 #1
Posted 16 August 2014 - 02:50 PM
Hello, I wrote a simple test for a energy monitoring program I have been planning to do, it isn't working the way I think it should… I am pretty sure the logic is ok, I can't see anyting wrong with it

here is the code: http://pastebin.com/aDXLi4rY

From what I understand it should display the energy cells power, updating every second… but it only seems to check once and then not carry on with the while loop. from what I have tested it does hit the sleep() though.

thanks for looking :)/>
RickiHN #2
Posted 16 August 2014 - 02:56 PM
Replace:

energy = cube.getEnergyStored('right')
with:

energy = cube.getEnergyStored('unknown')
RickiHN #3
Posted 16 August 2014 - 03:00 PM
Doh, brainfart…
You need to put:

energy = cube.getEnergyStored('unknown')
inside the while loop, else it will only detect the energy level once before reaching the while loop. You want it to do it continuously every cycle.
Dragon53535 #4
Posted 16 August 2014 - 03:47 PM
I believe it's because you're only grabbing the energy stored once during the entire code and so it's only got one number it knows. try adding

energy = cube.getEnergyStored('right')
inside the while loop. Also it is good practice to make every variable local so that other programs and such cannot use them, you just need to add the word local in front of the one you make first, the rest don't need it because they will see the first think, oooh it's already a local variable, lets stay as one. So you should add it infront of energy, cube, and monitor. Only the ones at the top under vars, all the others are fine and don't matter.
Edited on 16 August 2014 - 01:48 PM
Cybertwin1 #5
Posted 16 August 2014 - 04:47 PM
Ar ha!! that works :P/> How did i not think of that lol. Thanks so much you guys are the best :)/>
Edited on 16 August 2014 - 05:32 PM
Dragon53535 #6
Posted 16 August 2014 - 11:01 PM
No problem, just remember if you're trying to have things update, you need to make sure that they update :P/>