Jump to content




[SOLVED]how do I reference a table inside another?


6 replies to this topic

#1 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

Posted 25 February 2020 - 08:01 AM

It amuses me that I'm the only one starting threads here since the 20th, anyway- here's where I'm stuck yet again.
how do I reference a table within a different one?

this is what I got so far
sh = {} --[[sh stands for shorthand because I'm making a turtle crafting interface]]


sh["cbl"]="minecraft:cobblestone"


furnace = {
  sh:cbl, sh:cbl, sh:cbl, nil,
  sh:cbl, nil, sh:cbl, nil,
  sh:cbl, sh:cbl, sh:cbl, nil,
}
however you might notice that this doesn't work.
I've tried throwing everything but the kitchen sink of simple solutions but it looks like I'll have to use advanced techniques.

with regards
-qwerty

Edited by qwerty, 25 February 2020 - 03:30 PM.


#2 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 25 February 2020 - 08:02 AM

You need to use "sh.cbl" instead of "sh:cbl"

#3 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

Posted 25 February 2020 - 08:20 AM

View PostLuca_S, on 25 February 2020 - 08:02 AM, said:

You need to use "sh.cbl" instead of "sh:cbl"

thanks man, works now.

do you mind allso telling me how would I leave spaces in the table so that the turtle ignores it but doesn't break the loop?
here's what I am stuck at

furnace = {
sh.cbl, sh.cbl, sh.cbl, nil,
sh.cbl, nil,	   sh.cbl, nil,
sh.cbl, sh.cbl, sh.cbl, nil,
}
function selec(table)
  for i=1,#table do
    turtle.select(i)
    --rest of code

as you can guess it doesn't work as expected and when encountering a nil it will break the for loop not finishing the selection process.

with gratitude
-qwerty

#4 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 25 February 2020 - 08:49 AM

View Postqwerty, on 25 February 2020 - 08:20 AM, said:

-snip-

furnace = {
sh.cbl, sh.cbl, sh.cbl, nil,
sh.cbl, nil,	   sh.cbl, nil,
sh.cbl, sh.cbl, sh.cbl, nil,
}
function selec(table)
  for i=1,#table do
	turtle.select(i)
	--rest of code

with gratitude
-qwerty

You should probably just replace nil with "minecraft:air" or some dummy item, and then check in the rest of code wether it's an actual item or "minecraft:air"

Edited by Luca_S, 25 February 2020 - 08:51 AM.


#5 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

Posted 25 February 2020 - 09:12 AM

View PostLuca_S, on 25 February 2020 - 08:49 AM, said:

You should probably just replace nil with "minecraft:air" or some dummy item, and then check in the rest of code wether it's an actual item or "minecraft:air"

Ohhh ok then, I'll try that, thanks!

the only issue apparent here would be that the turtle selects all empty spaces and that's a no bueno in crafting.
scratch that, turtle.craft() is a stupid-to-use function.

with apreciation
-qwerty

Edited by qwerty, 25 February 2020 - 09:23 AM.


#6 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 25 February 2020 - 10:05 AM

View Postqwerty, on 25 February 2020 - 09:12 AM, said:

View PostLuca_S, on 25 February 2020 - 08:49 AM, said:

You should probably just replace nil with "minecraft:air" or some dummy item, and then check in the rest of code wether it's an actual item or "minecraft:air"

Ohhh ok then, I'll try that, thanks!

the only issue apparent here would be that the turtle selects all empty spaces and that's a no bueno in crafting.
scratch that, turtle.craft() is a stupid-to-use function.

with apreciation
-qwerty

If you don't want the turtle to select the empty slots you can use nil in the table and do the following to skip them:

function selec(tRecipe)
  for k, v in pairs(tRecipe) do
    turtle.select(k)
    -- The item name is now stored in v
  end
end


#7 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

Posted 25 February 2020 - 10:50 AM

View PostLuca_S, on 25 February 2020 - 10:05 AM, said:


If you don't want the turtle to select the empty slots you can use nil in the table and do the following to skip them:

function selec(tRecipe)
  for k, v in pairs(tRecipe) do
	turtle.select(k)
	-- The item name is now stored in v
  end
end
now while I've discovered that it doesn't need to skip the nil entries, this is still very useful. Thank you!

with kind regards
-qwerty





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users