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

Greg's SG Craft question

Started by Telnarion, 12 November 2014 - 07:59 PM
Telnarion #1
Posted 12 November 2014 - 08:59 PM
Hello everyone

i don't know how i can use the events from SG craft.
I hope anyone can help me and show me a little example.

sgDialIn, source, remote address
sgDialOut, source, remote address
sgChevronEngaged, source, chevron number, symbol
sgStargateStateChange, source, new state, old state
sgIrisStateChange, source, new state, old state

thanks =)
Bomb Bloke #2
Posted 12 November 2014 - 10:57 PM
Are you having trouble with these events, or events in general?

I guess start here.
Telnarion #3
Posted 12 November 2014 - 11:25 PM
hmm… i think e little bit booth…

is that correct? :

event == sgDialIn(stargate_1,sg.remoteAddress())

I do not know how I use the command "sgDialIn" or other one
valithor #4
Posted 13 November 2014 - 12:34 AM
hmm… i think e little bit booth…

is that correct? :

event == sgDialIn(stargate_1,sg.remoteAddress())

I do not know how I use the command "sgDialIn" or other one

Well when setting values you would use a single =, 2 is used for checking to see if two things equal the same thing.

These are events not functions. Events are fired based upon things such as a key being pressed or a mouse being clicked on the screen.

sgDialIn, source, remote address - An incoming connection has been initiated

sgDialOut, source, remote address - An outgoing connection has been initiated

sgChevronEngaged, source, chevron number, symbo - A chevron has been engaged during dialling

sgStargateStateChange, source, new state, old state - State of stargate has changed

sgIrisStateChange, source, new state, old state - State of iris has changed

sgMessageReceived, source, arg, … - A message was sent from the connected stargate using the sendMessage method



If you wanted to see what/when a event is fired you will want to use event,arg1,arg2,arg3,arg4 = os.pullEvent()
The args will equal the value of what follows the event in the table above respectivly.

edit: Sorry i copied and pasted a table, and when i hit post the format completely messed up.

Link to information about stargate and computercraft http://www.cosc.canterbury.ac.nz/greg.ewing/minecraft/mods/SGCraft/doc/ComputerCraft.html
Edited on 12 November 2014 - 11:38 PM
Telnarion #5
Posted 13 November 2014 - 09:33 AM
OK, thanks i try it =)
Telnarion #6
Posted 13 November 2014 - 06:43 PM
i don't know how i make a event with SG. :/

i hope anyone can help me.
Dragon53535 #7
Posted 13 November 2014 - 07:24 PM

local event = {os.pullEvent()}
if event[1] == "sgDialIn" then
  print( event[2] ) --# The source
  print( event[3] ) --# The remote address.
end
Telnarion #8
Posted 13 November 2014 - 09:09 PM
cool thanks… i copy the code but didn't work..sorry for my ignorance. :/

is my first try with lua…
KingofGamesYami #9
Posted 13 November 2014 - 09:25 PM
Just to clarify things… You don't "make" an event. An event happens when a user does something.

The code Dragon posted waits for a user to dial an address. (or so I assume, since I've never used SG craft)
Telnarion #10
Posted 13 November 2014 - 09:42 PM
sorry, its work..is my fail..i have a problem with my code. i test his code in an other one and it works. thank for help =))
Telnarion #11
Posted 14 November 2014 - 09:16 PM
Hello

I have a new problem…

my code ist not working with two event in one function…


while true do
local event,side,x,y = { os.pullEvent() }
if event[ 1 ] == "monitor_touch" then
if x == 2 and y == 3 then
    kai()
elseif x == 2 and y == 4 then
    nether()
  elseif x == 2 and y == 5 then
	 dark()
   elseif x == 2 and y == 10 then
	  sg.openIris()
   elseif x == 2 and y == 11 then
	  sg.closeIris()
   elseif x == 2 and y == 12 then
	  sg.disconnect()
	  monitor.setCursorPos(14,3)
	  monitor.write("	 ")
	  monitor.setCursorPos(14,4)
	  monitor.write("	 ")
	  monitor.setCursorPos(14,5)
	  monitor.write("	 ")
elseif event[1] == "sgDialIn" then
  print( event[2] ) --# The source
  print( event[3] ) --# The remote address.
    end
   end
  end

thanks for help =)
KingofGamesYami #12
Posted 14 November 2014 - 09:26 PM
You are defining the table "event" as well as declaring "side", "x", and "y" as nil… Try using event[ 2 ] as side, event[ 3 ] as x, etc.
Bomb Bloke #13
Posted 14 November 2014 - 09:37 PM
You also misplaced an end statement - consider cleaning up your indentation.

while true do
	local event = { os.pullEvent() }
	if event[1] == "monitor_touch" and event[3] == 2 then
		if event[4] == 3 then
			kai()
		elseif event[4] == 4 then
			nether()
		elseif event[4] == 5 then
			dark()
		elseif event[4] == 10 then
			sg.openIris()
		elseif event[4] == 11 then
			sg.closeIris()
		elseif event[4] == 12 then
			sg.disconnect()
			monitor.setCursorPos(14,3)
			monitor.write("        ")
			monitor.setCursorPos(14,4)
			monitor.write("        ")
			monitor.setCursorPos(14,5)
			monitor.write("        ")
		end
	elseif event[1] == "sgDialIn" then
		print( event[2] ) --# The source
		print( event[3] ) --# The remote address.
	end
end
Telnarion #14
Posted 15 November 2014 - 04:58 PM
Hey cool man =) thank you very much =) but can you me explain the event, why i don't need the variable declare?

i have an other question, is it possible one position with two different aktion? ehm..example, pos 1 = open door, pos 1 = close door ?
Edited on 15 November 2014 - 04:20 PM
Bomb Bloke #15
Posted 15 November 2014 - 11:33 PM
but can you me explain the event, why i don't need the variable declare?

The "event" variable ends up pointing to a table, which is basically a collection of data. All the data returned by os.pullEvent() goes into that table.

So if you do this:

local myEvent = {os.pullEvent()}

… then if the event that comes back is a monitor touch, then the table will look like this:

myEvent[1] = "monitor_touch"
myEvent[2] = side of the monitor
myEvent[3] = x position of the touch
myEvent[4] = y position of the touch

… but if the event is a timer, then it will look like this:

myEvent[1] = "timer"
myEvent[2] = id number of the timer

… and if the event is a Stargate state change, it might look like this:

myEvent[1] = "sgStargateStateChange"
myEvent[2] = source
myEvent[3] = new state
myEvent[4] = old state

The wiki page for os.pullEvent() shows you the layout for all events you might encounter in vanilla ComputerCraft.

i have an other question, is it possible one position with two different aktion? ehm..example, pos 1 = open door, pos 1 = close door ?

Sorry, not quite sure what you mean by this. Can you show an example of how you think you might code it?
Telnarion #16
Posted 15 November 2014 - 11:52 PM
Ah this is cool, now i think i understand the event code..i hope it :)/>

This is a smal part from the code i have two different commands. One for open and one for close..my question is, can i this make smaller.

Now:
			   
elseif event[4] == 17 then
sg.openIris()
elseif event[4] == 18 then
sg.closeIris()

i would like this:
			   
elseif event[4] == 17 then   <---- First position
sg.openIris()
elseif event[4] == 17 then   <---- Same position how the first
sg.closeIris()
Bomb Bloke #17
Posted 16 November 2014 - 12:21 AM
Assuming the commands here are accurate, you should be able to do something like this:

elseif event[4] == 17 then
  local state = sg.irisState()

  if state == "Closed" or state == "Closing" then
    sg.openIris()
  elseif state == "Open" or state == "Opening" then
    sg.closeIris()
  end
elseif ...
Telnarion #18
Posted 16 November 2014 - 10:02 AM
yeah, thank you very much =)))