Jump to content

Info Menu


Reece C.
 Share

Recommended Posts

Some of you may have read my previous post. I have a facility, with many functions. I wish to know what is going on.

So I have computers posted at each process in the facility, and they tell the main computer what state that process is in.

an example:

Computer 1 (it is posted at power generation.)

rednet.open("left")

while true do

shell.run("clear")

if rs.getInput ("back") then

      rednet.send(21,"Engins: ON")

else

    rednet.send(21,"Engins: OFF")

end

os.pullEvent("redstone")

end

 

And the main computer receives this and displays it on a monitor.

 


rednet.open("top")

while true do

id,EngStatus = rednet.receive()

mon = peripheral.wrap("back")

mon.clear()

mon.setCursorPos(5,5)

mon.write(EngStatus)

end

Sorry no spoilers.

125nax4.png

29zto9z.png

But obviously I have a very large monitor, to show lots of statistics. But I am up agenst a road block. Because I can only display one thing at a time. When new info comes in it replaces what is already on the screen.

Also, using the "setCursorPos" is universal, and not just for one piece of text.

I need to be able to show many statistics, in different places on the monitor, that, of course, will be changing all the time.

I have looked at menu tutorials, but that isn't what I needed. Can someone help me?

And if you need more information about my facility to get a better idea of how to help, please let me know.

Thanks.

PS: If anyone has a code(s) for something like this, please feel free to post them here. It may be all I need, because I can use it as a sort of template, and elaborate on it.

Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

look, ill start by saying that i dont do much programming but i know a little.

what i believe you need is a "function"

set up a function for everything you want to show in that monitor, then add another function called Draw or Whatever.

once you're done with all the functions start with the main program, the one that will request all the computers for status and then at the end call for the Draw() function using all the info stored.

Edit: my post was too ambiguous or W/E ill explain a little more.

Function getEngineStatus()

Code to get the status and store it in a variable goes here

end

and one more function for each data you want to represent, or maybe all in one. after that you start the program telling it to actually call those functions and store the values as you see fit. after that tell it to display each value at a specific coordinate to make sure that each one lines up as you want.

basically, the code you showed us would be the function for Engine status.... some other pc would give you the status for the fuel tanks, the current heat level, the amount of mobs in an area etc etc.

Link to comment
Share on other sites

Doing this with CC sadly isn't very straight forward. The direction you're going to want to go is os.pullEvent and it gets pretty dicey from there on out. Just theorizing you'd want to set up a loop with an if conditional for rednet events (if one exists I don't have time to do a full researched answer :D), have it keep track of state (engines are on or off, hot tub is on or off, etc) and display it's state on screen.

Link to comment
Share on other sites

engine_state = false

mon = peripheral.wrap("back")

do while true

	id, message = os.pullEvent("rednet_message")

	if id == 21 then

		if message == "engines on" then

			engine_state = true

		elseif message == "engines off" then

			engine_state = false

		end

	end

	

	mon.clear()

	mon.setCursorPos(5,5)

	if engine_state == true then

		mon.write("Engines: On")

	else

		mon.write("Engines: Off")

	end

end

There that may or may not work as is, but that should illustrate what you'll have to do. os.pullEvent will wait for a rednet_message, react if it's a message it's looking for and updates it's display afterward.

Link to comment
Share on other sites

only a minor typo, you wrote "do while true" instead of "while true do." Also you forgot to add "rednet.open("side") at the top.

I fixed those, and changed the message that the computer sends to correspond with the code. But all it prints on the screen is "Engines: Off" And it does not change. So either it could mean that it is not recognizing or getting the message from the other computer, or it is but something in the code is wrong.

Here is a template for message code. Do we have to include event and distance?

while true do

event, senderId, message, distance = os.pullEvent("rednet_message")

if senderId == 5 then

  print("Got a message from the boss saying: "..message)

end

end

Also, at the top of the code you declared something

"engine_state = false" I have this odd feeling there is supposed to be something more in that declaration. Just guessing.

It might also be because the computer sending the message only sends it once, not continuously. If I removed the "shell.run("clear")" from the sender code would it work?

BTW thanks for the code, now were getting somewhere. :P

Link to comment
Share on other sites

Does the same go for wireless modems? That is what I am using.

As I understand it, the ComputerCraft Wireless RedNet allows computers to broadcast messages to eachother, and the Wired modems/cables function in the same manner.

The MineFactory Reloaded RedNet cables function like RedPower 2 Bundled cables, and ComputerCraft includes an API to access all 16 channels of the cables through 1 connection.

So essentially I'm saying it would be easiest to use analog wired redstone cables as opposed to Computercraft networking. That's how I'd do it.

Link to comment
Share on other sites

BTW thanks for the code, now were getting somewhere. :P

Not bad for pulling code out of my rear huh? Perhaps if you change "engine_state = false" to "local engine_state = false." The local keyword effects variable scope which may be the problem here. The other issue is that the computer sending the message should send the same messages that the computer receiving is looking for. I used somewhat generic messages in my code. It should match what your sending.

Here is a template for message code. Do we have to include event and distance?

while true do

event, senderId, message, distance = os.pullEvent("rednet_message")

if senderId == 5 then

  print("Got a message from the boss saying: "..message)

end

end

The event is needed since that's always the first one returned (I missed that in my code.) Distance is last and it is safe to omit it.

Link to comment
Share on other sites

the line

event, senderId, message, distance = os.pullEvent("rednet_message")

is assigning the 5 possible return values from os.pullEvent to that list of variables. Event is always the first value returned but we don't have to actually do anything with it. Event would be filled with what type of event has fired in this case it would always hold "rednet_message" since with os.pullEvent("rednet_message") you're limiting to only rednet_message events. If you were doing things like monitor touch screen or keyboard input the event value would be different and you'd want to check what event holds. In this case as long as you have it in the line above, a value gets assigned to it that you don't have to do anything further with.

Link to comment
Share on other sites

So in short I don't have to change anything about these codes. So here they are. I went over them, and I can't see anything wrong. It looks fine to me.

But here they are, maybe you or someone can find the issue.

Sender Code: (computer attached to engines)

rednet.open("left")

while true do

shell.run("clear")

if rs.getInput ("back") then

      rednet.send(21,"engines on")

else

    rednet.send(21,"engines off")

end

os.pullEvent("redstone")

end

 

Receiver code: (main computer with monitor)


rednet.open("top")

local engine_state = false

mon = peripheral.wrap("back")

while true do

    id, message = os.pullEvent("rednet_message")

    if id == 17 then

        if message == "engines on" then

            engine_state = true

        elseif message == "engines off" then

            engine_state = false

        end

    end

 

    mon.clear()

    mon.setCursorPos(5,5)

    if engine_state == true then

        mon.write("Engines: On")

    else

        mon.write("Engines: Off")

    end

end

Link to comment
Share on other sites

also, I ran some experiments. The main computer is detecting and responding to the message sent by the other computer, but it's just not responding correctly. So I think the id's are all in order. The sender code has the id of the main computer, and the main computer listens for the message of the computer with the id of 17.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

Announcements




×
×
  • Create New...