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

A few questions

Started by TheArchitect, 04 January 2013 - 09:41 AM
TheArchitect #1
Posted 04 January 2013 - 10:41 AM
Hello, everyone. I learned about CC just a few days ago, and I believe it's a fantastic mod that would provide just the functionality I need on a multiplayer server I'm working on. However, I have a few questions regarding its use that the wiki hasn't completely answered and I haven't found about them in the forums either.

First of all, I intend to have some computers running continuously; but I've read in the forums some people are having a problem with computers randomly turning off and needing a manual reset. This of course is a bit inconvenient in a multiplayer server, requiring someone to be available to manually reset them when necessary. I have, however, read somewhere in the wiki that computers that have been running continuously without doing os.pullevent will be automatically shut down after ten minutes (may this be the problem some are experiencing, or did I understand wrong?). The issue here is that os.pullevent will freeze until an event or timeout occurs if I understood right, which would temporarily halt program execution. Am I understanding everything right about this? Is there a way around that?

Second, I saw in a mod highlight that placing a computer in the world will assign it an autoincremental numeric ID. When the computer is "mined" then replaced, if it doesn't have a Label it will receive a new numeric ID. The questions are:
> Is there a maximum ID? (or maximum number of computers that can ever be placed in a single world)
> If so, is there a way to reset the count so that new computers will take lower IDs from previously discarded computers?

From what I've seen, a possible way to reuse an old ID is to /give (or place with worldedit) a computerblockID:computerID, but it might not be the only one. This also brings me to the next question: Is it possible (just possible, not necessarily wanted or unwanted) that more than one computer has the same ID? Would this make two computers with the same contents or two instances of the same computer?

Sorry if I seem a bit too obsessed over details, but (especially with my background in IT) these are inevitable questions to me.

I've never programmed in Lua but seems easy enough to be worth a try! To the mod devs, this is a fantastic mod, congratulations.

Thanks in advance.
FUCKCOMPUTERCRAFT!"£ #2
Posted 04 January 2013 - 10:59 AM
http://www.computercraft.info/forums2/index.php?/topic/1516-ospullevent-what-is-it-and-how-is-it-useful/
TheArchitect #3
Posted 04 January 2013 - 12:22 PM
Thanks, I don't remember reading that post, but it doesn't quite answer my question. I understand what os.pullevent does, but I'm not sure if I want my program to be periodically put on hold for a certain time (knowing it will time out because there will be no events for it to retrieve) only so it doesn't get shut down.
thislooksfun #4
Posted 04 January 2013 - 12:29 PM
What kind of program(s) are you trying to run?
TheArchitect #5
Posted 04 January 2013 - 12:36 PM
Basically looping programs that listen for redstone signals and act/display accordingly.
FUCKCOMPUTERCRAFT!"£ #6
Posted 04 January 2013 - 12:47 PM
Thanks, I don't remember reading that post, but it doesn't quite answer my question. I understand what os.pullevent does, but I'm not sure if I want my program to be periodically put on hold for a certain time (knowing it will time out because there will be no events for it to retrieve) only so it doesn't get shut down.

Maybe not hearing you right but i've heard of it shutting down after 10mins, unless there is some input from something…
Maybe you could do os.pullEvent(2)
waits two secound for an event then moves on, if you need a os.pullEvent to stop it haulting add a time out one for a short period….

IM PROBS TALKING SH@T…
thislooksfun #7
Posted 04 January 2013 - 12:48 PM
Uh… I found this in the list of events os.pullEvent() can listen for.
FUCKCOMPUTERCRAFT!"£ #8
Posted 04 January 2013 - 12:49 PM
Uh… I found this in the list of events os.pullEvent() can listen for.

If i've understood what he said and there is no redstone input for 10mins or more will it not shutdown then?

If he is right..
TheArchitect #9
Posted 04 January 2013 - 12:53 PM
Maybe you could do os.pullEvent(2)
I thought you could only specify the type of event, not the timeout value.

At least, that's not what it says here. If that can be done, I'm all set on that aspect.
thislooksfun #10
Posted 04 January 2013 - 12:58 PM
Ah, I may have misunderstood the problem. I thought he was saying that any program will terminate after 10 minutes if it was not waiting for an event (for example:


while not redstone do
  if not rs.input(bla) then
    redstone = true
  end
  sleep(1)
end
print("Redstone is on!")

would terminate after 10 minutes but


os.pullEvent("redstone")
print("Redstone is on!")

would not).
Please forgive the sloppy code, I was just making it up to explain my point.
TheArchitect #11
Posted 04 January 2013 - 01:04 PM
Yes, that's exactly what I'm concerned about.
Bubba #12
Posted 04 January 2013 - 01:14 PM
You want os.pullEvent() to timeout after some amount of time and then reset? You can use timers to do that.


local function pullEvent()
while true do
  os.startTimer(100) --Starts a timer which will go off and activate os.pullEvent() after 100 seconds
  local event, arg1, arg2 = os.pullEvent()
  if event ~= "timer" then
  return event, arg1, arg2
  else
    --Do whatever other code you wish to do here
  end
 end
end

As for computer IDs, there is no limit (or if there is, I doubt you could ever reach it). And yes, technically it is possible to get two computers with the same ID if they are labeled and you break them in creative mode. They will have the same files on them but their runtimes are separate meaning you could be running two different programs at the exact same time. You can not change the ID of a computer, but you can unlabel it (type in "label" without arguments in the command line to see different label commands).
FUCKCOMPUTERCRAFT!"£ #13
Posted 04 January 2013 - 01:17 PM
Ah, I may have misunderstood the problem. I thought he was saying that any program will terminate after 10 minutes if it was not waiting for an event (for example:


while not redstone do
  if not rs.input(bla) then
	redstone = true
  end
  sleep(1)
end
print("Redstone is on!")

would terminate after 10 minutes but


os.pullEvent("redstone")
print("Redstone is on!")

would not).
Please forgive the sloppy code, I was just ma
king it up to explain my point.

But what happens when there is no event with os.pullEvent for 10mins, will it shutdown? Ill go test my time out cmd i read it somewhere i think….
Bubba #14
Posted 04 January 2013 - 01:39 PM
Ah, I may have misunderstood the problem. I thought he was saying that any program will terminate after 10 minutes if it was not waiting for an event (for example:


while not redstone do
  if not rs.input(bla) then
	redstone = true
  end
  sleep(1)
end
print("Redstone is on!")

would terminate after 10 minutes but


os.pullEvent("redstone")
print("Redstone is on!")

would not).
Please forgive the sloppy code, I was just ma
king it up to explain my point.

But what happens when there is no event with os.pullEvent for 10mins, will it shutdown? Ill go test my time out cmd i read it somewhere i think….

It doesn't matter if you're using that code I just posted. It sends a timer event every 100 seconds so the computer will never turn off.
Lyqyd #15
Posted 04 January 2013 - 01:51 PM
The time limit on failure to yield is on the order of ten seconds, not ten minutes. Moved to Ask a Pro.
W00dyR #16
Posted 04 January 2013 - 02:19 PM
For computer IDs there is a limit, the max 32 bit java value (I do believe Minecraft is 32-bit at least :P/>)

Which would be 2^32 = 2,147,483,647

So if you manage to get close, let me know, then I want your autograph :)/>
Lyqyd #17
Posted 04 January 2013 - 02:22 PM
For computer IDs there is a limit, the max 32 bit java value (I do believe Minecraft is 32-bit at least :P/>)

Which would be 2^32 = 2,147,483,647

So if you manage to get close, let me know, then I want your autograph :)/>

Might want to check your math on that one. I guaran-damn-tee you that 2^32 isn't an odd number. And it's approximately 4.3 billion anyway.
thislooksfun #18
Posted 04 January 2013 - 02:47 PM
2^32 is 4,294,967,296, just FYI (that's still a lot though).
ChunLing #19
Posted 04 January 2013 - 03:04 PM
Okay, almost everything useful a computer can do requires that it pull an event. And it is essential that computers yield because they are all being emulated by a single program space (I've heard rumbles that eventually they will execute in a time-muxed parallel, but currently they need to yield or no other computers get a chance to do anything).

You can reset the ID assignments by deleting the computer folders in your world save.
TheArchitect #20
Posted 04 January 2013 - 03:37 PM
Thanks ChunLing, your answer makes sense. I figure I have no other option but to do a os.pullevent even in computers that don't require user input, like clocks.

Next goal: Place 2^32 computers in a single world :P/>
ChunLing #21
Posted 04 January 2013 - 03:51 PM
The sleep() function works by setting a timer event and then pulling it, so you can just use sleep for a clock (you shouldn't, though, you should use os.time() to get the world time). Pretty much all the turtle functions yield so they can pull their success events, rednet messages pull events to both send and receive…usually the problem that people have is how to avoid using a function that will pull a specific event type while discarding others they wanted to get.
TheArchitect #22
Posted 04 January 2013 - 06:09 PM
Thanks. I've been testing some more and it turns out sleep(x) is also a valid replacement for os.pullevent for things like static displays not to time out and halt. I had been using pullevent all along.

So a clock would be basically a loop with os.time() and sleep(x) (after all, the time changes only after a second or so) and that would do the trick.
ChunLing #23
Posted 05 January 2013 - 02:12 AM
Yes. But for an actually static display, you'd want to just run it once and have a startup file that ran the program in case the chunk got reloaded.
TheArchitect #24
Posted 06 January 2013 - 06:15 PM
The only problem is that computers seem to turn off when their chunks get unloaded and need to be manually turned on afterwards.
ChunLing #25
Posted 07 January 2013 - 08:53 PM
They reboot, if they were on when they were unloaded. As long as you have a startup program that gets them back on task, they'll be fine.

There was a problem in older versions where monitors, once already placed in a large screen, didn't update themselves on reloading, so the monitor wouldn't work until a block was broken and replaced.
TheArchitect #26
Posted 07 January 2013 - 10:58 PM
Been testing with the latest version and they do reboot if they were on when unloaded. Fantastic. It's just what I need :D/>
theoriginalbit #27
Posted 08 January 2013 - 02:32 AM
Next goal: Place 2^32 computers in a single world :P/>
If my math is correct that is approximately 65.5k chunks full of computers… Have fun!
Heracles421 #28
Posted 08 January 2013 - 04:03 AM
Next goal: Place 2^32 computers in a single world :P/>/>
If my math is correct that is approximately 65.5k chunks full of computers… Have fun!
They are exactly 65793 chuncks
ChunLing #29
Posted 08 January 2013 - 07:06 AM
And Intel took so much flack for the early Pentium. Not that they didn't deserve it.
TheArchitect #30
Posted 08 January 2013 - 09:03 AM
I'd say WorldEdit would help, but the real challenge is to do it by hand.

In survival mode.


…Challenge accepted.
ChunLing #31
Posted 08 January 2013 - 10:56 AM
I think the real challenge is not crashing your game by doing it. And that's after taking into consideration that you'll need about 35.7 million chunks worth of redstone (depending on your luck) in order to make all those computers.
TheArchitect #32
Posted 08 January 2013 - 12:19 PM
This doesn't sound easy.
theoriginalbit #33
Posted 08 January 2013 - 12:53 PM
Well the computer shouldn't crash as long as he doesn't turn them on. If he turns them on they will start ticking and lagging like crazy…
ChunLing #34
Posted 08 January 2013 - 12:57 PM
Yeah, but you need to turn them on to generate the IDs, right?

If you just start with the making and placing, and keep that up for a couple of decades, computers and interfaces might evolve to the point where it would only take you another few years to get all the computers placed, and then you can turn them all on in a cascade using peripheral methods.