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

Stargate program won't update screen?

Started by gametechish, 11 August 2017 - 04:21 AM
gametechish #1
Posted 11 August 2017 - 06:21 AM
I'm working on a program to dial other stargates with mouse events. The problem is now that it won't update the screen until you click somewhere. Please help me?

Here is my code:


sg = peripheral.find("stargate")
laddress = sg.localAddress()
term.clear()
term.setTextColor(colors.lime)
term.setCursorPos(1,1)
o1 = {"Dawson's", "ELO3-VCC-D5"}
o2 = {"Outlying", "ALFO-VR0-SZ"}
o3 = {"Logan", "PGG2-2JL-53"}
o4 = {"Moon", "MLL0-1LI-LP"}
o5 = {"Mars", "ALDQ-TN0-7A"}
o6 = {"Spawn", "BFWG-F9G-8Q"}
print("Local Stargate: "..laddress.."		   ")
while true do
  local event, button, x, y = os.pullEvent("mouse_click")
  local sstate = sg.stargateState()
  local istate = sg.irisState()
  local raddress = sg.remoteAddress()
	
  term.setCursorPos(1,2)
  print("Connected Stargate: "..raddress.."		  ")

  term.setCursorPos(1,3)
  print("Stargate State: "..sstate.."		   ")
  
  term.setCursorPos(1,4)
  print("Iris State: "..istate.."		  ")

  term.setCursorPos(1,6)
  print(o1[1]..": "..o1[2])

  term.setCursorPos(1,7)
  print(o2[1]..": "..o2[2])

  term.setCursorPos(1,8)
  print(o3[1]..": "..o3[2])

  term.setCursorPos(1,9)
  print(o4[1]..": "..o4[2])

  term.setCursorPos(1,10)
  print(o5[1]..": "..o5[2])

  term.setCursorPos(1,11)
  print(o6[1]..": "..o6[2])

  term.setCursorPos(1,13)
  if istate == "Closed" then
	print("Open Iris ")
  else
	print("Close Iris")
  end

  term.setCursorPos(1,14)
  print("Disconnect Stargate")
  if y == 6 then
	sg.dial(o1[2])
  elseif y == 7 then
	sg.dial(o2[2])
  elseif y == 8 then
	sg.dial(o3[2])
  elseif y == 9 then
	sg.dial(o4[2])
  elseif y == 10 then
	sg.dial(o5[2])
  elseif y == 11 then
	sg.dial(o6[2])
  elseif y == 13 then
	if istate == "Closed" then
	  sg.openIris()
	else
	  sg.closeIris()
	end
  elseif y == 14 then
	sg.disconnect()
  end
  sleep(0.1)
end

Thank you in advance!
The Crazy Phoenix #2
Posted 11 August 2017 - 06:26 AM
You're pulling the mouse_click event before writing to the screen. Os.pullEvent doesn't return until it pulls at an event.
Move your os.pullEvent to just before the "if y == 6 then" line.

Sleep(0.1) is also unnecessary because os.pullEvent will yield the program.
gametechish #3
Posted 11 August 2017 - 06:42 AM
You're pulling the mouse_click event before writing to the screen. Os.pullEvent doesn't return until it pulls at an event.
Move your os.pullEvent to just before the "if y == 6 then" line.

Sleep(0.1) is also unnecessary because os.pullEvent will yield the program.

ok I did that but it still only updates when I click on the screen. It doesn't display the changes in the stargate or anything until I click the screen again.
Bomb Bloke #4
Posted 11 August 2017 - 07:32 AM
It's possible the gate generates an event when it "changes", in which case removing the "mouse_click" filter from your os.pullEvent() call would let it return when such an event occurs (you'd instead move the "mouse_click" check into your "if" blocks).

If the gate doesn't generate events, then you can produce some yourself using os.startTimer().
gametechish #5
Posted 11 August 2017 - 01:31 PM
It's possible the gate generates an event when it "changes", in which case removing the "mouse_click" filter from your os.pullEvent() call would let it return when such an event occurs (you'd instead move the "mouse_click" check into your "if" blocks).

If the gate doesn't generate events, then you can produce some yourself using os.startTimer().
\

THANK YOU! THAT WORKED FLAWLESSLY!