Jump to content




Self-Replicating Turtle - Revisited


104 replies to this topic

#81 Inksaver

  • Members
  • 61 posts

Posted 19 August 2014 - 10:24 PM

Thanks for your comments.

I would love to see your code. Perhaps you could put it on pastebin?

I may contunue with this, but at the moment I am working on a mining script that uses a lot of the functions I wrote to enable a player in survival mode to place a turtle down anywhere, give it a chest, dirt, cobble, stone, gravel, a bucket and a full stack of wood, and it will craft all it needs and mine out a 33x33 area in multiple layers with ladders and stone staircases, with full resume after server restart. It uses recursive functions to mine ores as efficiently as possible, and constructs floors in all layers, with signs giving levels and compass bearings, so the player can explore the mine with ease.

#82 lare290

  • Members
  • 53 posts
  • LocationFinland

Posted 04 July 2015 - 05:37 PM

View PostInksaver, on 12 May 2014 - 08:52 PM, said:

After all I am still a beginner!
Yeah, sure.

#83 wood

  • Members
  • 6 posts
  • LocationQuebec

Posted 13 January 2016 - 10:24 PM

@Inksaver, awesome progam !
I just started progaming during winter holiday and don't have much background in programing.
I'm going to try and make some sort of AI for my turtle, I hope I can do it as fast as you, if I'm done by the end of the year, it's a success :)
I read that you were going to make a tutorial, I was wondering if you started it ?

#84 jaketheraven

  • Members
  • 3 posts

Posted 06 June 2016 - 08:37 PM

When I run this it says slot number 0 out of range. I really want to use this. Please help.

Hey I just had an idea! What if you used the peripherals api to automatically activate the offsprings?

Edited by Bomb Bloke, 07 June 2016 - 01:45 AM.


#85 Meit

  • Members
  • 22 posts
  • LocationPK

Posted 24 July 2016 - 10:11 AM

Increase all slots number by 1 in the code, ITS COMMON SENSE..
They are going out of the range and ID's cause the codes been changed (slot ids start: 1, 1-10 = 9 slots)
So increase all slots Id's/numbers by 1 and it will work (even if it is 0 + 1 it should be 1,)

#86 dropdead

  • Members
  • 14 posts

Posted 17 November 2016 - 06:41 PM

Hi there!
I visit this forum for years since there is always a neat little program for this or that.
This self replicating turtle program is really great and obviously the creator took quite some time to make it that way.
I have tried it countless times but if it does not bug out because something confuses the turtle, the program stops when diamonds are found and it is back on the surface. The problem is always the same: slot number 0 out of range.
I get the problem but my grasp of Lua is not good enough to dig through all the code and fix it. I DO understand that Lua is a bit peculiar since it starts counting with 1 and not with 0 like most other languages.
And if I understand then slot 0 is out of range because it simply does not exist.
I tried all the world seeds the creator gave because they should work but somehow I am out of luck. The most of the program I've seen one time is the turtle making a pickaxe and then spitting it out for whatever reason. I never got that far again.

Any idea how to fix this since I've read more than once about this problem or is this thread too old? I could even provide the logs and such but I don't want to put all this stuff here if nobody can help anyway.


Thanks in advance!

Edit: Fixed some stuff. Stupid typos.

Edited by dropdead, 18 November 2016 - 05:32 AM.


#87 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 18 November 2016 - 12:32 PM

View Postdropdead, on 17 November 2016 - 06:41 PM, said:

-snip-
does the error give a line number?

#88 dropdead

  • Members
  • 14 posts

Posted 18 November 2016 - 01:50 PM

View PostLupus590, on 18 November 2016 - 12:32 PM, said:

View Postdropdead, on 17 November 2016 - 06:41 PM, said:

-snip-
does the error give a line number?

It does, though I'd have to lie if I said anything more than it was about 3000 and had this time something to do with wood... (@_o) but I have started the program once again and it is already over two hours and the turtle has lots of resources gathered (deep mining soon). The error doesn't appear in the log and since your guess is as good as mine which line number the error threw yesterday time, I will tell you when
the program stops because if it finishes THIS TIME it would be a first.

View PostLupus590, on 18 November 2016 - 12:32 PM, said:

View Postdropdead, on 17 November 2016 - 06:41 PM, said:

-snip-
does the error give a line number?

Hi again.

Since I am still a brand new member, the first posts have to be approved but I have an error now. It occurs in line 2719 (function craft):

function craft(arg)
		-- code...
if arg.doSort == nil then
  arg.doSort = false
end
if arg.doSort then
  sortInventory(true)
end

if arg.sourceItem1 == nil then
  sourceSlot1 = 0
  sourceQuantity1 = 0
else
  sourceSlot1 = slot:getItemSlot(arg.sourceItem1)
  sourceQuantity1 = turtle.getItemCount(sourceSlot1) -- THIS IS LINE 2719!
end
	  
		-- code ...
end

This time the turtle didn't even find diamonds. Ten places in the turtles inventory contain items:

1x chest, 61x dirt, 61x cobblestone, 31x ironore,
1x stone, 24x coal, 61x gravel, 1x bucket,
1x redstonedust, 1x torch

Hope this helps.

Addendum1: Line 2719 is the same like yesterday and I can't shake the feeling that it is ALWAYS that line when the dig goes wrong.

Addendum2: Well, tried once again and it is line 2718 that throws the same error. Is it possible that the turtle is too packed with stuff?
This time it carried 16 slots full of items, spit out the planks and the program spit out that damn error...

MC 1.64
CC 1.63
Forge 9.11.1.1345

Edited by dropdead, 19 November 2016 - 03:28 PM.


#89 Inksaver

  • Members
  • 61 posts

Posted 09 January 2017 - 01:52 AM

Hi all
I have not looked at these forums for some time, so apologies to anybody who has left comments which I have not answered.
I just spotted this thread was still active, as I was about to post another program called "Survival Toolkit" which has been developed for use in survival mode and allows you to make use of your first Crafty Mining Turtle to mine without needing any supervision, flatten and clear surface areas, and create tree farms.

This version of the self-replicating turtle was developed before the ability to identify blocks and items was added, which is why it is so complicated.

There is a logging system, which if enabled can give clues to the cause of the errors described above.

As a suggestion, if you add a line above 2718:
print("About to use line 2718. arg.SourceItem1 = "..tostring(arg.SourceItem1))
and it errors out because arg.SourceItem1 = nil, and consequently sourceSlot1 = 0, which gives the error.

There is an updated version of this using MC 1.7.10 here http://pastebin.com/2Krm3Yva

#90 Beeskee

  • Members
  • 27 posts

Posted 12 August 2017 - 03:16 PM

This is still one of the most amazing computercraft things I've ever seen. :)

#91 nagoL2015

  • Members
  • 4 posts

Posted 25 October 2017 - 08:12 PM

This is by far the best and well-done script I have ever seen before in my experience with lua . Great job, keep up the amazing work :D.

Edited by nagoL2015, 27 October 2017 - 10:09 AM.


#92 dropdead

  • Members
  • 14 posts

Posted 05 December 2017 - 06:51 PM

Might be late, but of course I've not forgotten about this neat program.

Without looking at the code before starting up the first time, it's easy to see that there are quite some changes.
For now the little guy is just cutting down trees. It hasn't even been looking for stone and so there is no oven anywhere to be seen. Guess it can power itself with wood now? It's running about an hour now and I wonder what the program does this time. This time I took a random world - I've seen the other ones so much there was time for a change there, too.

And: my thanks to the creator for not forgetting this thread!

Edit:
Well, it was interessting while it lasted. ^^
It dug down after it spit out out some trash and when it came back up it put the chest on the bottom and filled stuff in, got it out, filled it in, got it out and so on. After uncounted times it suddenly stopped doing anything and my inspection showed, that it had started itself to death. Or something of the sort. <g>

This time the program failed with an vm java error: again with an array access that was out of bounds. The last words:

getStock()minecraft:coal(0)= not found
Refuelling with log slot 13, crafting planks
EmptyTrash():moving down
bios:80: vm error: java.lang.ArrayIndexOutOfBoundException: 256

The inventory of the turtle is chock full. Slot 13 does indeed contain wood but since the inventoy is full there would have been no place for planks.

slot 1: 30 oak sapling
slot 2: 37 dirt
slot 3: 15 sugar cane
slot4: 64 oak wood

slot 5: 64 cobblestone
and 6: 64 cobblestone
slot 7: 12 birch saplings
slot8: 64 oak wood

slot 9: 3 sand
slot 10: 63 birch wood
slot 11: 64 cobblestone
slot 12: 48 redstone

slot 13: 64 oak wood
slot 14: 17 cobblestone
slot 15: 1 furnace
slot 16: 1 chest

The log is in the spoiler.

Spoiler

Edited by dropdead, 05 December 2017 - 08:05 PM.


#93 dropdead

  • Members
  • 14 posts

Posted 06 December 2017 - 10:56 PM

This is just a tad annoying, but at least now I got the same error two times. Long story short:
The turtle does its thing and after mining has a bunch of diamonds in its inventory. Then it comes up, drives forwards and backwards, sorts a bit in between and then it suddenly spits everything out: 372: Slot number 0 out of range
366 -- go back and remove supplies
367 T:go("RRFF") -- diamonds
368 turtle.select(1)
369 turtle.suckDown()
370 itemSlot = T:getItemSlot("minecraft:diamond")
371 keepNum = numTurtles * 3
372 turtle.select(itemSlot)
373 if turtle.getItemCount(itemSlot) &gt; keepNum then
374 turtle.dropDown(turtle.getItemCount(itemSlot) - keepNum)
375 end
And what I see eveytime: somewhere along the way the turtle makes a neat little chest and puts the saplings in... but obviously cannot remember where they went, because when it says something about clearTreefarm() it abandons the project because there are no saplings.
Don't know if that's ever going to work but I'll try anyway. ^^
Put the log in the soiler again...
Spoiler

Edited by dropdead, 08 December 2017 - 09:16 PM.


#94 doctorwhofan92

  • Members
  • 17 posts

Posted 10 August 2018 - 05:03 AM

Hey so the code still isn't working on Computercraft 1.7.5 for 1.7.10 getting the 0 is out of range error

#95 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 August 2018 - 02:11 PM

The author hasn't posted here in quite some time, so unless you're willing to update it for your specific Minecraft build yourself, that's unlikely to change. Earlier posts in this discussion already discuss how to narrow the problem down.

#96 Inksaver

  • Members
  • 61 posts

Posted 09 December 2018 - 06:24 PM

I have now retired the original 12,000 lines to a new pastebin link: https://pastebin.com/JVD1RPfg
The link given in my original post has now been updated to a new version with less than half the line count which is far more reliable. Here it is again: https://pastebin.com/2Zf5an8H

It served its purpose well, and is still useful for those interested in the concept of machine learning / AI as the turtle had to learn by experiment what the various blocks are, but the huge difficulty of keeping track of all the items during a run session lasting up to 12 hours was a nightmare. I am amazed it ever worked at all.

This has been tested on a portable version of MC 1.7.10 and the latest launcher running MC 1.8.9.

Please continue to enjoy and learn. I now use the computercraft mod in coding clubs due to the instant feedback young pupils get when trying it out.

#97 dropdead

  • Members
  • 14 posts

Posted 10 January 2019 - 05:42 PM

View PostInksaver, on 09 December 2018 - 06:24 PM, said:

I have now retired the original 12,000 lines to a new pastebin link: https://pastebin.com/JVD1RPfg
The link given in my original post has now been updated to a new version with less than half the line count which is far more reliable. Here it is again: https://pastebin.com/2Zf5an8H

It served its purpose well, and is still useful for those interested in the concept of machine learning / AI as the turtle had to learn by experiment what the various blocks are, but the huge difficulty of keeping track of all the items during a run session lasting up to 12 hours was a nightmare. I am amazed it ever worked at all.
...

Well well,

what do we have here? Looks like another chance for me to FINALLY get this program to work.

I have tried countless times since I first found this program years ago and one of the last version I got always got confused where the chests were exactly as well as the tree farm. This was a run that really got me somewhere, although I had to help the turtle a bit or it wouldn't have found the chests for the material and the chest for saplings. In the end it bugged out like always with the lovely "ArrayIndexOutOfBoundsException".

Looks like I'm up for another test. I'm nothing if not persistant. <chuckle>


Thank you for the update!

#98 dropdead

  • Members
  • 14 posts

Posted 10 January 2019 - 06:52 PM

View Postdropdead, on 10 January 2019 - 05:42 PM, said:

... Looks like I'm up for another test. ...
That was fast. Turtle found massive amounts of wood and saplings, started to create the homebase. After it built a furnace it spit it out - probably because of a full inventory. It built a bit more of the base and when it tried to place the furnace it wasn't there (because it was lying around somewhere).
Great.
Would have posted a pic or something but I can't find where to upload it. Since I have no webspace I can not use an URL.

Edited by dropdead, 11 January 2019 - 01:01 AM.


#99 dropdead

  • Members
  • 14 posts

Posted 11 January 2019 - 05:00 PM

Huh,
guess I never get this to work. This time I followed it around the whole time and it was a good idea - turtle would have found only two diamonds otherwise. After deep mining for diamonds it got up, sorted a bit and then a bit more and went to put the stuff for away aside from things needed for the pickaxe. Then there it was again: "Slot number 0 out of range".
To me it looked as if this happened exactly after it put some diamonds away. It last words:
"selfrepneu.lua:2687: Slot number 0 out of range"
The end of the log file:

Spoiler

It stood exactly over the chest between the iron and the stone/dirt. I guess this is where it got the sugarcane.

What I did while following it around was to snag a stack of stones or obsidian when the inventory was full but I don't think the turtle cares because it always sorts its inventory after digging out a row of stone and throws stone/dirt/gravel away if it has more than one stack. I only did that because the first run failed when the inventory was completely full.

Quite a couple of month ago I played around with the older code and this time it came quite far, although I had to place all chests one block back, because it got confused where the heck all the chests where. Then it even made a computer and somewhere around then it got confused with all the stuff in the inventory and the program died.
Don't know why it never works for me. <sigh>

Edited by dropdead, 11 January 2019 - 05:05 PM.


#100 dropdead

  • Members
  • 14 posts

Posted 12 January 2019 - 03:19 AM

The story continuous!

This time everything went well until the turtle had crafted a bucket. It started the method goToWater() and drove off into the sunset. Quite literally.

In the computer folder of the turtle was no file "waterCoords.txt". The coords it loaded where from "homeCoords.txt". I followed it for a while until I looked what the heck it was trying to do and saw that the water coords in the display where changed everytime it stopped to refuel.

I have absolutely no idea why it will not work for me when everybody says it does. I didn't use a portable version of MC 1.7.1 but a normal one. In the past I have tried different MC versions and different computercraft versions and, for good measure, different forge versions.

So I am a bit obsessed.

Since I didn't get how exactly the turtle got confused again, I'll post the log in the spoiler. Especially the end until I destroyed it was interesting.

Spoiler


I would provide a link to the save but I lack the webspace. To give the seed is not an option too, because I created the pond manually... and the turtle thought too close to base camp.

Maybe I should have ridden with the turtle into the sunset. :rolleyes:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users