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

Doing diferent stuff acording to inputs/ file saving and resuming

Started by Minixiri, 03 June 2013 - 06:58 AM
Minixiri #1
Posted 03 June 2013 - 08:58 AM
so i'm having trouble with the first 15 lines of my code, not sure what i'm doing wrong.
and how can i make him resume if i disconnect

http://pastebin.com/fV7Ya5EB

thank you
Minixiri #2
Posted 03 June 2013 - 11:21 AM
hello everyone!!

I'm having trouble with this i cant make the if statement work

local info
term.write("MobDrop(1) or TradeVillage(2): ")
info = read()
print(info)
if info == 1 then
print("Building MobDrop")
else
if info == 2 then
print("Building TradeVillage")
else
print("Error not valid build")
end
end

I would like to make it save and resume if i disconnect and i don't know how to do it.
Also if there's a way to improve my code feel free to give tips.

Also missing is the checking fuel but that I think I can do it.

Here's full code not yet completed:
http://pastebin.com/JGeHQkY9

thanks
theoriginalbit #3
Posted 03 June 2013 - 11:24 AM
ok to tackle your first problem. the reason the if statements do not work is because the read function returns a string, and you're comparing to a number. to fix it you can do one of 2 things
#1, make the user input into a number with tonumber

local info = tonumber(read)
#2, make the comparisons a string

if info == "1" then

Also incase you're unaware we do have [code][/code] tags on these forums to help better format code in posts, however pastebin is better for long pieces of code.
InputUsername #4
Posted 03 June 2013 - 11:53 AM
Also, I would suggest changing the

else
if (condition)

to

elseif (condition)
Minixiri #5
Posted 03 June 2013 - 11:55 AM
I did like this and it doesnt ask me what i want to build


local info
  term.write("MobDrop(1) or TradeVillage(2): ")
  info = tonumber(read)
  print(info)
  if info == 1 then
   print("Building MobDrop")
   else
    if info == 2 then
	 print("Building TradeVillage")
	 else
	 print("Error not valid build")
 end
end
Lyqyd #6
Posted 03 June 2013 - 01:30 PM
Split into new topic.

If you continue to have trouble with posting new topics, please contact an administrator and respectfully request that they review your permissions, as the sticky post suggests.
Exerro #7
Posted 03 June 2013 - 01:32 PM
you are not calling the read function ( line 3 ). You should do
 info = tonumber( read( ) )
.
Lyqyd #8
Posted 03 June 2013 - 01:37 PM
Threads merged.
Bomb Bloke #9
Posted 03 June 2013 - 07:46 PM
if info == 1 then
   print("Building MobDrop")
   else
    if info == 2 then
         print("Building TradeVillage")
         else
         print("Error not valid build")
 end
end

This can be packed down just a little bit:

if info == 1 then
  print("Building MobDrop")
elseif info == 2 then
  print("Building TradeVillage")
else
  print("Error not valid build")
end
Minixiri #10
Posted 04 June 2013 - 10:56 AM
Got it almost done for what i want it to do. I just don't know how to make it resume if i leave chunk or disconnect since i'm playing singleplayer.

So how do i make it continue if the turtle gets unloaded?
And where do i put it?

Here's my full code:

http://pastebin.com/Pnkj9C3u

Thanks
Bomb Bloke #11
Posted 04 June 2013 - 10:10 PM
If there's a script titled "startup" on the root of a computer or turtle's drive, it'll run it on boot.

Your devices boot the first time you right click them after placing, or, when the chunk they're in reloads.

Making a script "continue" is tricky - when it restarts, it'll start from the beginning. You need to implement some code so that the turtle can either return to a "home" position when the script starts, or figure out where it was up to and carry on from there.
valithor #12
Posted 05 June 2013 - 01:42 AM
a basic "startup" wouldn't be enough seeing as you have no way of storing where the turtle is using either a coordinate folder (what i am currently struggling with creating myself) or a gps system which is much easier to set up but has a limited range. Currently with just a startup your script would start over from the beginning of the script which would result in it going off track or ending up in a undesirable location. I am sorry i can not help setting up either of these but this is probably what you will need to do in order to make it start back up.

If the turtle does not move then neither of these are required.

I read through about half of the code and from what i could tell one of these systems are required.
Bomb Bloke #13
Posted 05 June 2013 - 08:01 AM
There is a third option, at the least…

The idea is to construct a cage around the turtle. When the turtle boots, it flies up until it hits a roof, runs forward until it hits a wall, turns once and runs forward again until another wall is reached. The turtle now knows it's in one of the four corners of the cage. If it can find a chest to suck items from there, then it knows it's in the "right" corner, if not, it continues running to the next corner and the next until the chest is found.

From there, the turtle knows its position in the cage and can continue its work. Obviously this method (and methods like it) are only of any good for turtles that will be spending a lot of time in a single area (eg, a farming turtle).
Minixiri #14
Posted 07 June 2013 - 07:55 AM
Thanks anyway, i guess i'll make sure it doesn't go unloaded