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

Something setting a variable to true

Started by flaghacker, 23 April 2014 - 06:40 PM
flaghacker #1
Posted 23 April 2014 - 08:40 PM
I want to make a program that checks 2 resonant energy cells (thermal expansion) using the integration from openperipherals and turns my reactor (big reactors) on and off.
I have successfully made a program that does all this.

This is what I currently have:
https://www.dropbox....%2021.18.39.png
http://pastebin.com/2DjWvL49

It checks if the power level in the energy cell that drains the last (left in the picture) is below 10%, and then turns on the redstone signal. If the power raises above 90% in the other cell (meaning that both are nearly full) it disables the redstone signal, and vice versa. The variable "mode" is crucial to this system, because it allows the program to toggle like a flip-flop.

Now I want to make a modification that allows the program to save it's current mode into a file and reuse it when the computer reboots.
http://pastebin.com/UucRgcYs

But for some reason something keeps setting mode to true, and I can't find the reason.
Eg:
I just manually changed the mode file to false, and I reboot the computer:
https://www.dropbox....%2021.41.42.png

There is no reason for it to become true!
Anyone knows what's going on?
Lyqyd #2
Posted 23 April 2014 - 09:21 PM
The only time your toboolean function would return false would be if you passed it nil or a genuine boolean false. Any other value, including "false", will return true. You should use a better toboolean function to convert "true" and "false" to booleans:


function toboolean(str)
  return str == "true"
end
flaghacker #3
Posted 23 April 2014 - 10:17 PM
Thanks!
flaghacker #4
Posted 24 April 2014 - 03:45 PM
I changed the toBoolean function to:

function toBoolean(data)
	return data == "true" or data = true
end
That was messing up a little bit in my code, because i run that function every loop.

–EDIT–

Wait, that doesn't work! What? It says:

bion:339: [string "startup"]:35: 'end' expected (to close 'function' at line 34)

My code lines:

34   function toBoolean(data)
35	   return data == "true" or data = true
36   end

–EDIT 2–
Damm I see, simple syntax error, it's 2 '=' signs…

Weird error message…
Edited on 24 April 2014 - 01:51 PM