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

can't get it to wrap all peripherals and also get the coordinates of these peripherals.

Started by renjestoo, 01 September 2016 - 03:52 PM
renjestoo #1
Posted 01 September 2016 - 05:52 PM
Hey there, I am creating a sorting system for turtles. (yeah I know I am not really original :P/> )
the problem is, that I can't figure out a way to wrap all the peripherals and their coordinates.


this is how it works: \
there is a Main computer (server)
there is a slave (turtle)
there is a remote (Pocket computer)

this is a little bit of the code for the Server (I always need to manually edit the script):


local localChannel=1
local rest={x=156,y=7,z=263}
local drop={x=160,y=6,z=264}
local chests={
{chest=peripheral.wrap("iron_0"),pos={x=156,y=5,z=260}},
{chest=peripheral.wrap("iron_1"),pos={x=157,y=5,z=260}},
{chest=peripheral.wrap("iron_2"),pos={x=158,y=5,z=260}},
{chest=peripheral.wrap("iron_3"),pos={x=159,y=5,z=260}},
{chest=peripheral.wrap("iron_4"),pos={x=160,y=5,z=260}},
{chest=peripheral.wrap("iron_5"),pos={x=161,y=5,z=260}},
{chest=peripheral.wrap("iron_6"),pos={x=162,y=5,z=260}},
{chest=peripheral.wrap("iron_7"),pos={x=163,y=5,z=260}},
{chest=peripheral.wrap("iron_8"),pos={x=164,y=5,z=260}},
{chest=peripheral.wrap("iron_9"),pos={x=165,y=5,z=260}},
}
local modem=peripheral.wrap("back")
local wireless=peripheral.wrap("bottom")

you can see the complete code for the server here: http://pastebin.com/zhSV6GeZ
I need to optimize the code so it will ask for a resting point and a drop point for the turtle, the modem sides and ofcourse the chests, with their coordinates.

The code for the turtle is here: http://pastebin.com/saVGtpYB

The code for the pocket computer is: http://pastebin.com/RsXahp4s

PS:
I also get errors on the turtle when sending him instructions: Startup:131: Expected number

this leads to the following snippet of the Turtle script:


unction self.goto(x,y,z,fails)
    if turtle.getFuelLevel() == 0 then
  [color=#ff0000]	 [/color] wireless.transmit(replyChannel,localChannel,"status|Out of fuel")[color=#ff0000] -- this is the error line 131[/color]
	    print("Awaiting fuel in slot 16")
	    turtle.select(16)
	    while turtle.getFuelLevel() == 0 do
		    turtle.refuel()
	    end
    end
    local fails=fails
    if fails==nil then
	    fails=0
    end
    local yDistance=(self.pos.y-y)*-1
    local yTravel=true
    if yDistance>0 then
	    yTravel=self.move("up",yDistance)
    elseif yDistance<0 then
	    yTravel=self.move("down",yDistance*-1)
    end
    local xDistance=(self.pos.x-x)*-1
    local xTravel=true
    if xDistance>0 then
	    self.setFacing("east")
    elseif xDistance<0 then
	    self.setFacing("west")
	    xDistance=xDistance*-1
    end
    xTravel=self.move("forward",xDistance)
    local zDistance=(self.pos.z-z)*-1
    local zTravel=true
    if zDistance>0 then
	    self.setFacing("south")
    elseif zDistance<0 then
	    self.setFacing("north")
	    zDistance=zDistance*-1
    end
    zTravel=self.move("forward",zDistance)
    if xTravel==false or zTravel==false or yTravel==false then
	    if fails==6 or fails == 8 or fails == 10 then
		    self.move("up",1)
		    self.move("forward",2)
		    self.move("down",1)
	    elseif fails == 5 or fails == 7 or fails == 9 then
		    local originalFacing = self.facing
		    if originalFacing == "north" then
			    self.setFacing("west")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
			    self.move("forward",2)
			    self.setFacing("east")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
		    elseif originalFacing == "south" then
			    self.setFacing("east")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
			    self.move("forward",2)
			    self.setFacing("west")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
		    elseif originalFacing == "west" then
			    self.setFacing("north")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
			    self.move("forward",2)
			    self.setFacing("south")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
		    else
			    self.setFacing("south")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
			    self.move("forward",2)
			    self.setFacing("north")
			    self.move("forward",1)
			    self.setFacing(originalFacing)
		    end
	    end
	    fails=fails+1
	    if fails>=11 then
		    return false
	    end
	    sleep(1)
	    return self.goto(x,y,z,fails)
    end
    return true
end

can someone help me fix my scripts please? I am getting a headache from it at this point since I can't figure it out anymore :(/>
CCJJSax #2
Posted 01 September 2016 - 07:02 PM
You would have to save the locations as a table and then


if [turtles location is adjacent] then
 peripheral.wrap([sides]) -- this would have to loop through all the adjacent chests.
end

Edited on 01 September 2016 - 05:03 PM
renjestoo #3
Posted 01 September 2016 - 07:28 PM
Sorry, didn't mentioned :)/> the chests are connected via Peripheral Proxy's so the Turtle gets the locations of the chests via the Server wirelessly

my question is, can I somehow get the locations of the chests more easily in someway and add them automatically in this setup?

here is a screenshot of my setup:


Also I want to know how to get all the peripherals in a table, inclusive the coords (automatically) the moment I add new chests.

please take a look at all the scripts or test it out.

The computer's program is http://pastebin.com/zhSV6GeZ
The turtle program is http://pastebin.com/saVGtpYB
The pocket computer program is http://pastebin.com/RsXahp4s

Here is a little bit more information:
The server is the computer hooked up to all chests, and manages the traffic between the clients and turtles. The central computer requires both a wireless and a wired modem. The wired modem would be wired up to chests attached to peripheral proxies (or any other inventory containing item which works with openperipherals).
The wireless modem will be used to communicate with the turtles and the pocket computer.

Besides the inventory chests you would need one more block where the items will be brought to. If you lack this the items will be dropped onto the ground. This chest should be placed on a different elevation than the regular chests for storage to aid in turtle path finding, and prevent them from blocking one another.

The turtles should have the wireless modem on the left, and crafting table on the right. The program also has 1 config option at the start of the program (requesting the channel of the server)
On the first launch it will ask for coordinates and direction, set the x,y,z coordinates to the ones the turtle is at. And the facing to the direction it is facing. Valid directions are "north", "east", "south" and "west".

The hand-held client is a wireless advanced pocket computer. It's also possible to run on an advanced computer, but the UI is not designed for that.
The first line is to be edited as well like the turtle, to the channel set in the storage server.

On first launch it will also ask for a channel, this should be a channel below 1000. This will be the channel used to connect to the server, if you want to add a second hand held client you simply do the same but input a different channel than the other ones.
Edited on 01 September 2016 - 05:37 PM
CCJJSax #4
Posted 02 September 2016 - 03:28 AM
I don't have a computer or anything to try anything out. But I was on a server where I helped make one. We had a wall of chests and had the turtle save the location info and the contents of said chests. It also had the pocket computer too
Bomb Bloke #5
Posted 02 September 2016 - 07:16 AM
We had a wall of chests and had the turtle save the location info and the contents of said chests.

I've used the same method.
renjestoo #6
Posted 02 September 2016 - 03:59 PM
Okay, can you give me an example of this script? Because one needs to be on the server that communicates between the handheld and the turtle

I can't figure it out anymore
Bomb Bloke #7
Posted 02 September 2016 - 05:04 PM
http://pastebin.com/kscHJZd1

In this case, the turtle moved from barrel to barrel, checking each container as it went to see which sort of item it contained. It wrote the final result to a file as a serialised table, which I could then simply copy and paste into my server's code.
renjestoo #8
Posted 02 September 2016 - 07:00 PM
its kinda what I mean, but not exactly…
Its good that he turtle knows the locations, but its actually the task of the server to tell this to the turtle, so the server needs to have these coords of the chests/barrels/whatever storage

try out my script by creating the setup as in my screenshot and you will see the other errors also ;)/>
you will need:
  • an Advanced Crafty Wireless turtle (and not a Wireless Crafty turtle)
  • an Advanced Computer with a modem and a wireless modem
  • a wireless Pocket Computer
If you can, please fix the script, it would be so cool :)/>
it still gives and error on line 131 in the turtle when giving him instructions via the handheld.
Edited on 02 September 2016 - 05:01 PM
Lupus590 #9
Posted 02 September 2016 - 07:53 PM
If it's the player which adds a new chest then have the server ask for the location, if it's the turtle then have the turtle send the location as it places the chest
renjestoo #10
Posted 02 September 2016 - 09:31 PM
hmmmm, is there no possibility that the turtle will check the coords of the chests, and send it to the server wirelessly?

and after that, "forget" the coords of the chests, since the server needs to send it to the turtle in the end for commands from the player.
renjestoo #11
Posted 03 September 2016 - 03:20 PM
Can someone test this script if it works correctly on your world? Maybe even give me tips and examples of how to improve it or fix it :)/>
that should be awesome, since I want to create a storage system where you can also craft stuff recursively.

I know its a lot of questions, but I dont know it anymore.
Lupus590 #12
Posted 03 September 2016 - 04:24 PM
Would help if you gave a link to your latest version of code
renjestoo #13
Posted 03 September 2016 - 04:55 PM
The computer's program is http://pastebin.com/zhSV6GeZ
The turtle program is http://pastebin.com/saVGtpYB
The pocket computer program is http://pastebin.com/RsXahp4s

this is how you need to setup everything :)/>


try out my script by creating the setup as in my screenshot and you will see the other errors also ;)/>
you will need:
  • an Advanced/normal Crafty Wireless turtle (and not a Wireless Crafty turtle)
  • an Advanced/normal Computer with a modem and a wireless modem
  • an wireless Pocket Computer
If you can, please fix the script, it would be so cool :)/>
it still gives and error on line 131 in the turtle when giving him instructions via the handheld.
Edited on 03 September 2016 - 02:55 PM
Lupus590 #14
Posted 03 September 2016 - 05:46 PM
I can't find where wireless and replyChannel are defined, also what is the exact error?
Edited on 03 September 2016 - 03:47 PM
renjestoo #15
Posted 04 September 2016 - 07:19 PM
I explained everything in the first post ;)/>