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

Issue with a reactor control system (Using touchpoint)

Started by TheOnlyDroid, 19 June 2015 - 07:33 PM
TheOnlyDroid #1
Posted 19 June 2015 - 09:33 PM
To be quite honest the title says it all (but I know what its like, when people say it); Basically I'm having an issue with a BigReactors 'control' system that I'm doing, each time I open the program I get 'touchpoint:128: attempt to index ? (a nil value)'; I've tried multiple variants to change the text in the 'button' or so its called in the API; I did get it working before, just the way I did wasn't very 'Optimized' in the way of getting the current text.




os.loadAPI("touchpoint")
local t = touchpoint.new("left")
m = peripheral.wrap("monitor_0")

local LastTickEnergyLevel = 0

t:add("Start", function() bFunc0() end, 1, 1, 8, 2, colors.lime, colors.lightGray)
t:add("Stop", function() bFunc1() end, 1, 4, 8, 5, colors.red, colors.lightGray)
t:add("Dump", function() bFunc2() end, 1, 7, 8, 8, colors.lightBlue, colors.lightGray)
t:add("Rods -", function() bFunc3() end, 1, 10, 8, 11, colors.yellow, colors.lightGray)
t:add("Rods +", function() bFunc4() end, 1, 13, 8, 14, colors.orange, colors.lightGray)
t:add("Reboot", function() RebootSys() end, 1, 16, 8, 17, colors.lightBlue, colors.lightGray)
t:add("Reactor Active:", "R_Active", 11, 1, 27, 1, colors.black, colors.black)
t:add("Reactor Energy:", "R_SEnergy", 11, 2, 27, 2, colors.black, colors.black)
t:add("Fuel Temp:", "R_FuelTmp", 11, 3, 22, 3, colors.black, colors.black)
t:add("Case Temp:", "R_CaseTmp", 11, 4, 22, 4, colors.black, colors.black)
t:add("-----------------------------", nil, 11, 5, 41, 5, colors.black, colors.black)
t:add("Radiated Fuel:", "R_FRadiated", 11, 6, 26, 6, colors.black, colors.black)
t:add("Unradiated Fuel:", "R_URadiated", 11, 7, 28, 7, colors.black, colors.black)
t:add("Energy (p/tick):", "R_EnergyTick", 11, 8, 28, 8, colors.black, colors.black)

function RebootSys()
	m.clear()
	os.reboot()
end

while true do

	-- Update variables, and save required information --
	local reactor = peripheral.wrap("BigReactors-Reactor_0")
	local reactor_active_string = ""

	if reactor.getActive() == true then
	  t:rename("R_Active",  "Reactor Active: Yes")
	  else
	  t:rename("R_Active", "Reactor Active: No")
	end



	t:draw()
	local event, p1 = t:handleEvents(os.pullEvent())
	if event == "button_click" then
		if t.buttonList[p1].func ~= nil then
			t.buttonList[p1].func()
		end
		t:flash(p1)
	end
end


Lyqyd #2
Posted 20 June 2015 - 04:25 AM
When calling the rename function, you have to pass in the current name of the button. The reactor active button starts out with the name "Reactor Active:", but you're trying to rename it as if it were named "R_Active". The "R_Active" you're passing to the add function when creating that button is in the function parameter slot, not the name slot, so Touchpoint of course cannot figure out which button you're trying to rename. I should probably provide a more useful error there.
TheOnlyDroid #3
Posted 20 June 2015 - 01:50 PM
When calling the rename function, you have to pass in the current name of the button. The reactor active button starts out with the name "Reactor Active:", but you're trying to rename it as if it were named "R_Active". The "R_Active" you're passing to the add function when creating that button is in the function parameter slot, not the name slot, so Touchpoint of course cannot figure out which button you're trying to rename. I should probably provide a more useful error there.

Indeed, It would be nice to have 'Named' objects as-sush per my code, that way you don't need to constantly build strings based on the value you just need as I put "R_Active"; But non-the-less, I'll try and find a way around it xD.
Lyqyd #4
Posted 20 June 2015 - 04:53 PM
Well, there already is a way around it. You can name the button whatever you like, but then use the alternate way of renaming buttons wherein you provide a table of lines of text for the button appearance, and also a label entry in the table that will be the new "name" of the button. With this way, you'd originally name the button "R_Active", then immediately rename it to change the appearance, but keep the name "R_Active". Also note that you'll need to make your buttons wider, as at least your R_Active button isn't wide enough to accomodate the "Yes" or "No" you're wanting to add to it, it's only wide enough to accomodate the original text label without the "Yes" or "No".
TheOnlyDroid #5
Posted 22 June 2015 - 03:08 AM
Well, there already is a way around it. You can name the button whatever you like, but then use the alternate way of renaming buttons wherein you provide a table of lines of text for the button appearance, and also a label entry in the table that will be the new "name" of the button. With this way, you'd originally name the button "R_Active", then immediately rename it to change the appearance, but keep the name "R_Active". Also note that you'll need to make your buttons wider, as at least your R_Active button isn't wide enough to accomodate the "Yes" or "No" you're wanting to add to it, it's only wide enough to accomodate the original text label without the "Yes" or "No".

I've decided to go the route of using the Bedrock GUI Framework; Mainly due to the fact that it supports what I need; And what I may need in the future, its not that Touchpoint isn't good, in fact it's amazing.. It just doesn't support things that make it easier to handle such as text.


I've managed to throw this togeather in two hours, mainly due to the mass amount of Re-Positioning I've done, using 'Rednet' to grab information; serialize it and then un-serialize it (So I can use it on Portable Computers too):