Jump to content




Stargate program won't update screen?


  • You cannot reply to this topic
4 replies to this topic

#1 gametechish

  • Members
  • 47 posts

Posted 11 August 2017 - 05: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!

#2 The Crazy Phoenix

  • Members
  • 136 posts
  • LocationProbably within 2 metres of my laptop.

Posted 11 August 2017 - 05: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.

#3 gametechish

  • Members
  • 47 posts

Posted 11 August 2017 - 05:42 AM

View PostThe Crazy Phoenix, on 11 August 2017 - 05:26 AM, said:

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.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 August 2017 - 06: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().

#5 gametechish

  • Members
  • 47 posts

Posted 11 August 2017 - 12:31 PM

View PostBomb Bloke, on 11 August 2017 - 06:32 AM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users