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

Menu won't activate Redstone bundles?

Started by Tassyr, 02 April 2013 - 07:57 PM
Tassyr #1
Posted 02 April 2013 - 09:57 PM
First off, I apologize if this counts as spamming and will delete it if told- it's just that I accidentally set the last post I made as 'finished,' only to find out it wasn't. So I have a program that should let me select an option using up and down arrow keys in combination with the enter key, after a bit of help. So far so good. Then I edited it to put [] around the option selected- and suddenly it broke. Can someone help me? I've been beating my head against this for most of a day.

Spoiler




--Screen/Drawing functions
-----------------------------
w,h = term.getSize()
hW = w/2
hH = h/2  

function centerPrint(y,text)
  term.setCursorPos(w/2 - #text/2, y)
    term.write(text)
end

function drawAt(x,y,text)
 term.setCursorPos(x,y)
write(text)
end

function cleanScreen()
term.clear()
  term.setCursorPos(1,1)
 end


input = 1


function drawArt() 

c = colors.combine(colors.red,colors.black,colors.white,colors.green)
white = false
black = false
green = false
red   = false
rs.setBundledOutput("back", c)

  cleanScreen()
  term.setTextColor(colors.lime)
  term.setBackgroundColor(colors.black) --title and title background color
  print[[

      VAULT-TEC REACTOR MK 4 CONTROL STATION             
          AUTHORIZED PERSONEL  ONLY!                            

]]


 for i = 5,19 do
 term.setBackgroundColor(colors.black) -- MAIN BACKGROUND SPAM COLOR
  drawAt(1,i,"                                                   ")
   term.setBackgroundColor(colors.black)
  end

  if input == nil then
  input = 1
  end

  term.setBackgroundColor(colors.black) -- menu section background
  term.setTextColor(colors.red) -- menu section brackets
   term.setCursorPos(9,(input + 5)
   print("[")
   term.setCursorPos(40,(input + 5))
   print("]")
    term.setBackgroundColor(colors.black)




  options = {
"                              ",
"  ACTIVATE    REACTORS 1 - 3  ",
"  DEACTIVATE  REACTORS 1 - 3  ",
"  ACTIVATE    REACTORS 4 - 6  ",
"  DEACTIVATE  REACTORS 4 - 6  ",
"  ACTIVATE    BREEDER CORE 1  ",
"  DEACTIVATE  BREEDER CORE 1  ",
"  ACTIVATE    BREEDER CORE 2  ",
"  DEACTIVATE  BREEDER CORE 2  ",
"  -EMERGENCY-  CORE SHUTDOWN  ",
"                              ",
}


for i = 1, #options do
term.setBackgroundColor(colors.black) -- options background color
term.setTextColor(colors.blue) -- options text color
  drawAt(10,i + 4,options[i])
 end

 term.setTextColor(colors.red) -- option text color optional
 drawAt(10,14,"  -EMERGENCY-  CORE SHUTDOWN  ")
end




   function events()
   evt, but = os.pullEvent()
     if evt == "key" then

 if but == 208 then --down arrow
 input = input + 1
 if input > 9 then
 input = 9
 end

 elseif but == 200 then --up arrow
 input = input - 1
 if input < 1 then
 input = 1
 end

 elseif but == 28 then --Enter
 if input == 1 then
  c = colors.subtract(c, colors.white)
  rs.setBundledOutput("back",c)
  white = not white


  elseif input == 2 then
  c = colors.combine(c, colors.white)
  rs.setBundledOutput("back",c)
  white = not white


  elseif input == 3 then
  c = colors.subtract(c, colors.black)
  rs.setBundledOutput("back",c)
  black = not black


  elseif input == 4 then
  c = colors.combine(c, colors.black)
  rs.setBundledOutput("back",c)
  black = not black


  elseif input == 5 then
  c = colors.subtract(c, colors.red)
  rs.setBundledOutput("back",c)
  red = not red


  elseif input == 6 then
  c = colors.combine(c, colors.red)
  rs.setBundledOutput("back",c)
  red = not red


  elseif input == 7 then
  c = colors.subtract(c, colors.green)
  rs.setBundledOutput("back",c)
  green = not green


  elseif input == 8 then
  c = colors.combine(c, colors.green)
  rs.setBundledOutput("back", c)
  green = not green


  elseif input == 0 then
  c = colors.combine(colors.green,colors.red,colors.white,colors.black)
  green = false
  red = false
  black = false
  white = false
  rs.setBundledOutput("back", c)
  end

end 
   end
     end

 function main()
    while true do
      cleanScreen()
       drawArt()
     events() --Handles the menu stuff
 end
    end


main()

Bubba #2
Posted 02 April 2013 - 10:22 PM
Specifically, what is not working here? On line 61 you are missing an end parentheses and once you fix that the GUI will work fine. But your title mentions Redstone bundles. Are they not working at all?

Edit:
For clarification, this is the line that was bad:

term.setCursorPos(9,(input + 5) <--Missing that end parentheses there!
Tassyr #3
Posted 02 April 2013 - 10:32 PM
They're not working in the slightest! I select the option, hit enter, and nothing changes- they're supposed to deactivate (so a NOT circuit can turn the reactor on) but they just kinda. Sit there in the on position. Also ch ecking to see if I left that parenthesis in- I had to copy this by hand, since I used up my pastebin limit.

Yeah, that parenthesis is in the original. >.<
Bubba #4
Posted 02 April 2013 - 10:55 PM
They're not working in the slightest! I select the option, hit enter, and nothing changes- they're supposed to deactivate (so a NOT circuit can turn the reactor on) but they just kinda. Sit there in the on position. Also ch ecking to see if I left that parenthesis in- I had to copy this by hand, since I used up my pastebin limit.

Ouch! That sucks.

But your problems lies in the fact that you reset the c variable every time you call the drawArt() function, meaning that even though you set the bundled output to a new value it will revert back immediately. Put the c variable declaration outside of the drawArt() function and then see how it works.

Note: I can't actually test things right now because the computer I'm on now can't really handle minecraft well. But I'm almost absolutely positive this is your only problem in terms of the output not changing. Your code might contain other bugs though.
Tassyr #5
Posted 02 April 2013 - 11:09 PM
About to test it. This is sort of a giant mashup code- Someone else showed me how to make the menu, I decided I knew what I was doing and reordered the menu… yeah. XD Testing now.
Tassyr #6
Posted 02 April 2013 - 11:16 PM
Well, I removed the block of text about c- that was initially meant to be what happened on startup, and I need to figure out where the heck I put it now- because without it I get an odd error. "colors:30: too few arguments."

See, what it's meant to do is set red/black/white/green to 'on,' and then set the related variables to 'false' for the first time.
Bubba #7
Posted 02 April 2013 - 11:27 PM
Well, I removed the block of text about c- that was initially meant to be what happened on startup, and I need to figure out where the heck I put it now- because without it I get an odd error. "colors:30: too few arguments."

See, what it's meant to do is set red/black/white/green to 'on,' and then set the related variables to 'false' for the first time.

Did you completely remove it? You just need to move the declaration outside of the function. I would put it into the first few lines where it has this:

w,h = term.getSize()
hW = w/2
hH = h/2
--Add it in here, keeping everything about the declaration the same. You're only moving it, not really changing anything.

Edit: Here's the full code in case you want it.
Spoiler




--Screen/Drawing functions
-----------------------------
w,h = term.getSize()
hW = w/2
hH = h/2
c = colors.combine(colors.red,colors.black,colors.white,colors.green)

function centerPrint(y,text)
  term.setCursorPos(w/2 - #text/2, y)
	term.write(text)
end

function drawAt(x,y,text)
term.setCursorPos(x,y)
write(text)
end

function cleanScreen()
term.clear()
  term.setCursorPos(1,1)
end


input = 1


function drawArt()



white = false
black = false
green = false
red   = false

rs.setBundledOutput("back", c)

  cleanScreen()
  term.setTextColor(colors.lime)
  term.setBackgroundColor(colors.black) --title and title background color
  print[[

	  VAULT-TEC REACTOR MK 4 CONTROL STATION
		  AUTHORIZED PERSONEL  ONLY!

]]


for i = 5,19 do
term.setBackgroundColor(colors.black) -- MAIN BACKGROUND SPAM COLOR
  drawAt(1,i,"												   ")
   term.setBackgroundColor(colors.black)
  end

  if input == nil then
  input = 1
  end

  term.setBackgroundColor(colors.black) -- menu section background
  term.setTextColor(colors.red) -- menu section brackets
   term.setCursorPos(9,(input + 5))
   print("[")
   term.setCursorPos(40,(input + 5))
   print("]")
	term.setBackgroundColor(colors.black)




  options = {
"							  ",
"  ACTIVATE	REACTORS 1 - 3  ",
"  DEACTIVATE  REACTORS 1 - 3  ",
"  ACTIVATE	REACTORS 4 - 6  ",
"  DEACTIVATE  REACTORS 4 - 6  ",
"  ACTIVATE	BREEDER CORE 1  ",
"  DEACTIVATE  BREEDER CORE 1  ",
"  ACTIVATE	BREEDER CORE 2  ",
"  DEACTIVATE  BREEDER CORE 2  ",
"  -EMERGENCY-  CORE SHUTDOWN  ",
"							  ",
}


for i = 1, #options do
term.setBackgroundColor(colors.black) -- options background color
term.setTextColor(colors.blue) -- options text color
  drawAt(10,i + 4,options[i])
end

term.setTextColor(colors.red) -- option text color optional
drawAt(10,14,"  -EMERGENCY-  CORE SHUTDOWN  ")
end




   function events()
   evt, but = os.pullEvent()
	 if evt == "key" then

		 if but == 208 then --down arrow
		 input = input + 1
		 if input > 9 then
		 input = 9
		 end

		 elseif but == 200 then --up arrow
		 input = input - 1
		 if input < 1 then
		 input = 1
		 end

		 elseif but == 28 then --Enter
		 if input == 1 then
		  c = colors.subtract(c, colors.white)
		  rs.setBundledOutput("back",c)
		  white = not white


		  elseif input == 2 then
		  c = colors.combine(c, colors.white)
		  rs.setBundledOutput("back",c)
		  white = not white


		  elseif input == 3 then
		  c = colors.subtract(c, colors.black)
		  rs.setBundledOutput("back",c)
		  black = not black


		  elseif input == 4 then
		  c = colors.combine(c, colors.black)
		  rs.setBundledOutput("back",c)
		  black = not black


		  elseif input == 5 then
		  c = colors.subtract(c, colors.red)
		  rs.setBundledOutput("back",c)
		  red = not red


		  elseif input == 6 then
		  c = colors.combine(c, colors.red)
		  rs.setBundledOutput("back",c)
		  red = not red


		  elseif input == 7 then
		  c = colors.subtract(c, colors.green)
		  rs.setBundledOutput("back",c)
		  green = not green


		  elseif input == 8 then
		  c = colors.combine(c, colors.green)
		  rs.setBundledOutput("back", c)
		  green = not green


		  elseif input == 0 then
		  c = colors.combine(colors.green,colors.red,colors.white,colors.black)
		  green = false
		  red = false
		  black = false
		  white = false
		  rs.setBundledOutput("back", c)
		  end

		end
		   end
	 end

function main()
	while true do
	  cleanScreen()
	   drawArt()
	 events() --Handles the menu stuff
	 term.clear() term.setCursorPos(1,1)
	 term.write("C: "..c)
	 os.pullEvent()
end
	end


main()


Also you have some unecessary variables in there (I never actually see you use the color variables such as white = false and such other than to change the value). But get the program working first and then go back and see if there's anything you don't use.
Tassyr #8
Posted 02 April 2013 - 11:31 PM
You are a genius and all sorts of wonderful things should happen to you! (Hey, it's 2:30 am. That's about as eloquent I can get- but I AM excited and grateful. You've FIXED it! :D/>)
Bubba #9
Posted 03 April 2013 - 04:12 AM
You are a genius and all sorts of wonderful things should happen to you! (Hey, it's 2:30 am. That's about as eloquent I can get- but I AM excited and grateful. You've FIXED it! :D/>)

Lol well I'm no genius but thanks for the praise :)/> Glad I could help.