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

Turtle Save in the chests

Started by Bardiel, 11 October 2012 - 06:55 PM
Bardiel #1
Posted 11 October 2012 - 08:55 PM
Hello! Here are my algorithm for save items in chests. Again, sorry for my bad english!

[media]http://youtu.be/NqorEeJWcKw[/media]

PasteBin: http://pastebin.com/8Wtw1gwG

Download: http://adf.ly/E2ZcO

I welcome your comments and questions!
slango20 #2
Posted 12 October 2012 - 11:57 AM
Translate code into English? Also you can put a signature into your profile, that says English is not your native language
ChunLing #3
Posted 12 October 2012 - 03:39 PM
You mean translate the comments.

It's an inventory management program for turtles, like he said.

Codewise, I see that there is room for improvement. For example:
Spoiler

function iralcofre(n)   --Lista de los cofres con sus respectivas localizacion.
		if n==1 then
				shell.run ("Pach","-211","64","-323","0")	   --"Pach" es mi programa de busqueda de caminos, las coordenadas son las del mapa del video.
				return true
		elseif n==2 then
				shell.run ("Pach","-213","64","-323","0")
				return true
		elseif n==3 then
				shell.run ("Pach","-214","64","-323","1")
				return true
		elseif n==4 then
				shell.run ("Pach","-214","64","-325","1")
				return true
		elseif n==5 then
				shell.run ("Pach","-214","64","-327","1")
				return true
		elseif n==6 then
				shell.run ("Pach","-213","64","-327","2")
				return true
		elseif n==7 then
				shell.run ("Pach","-211","64","-327","2")
				return true
		else
				return false
		end
end
could be replaced by a table lookup, like so:
Spoiler
iralcofre = {function() shell.run ("Pach","-211","64","-323","0") end,
function ()shell.run ("Pach","-211","64","-323","0")  end,
function() shell.run ("Pach","-213","64","-323","0")  end,
function() shell.run ("Pach","-214","64","-323","1")  end,
function() shell.run ("Pach","-214","64","-325","1")  end,
function() shell.run ("Pach","-214","64","-327","1")  end,
function() shell.run ("Pach","-213","64","-327","2")  end,
function() shell.run ("Pach","-211","64","-327","2") end
}
Then the relevant function would be called by "if iralcofre[n] then iralcofre[n]() else print("error message "..n) end"

You could further tighten the code by only storing the coordinate values in the table and just having a function that accepted the table…but there are more basic flaws to address first.

Like the fact that we don't have the program Pach that is needed to make use of this code. Or that you've only got room for a few chests.

Forgot a "()"…not that it matters since we can't run the code anyway.
Bardiel #4
Posted 12 October 2012 - 04:57 PM
Translate code into English? Also you can put a signature into your profile, that says English is not your native language

I think he meant to say my nationality is Argentine. Just a good idea to not be repeating "sorry for my bad English" all the time. XD
Bardiel #5
Posted 12 October 2012 - 05:01 PM
You mean translate the comments.

It's an inventory management program for turtles, like he said.

Codewise, I see that there is room for improvement. For example:
Spoiler

function iralcofre(n)   --Lista de los cofres con sus respectivas localizacion.
		if n==1 then
				shell.run ("Pach","-211","64","-323","0")	   --"Pach" es mi programa de busqueda de caminos, las coordenadas son las del mapa del video.
				return true
		elseif n==2 then
				shell.run ("Pach","-213","64","-323","0")
				return true
		elseif n==3 then
				shell.run ("Pach","-214","64","-323","1")
				return true
		elseif n==4 then
				shell.run ("Pach","-214","64","-325","1")
				return true
		elseif n==5 then
				shell.run ("Pach","-214","64","-327","1")
				return true
		elseif n==6 then
				shell.run ("Pach","-213","64","-327","2")
				return true
		elseif n==7 then
				shell.run ("Pach","-211","64","-327","2")
				return true
		else
				return false
		end
end
could be replaced by a table lookup, like so:
Spoiler
iralcofre = {function() shell.run ("Pach","-211","64","-323","0") end,
function ()shell.run ("Pach","-211","64","-323","0")  end,
function() shell.run ("Pach","-213","64","-323","0")  end,
function() shell.run ("Pach","-214","64","-323","1")  end,
function() shell.run ("Pach","-214","64","-325","1")  end,
function() shell.run ("Pach","-214","64","-327","1")  end,
function() shell.run ("Pach","-213","64","-327","2")  end,
function() shell.run ("Pach","-211","64","-327","2") end
}
Then the relevant function would be called by "if iralcofre[n] then iralcofre[n]() else print("error message "..n) end"

You could further tighten the code by only storing the coordinate values in the table and just having a function that accepted the table…but there are more basic flaws to address first.

Like the fact that we don't have the program Pach that is needed to make use of this code. Or that you've only got room for a few chests.

Forgot a "()"…not that it matters since we can't run the code anyway.

Thank you very much! I'm still not quite used to LUA. not going up the "Pach" that I believe still has bugs when I'll upload the fix. Just imagine that the majority has its own program pathfinding.

The program is equal to 7 chests for those who are just there to add the address of the other boxes.


function iralcofre(n) –Lista de los cofres con sus respectivas localizacion.
if n==1 then
shell.run ("Pach","-211","64","-323","0")
return true
elseif n==2 then
shell.run ("Pach","-213","64","-323","0")
return true
elseif n==3 then
shell.run ("Pach","-214","64","-323","1")
return true
elseif n==4 then
shell.run ("Pach","-214","64","-325","1")
return true
elseif n==5 then
shell.run ("Pach","-214","64","-327","1")
return true




elseif n==256 then
shell.run ("Pach","-211","64","-327","2")
return true
else
return false
end
end


know?
ChunLing #6
Posted 12 October 2012 - 11:33 PM
Yes, if you just store the coordinates in a table like so:

iralcofre = {{"-211","64","-323","0"},
{"-211","64","-323","0"},
{"-213","64","-323","0"},
{"-214","64","-323","1"},
{"-214","64","-325","1"},
{"-214","64","-327","1"},
{"-213","64","-327","2"},
{"-211","64","-327","2"}
}
Then you could expand the table with new entries to represent more chests. You could use the fs API to allow you to store and load the table using a file (so the changes wouldn't be lost if you) unloaded a world chunk or left the game. You can pull them back out easily enough by index, like iralcofre[1][1].
Bardiel #7
Posted 13 October 2012 - 02:34 AM
Yes, if you just store the coordinates in a table like so:

iralcofre = {{"-211","64","-323","0"},
{"-211","64","-323","0"},
{"-213","64","-323","0"},
{"-214","64","-323","1"},
{"-214","64","-325","1"},
{"-214","64","-327","1"},
{"-213","64","-327","2"},
{"-211","64","-327","2"}
}
Then you could expand the table with new entries to represent more chests. You could use the fs API to allow you to store and load the table using a file (so the changes wouldn't be lost if you) unloaded a world chunk or left the game. You can pull them back out easily enough by index, like iralcofre[1][1].

Very good idea thanks!