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

Computers Reset When Move

Started by Lux, 30 August 2013 - 02:15 AM
Lux #1
Posted 30 August 2013 - 04:15 AM
Hi! I'm trying to open a door with Redstone In Motion but when the computer is moving it shutdown closing the wireless rednet conection. Any idea how to fix this or make a door like this?

The codes that I'm using:
Sender(Computer with the lock code):

term.clear()
term.setCursorPos(1,1)
rednet.open("back")
print[[
			  ----------------------
			  |SISTEMA DE SEGURIDAD|
			  ----------------------
			  Ingrese clave: ]]
term.setCursorPos(29,5)
local pass = "mypass"
local user = read()
term.clear()
term.setCursorPos(1,7)
if user == pass then
print[[
				------------------
				|Acceso concedido|
				------------------
				 Abriendo puertas]]
rednet.send(11,"Abrir")

else
print[[
				-----------------
				|Acceso denegado|
				-----------------]]
end
Receiver(computers beside to Carriage Controller):

rednet.open("top")
id, message = rednet.receive()
if message == "Abrir" then
shell.run("openr")
end

Texts are in spanish (like "sistema de seguridad" = "security system").
Thanks!
Last1Here #2
Posted 30 August 2013 - 05:30 AM
I assume this is a redstone in motion problem. So I don't think there would be a fix, unless you move the computer off the door.
Pinkishu #3
Posted 30 August 2013 - 05:49 AM
Same with MFFS.

MFFS people say CC has to fix it because of computers being a complex block or so :P/>
Not sure about RiM, but for MFFS i think it doesnt actually "restart" the PC but move it without moving the PC tileentity or state or something, causing the PC to startup again after the move with a new tileentity/state

I put a chat box thingy (from misc peripherals) on top of a PC and moved both with MFFS, the PC would read the chat event from the chat box and respond using the chat box, after moving now you got 2 responses though, after moving it again you got 3, etc; which hints to what i explained before
Lux #4
Posted 30 August 2013 - 06:11 AM
I read the WiM thread in Technik and it's a bug of ComputerCraft because when the CC is moved the chunks unloads and reloads so the computer will reboot. So I'll need get another form to conect the carriages to computercraft. Thanks for the replies!
Pinkishu #5
Posted 30 August 2013 - 06:44 AM
I read the WiM thread in Technik and it's a bug of ComputerCraft because when the CC is moved the chunks unloads and reloads so the computer will reboot. So I'll need get another form to conect the carriages to computercraft. Thanks for the replies!

That would be a word behavior… why would the chunk be unloaded and reloaded Oo
theoriginalbit #6
Posted 30 August 2013 - 06:52 AM
I read the WiM thread in Technik and it's a bug of ComputerCraft because when the CC is moved the chunks unloads and reloads so the computer will reboot. So I'll need get another form to conect the carriages to computercraft. Thanks for the replies!

That would be a word behavior… why would the chunk be unloaded and reloaded Oo
Because a chunk doesn't do that when a Block or TileEntity is updated. The Technik people have no idea about how Minecraft works and are just stating things to make people not blame them. and instead blame someone else.
Last1Here #7
Posted 30 August 2013 - 11:25 AM
How can this be a CC bug when the computer work fine on redpower frames (1.4.7)?
PixelToast #8
Posted 30 August 2013 - 11:56 AM
How can this be a CC bug when the computer work fine on redpower frames (1.4.7)?
this is not redpower, shoo
theoriginalbit #9
Posted 30 August 2013 - 12:05 PM
How can this be a CC bug when the computer work fine on redpower frames (1.4.7)?
'cause a lot in Minecraft has changed since 1.4.7… Also Elo did a lot of crazy magic behind the scenes when dealing with TileEntites, remember those crates, they did some pretty amazing and magical things…
kreezxil #10
Posted 30 August 2013 - 12:54 PM
Have you tried using a turtle instead of computer?
jakj #11
Posted 30 August 2013 - 05:36 PM
Woah, woah, ladies and gentlemen, calm down.

1) We at Technic do know how Minecraft works, thanks: The person who "quoted" us didn't even understand what we said. The method that I use to move tile entities is to save and restore them via NBT, the same method the game itself uses when loading and unloading chunks. That's where the chunk comment came from: By design, ComputerCraft computers and turtles reboot when the chunk unloads/loads, or when the game is closed/opened. So it's not a bug in RiM and it's not a bug in CC: It's a limitation in CC.

2) Yes, Eloraam used magic in the form of special code to directly transfer tile entities and update them. I'm not doing that because a) It's a lot of work to keep up with N mods instead of just Minecraft, and I'm not getting paid to do it, and B)/> it doesn't survive crashing or saving/loading while a carriage/frame is in-transit.

This is all very simple: If ComputerCraft were ever changed so that computers/turtles retain their running state when saving to disk and being reloaded, this would suddenly start working in block-moving mods.

When initially developing my mod and discovering this issue, I did my own research, and found old threads discussing this that basically boiled down to "We know it's not ideal; We'd like it to work like that; Don't expect it to be changed because it's a lot of work and we have other priorities to deal with first.". That's fine: Computers/turtles function just fine, as long as people have enough of a clue to write intelligent 'startup' programs. It's a bit of a pain/hassle, but since it's easy to save/load local state in programs, it's by no means impossible.
GammaPaladin #12
Posted 20 September 2013 - 08:18 PM
I have a question related to this.

I understand the computer "restarts" every time it's moved. That's fine. I wrote my code around that limitation, but I've run into another problem.

My program basically lets the user give it a direction and a number of blocks to move the frame. The program checks the number, and if it's greater than 1, it writes a file to the disk with the direction and the distance that will still need to be travelled after it moves once, closes the file, and then moves one block in the direction specified.

After moving, the computer "reboots", and the startup program looks for the file, if it's there, it reads in the direction and distance, decrements distance, rewrites the file, and moves again (Assuming distance was greater than zero).

The thing is, this works, but only once. If I type in "drive n 5", it moves north, restarts, moves north again, and then just stops. The computer seems to stop restarting itself. If I right click the computer, it will start up and load the startup file and move again. If I keep right clicking after each move, it will eventually finish out the queued movements, and give me a prompt again. But it requires manual intervention after that second move.

Does anyone have any idea why this is? Is there any way I could work around it?

[EDIT: Just in case it might help, my code follows. I had to type it in by hand, don't know how (If it's even possible) to copy and paste out of a CC computer.

drive program:

local carriage = peripheral.wrap("bottom")

local args = {...}

local dir = -1
local dist = 1

if #args > 0 then
  if args[1] == "d" then
    dir = 0
  elseif args[1] == "u" then
    dir = 1
  elseif args[1] == "n" then
    dir = 2
  elseif args[1] == "s" then
    dir = 3
  elseif args[1] == "w" then
    dir = 4
  elseif args[1] == "e" then
    dir = 5
  end
 
  if #args > 1 and tonumber(args[2]) ~= nil then
    dist = tonumber(args[2])
  end
 
  if dist > 1 then
    dist = dist - 1
    local h = fs.open("movequeue", "w")
    h.writeLine(dir)
    h.writeLine(dist)
    h.close()
  end
 
  if dir ~= -1 then
    carriage.move(dir, false, false)
  end
end

startup file:

if fs.exists("movequeue") then
  local h = fs.open("movequeue", "r")
  local dir = tonumber(h.readLine())
  local dist = tonumber(h.readLine())
  h.close()
 
  local carriage = peripheral.wrap("bottom")
 
  if dir ~= nil and dist > 0 then
    dist = dist - 1
    
    h = fs.open("movequeue", "w")
    h.writeLine(dir)
    h.writeLine(dist)
    h.close()
    
    carriage.move(dir, false, false)
  end
end
kreezxil #13
Posted 21 September 2013 - 06:59 AM
– snip –

[EDIT: Just in case it might help, my code follows. I had to type it in by hand, don't know how (If it's even possible) to copy and paste out of a CC computer.

– snip –

If HTTP is enabled in your minecraft and you would know if it was cause you could use pastebin get cOdE file then you can also take all of your code and send it to pastebin and receive a code to give us by using pastebin put file.
GammaPaladin #14
Posted 21 September 2013 - 10:20 AM
Well, I'm the one administering the minecraft server so I can easily enable things like that. But I'm pretty sure I typed the code in correctly anyway.

Good to know for the future though, thanks.
theoriginalbit #15
Posted 21 September 2013 - 10:37 AM
Well, I'm the one administering the minecraft server so I can easily enable things like that.
Also since you have access to the files, all computers save their code in /[path to server]/[world name]/computer/[computer id]/ replacing each of the values in [] with the appropriate value (note: to find out the computer id, run the `id` program on the computer).
kreezxil #16
Posted 21 September 2013 - 10:50 AM
Well, I'm the one administering the minecraft server so I can easily enable things like that.
Also since you have access to the files, all computers save their code in /[path to server]/[world name]/computer/[computer id]/ replacing each of the values in [] with the appropriate value (note: to find out the computer id, run the `id` program on the computer).

Omg, I didn't know that one! Sure beats looking at all of the ids manually when you have over 80 turtles on the server.
theoriginalbit #17
Posted 21 September 2013 - 11:09 AM
Omg, I didn't know that one! Sure beats looking at all of the ids manually when you have over 80 turtles on the server.
Well in that case, SSP computer files are in /[path to minecraft instance]/saves/[world name]/computer/[computer id]. A bonus addition of having access to the files that the computer uses is you can also edit them in a real editor instead of in-game. You can use something like Sublime Text 2 (cross-platform) and get a syntax highlighter for ComputerCraft, or you can use other things such as Notepad++ (Windows only) and edit in that with Lua highlighting.
GammaPaladin #18
Posted 21 September 2013 - 11:30 AM
Heck, even being able to edit them in pico is nice.

But I still can't figure out why the computer isn't starting up after the second move :/

I did edit my first post in this thread with copy-pasted code though, so it should be exactly accurate now, if it wasn't before.
GammaPaladin #19
Posted 21 September 2013 - 12:05 PM
Hmm. On a wild guess that the computer might be moving too fast for the server to keep up with updating its tileentity, I added a "sleep(1)" at the top of my startup script, and now it works fine. At least in singleplayer, where I'm testing it, as the minecraft login servers are down right now :/

So, solution appears to be, make sure there's a slight delay between moves when your computer is travelling with the frames, to allow the system to keep up.
theoriginalbit #20
Posted 21 September 2013 - 12:47 PM
Hmm. On a wild guess that the computer might be moving too fast for the server to keep up with updating its tileentity
No this is not the case. Its impossible to happen, the Turtle and its TileEntity move immediately, all you're seeing is a 0.8 second long animation, and once this is completed it will send a "turtle_reponse" event to any Turtle function you've called (assuming you're not calling turtle.native.func), that function will then return and allow your program to continue. Actually to that point there was a beta with "super" Turtles which could all perform their actions about 4x quicker and the clients/servers could still perfectly handle that, and with the current state of technology in modern computing could handle much, much more!


I added a "sleep(1)" at the top of my startup script, and now it works fine.
Chances are that if this fixes your problem you have a bug else where in your code. Please provide us with all your code so we can further help with this problem.
GammaPaladin #21
Posted 21 September 2013 - 05:33 PM
Um, that IS all my code. There is no turtle involved.

The computer is being moved by a third party mod item. I know that the move is completed instantly on the server side, but that's not to say that too many of those moves in rapid succession with no delay between them won't affect the functioning of the computer's tileentity in some way.

All I know for certain is that it works with the delay, and won't without. The code works fine, but the computer never loads it after the first time, unless there's a delay between iterations.
theoriginalbit #22
Posted 21 September 2013 - 06:05 PM
Um, that IS all my code.
there are api calls you make to a file named carriage to move things.

There is no turtle involved.
Well since you didn't specify, I had to speculate

The computer is being moved by a third party mod item. I know that the move is completed instantly on the server side, but that's not to say that too many of those moves in rapid succession with no delay between them won't affect the functioning of the computer's tileentity in some way.
Redstone in Motion?

All I know for certain is that it works with the delay, and won't without. The code works fine, but the computer never loads it after the first time, unless there's a delay between iterations.
The smallest delay possible to do is 0.8 seconds, its the speed of block movement, like gravel/sand falling, etc.
GammaPaladin #23
Posted 22 September 2013 - 12:58 AM
It's not an API call. It's a peripheral call. Did you notice the line:
local carriage = peripheral.wrap("bottom")

Yes, the third party mod is Redstone In Motion, which is what the thread's original poster was talking about. As I said, I'm using the structure carriage frames and a carriage controller, which is the peripheral being accessed. The carriage controller has one function, "move", which takes a numeric direction (0-5), a boolean which represents whether to only test the movement to see if it's possible, and a boolean that tells it whether the controller should stay anchored in place rather than moving with the carriage frames.

As I want it to actually move, the first boolean is false, and as I want the carriage controller to come along (Because otherwise I'm going to be stuck after the first movement), the second boolean is also false.
frostthejack #24
Posted 25 September 2013 - 01:21 PM
there has to be a minimum of 0.8 second delay at the top of the startup script and you have to have a startup script that points to your program. I have a working program that that moves frames in the direction you want the number of blocks you want.