Jump to content




Chest Scanning Error / Safari Net Troubles


  • You cannot reply to this topic
13 replies to this topic

#1 cocotoffee

  • Members
  • 12 posts

Posted 21 April 2015 - 03:54 AM

I'm trying to make my own code to automate a MFR Auto-Spawner. Currently I have a few things already set up, but I can't seem to get the data for whats in the safari net. I have the computer attached by a modem to a chest with various mobs in it. However, I set up a loop that only gives me the data on the 1st net. (1st slot) How do I make it scan ALL the slots/nets?

--Test for Mob Only
chest = peripheral.wrap("container_chest_0")
for i=1, 27 do
   data = chest.getStackInSlot(i)
	  print(data.captured)
   return false, nil
end

Edited by cocotoffee, 22 April 2015 - 02:07 AM.


#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 21 April 2015 - 04:19 AM

Try removing the 'return false, nil' - that's most likely the problem

#3 Bomb Bloke

    Hobbyist Coder

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

Posted 21 April 2015 - 09:59 AM

Sounds to me like you're using a peripheral proxy. Those things tend to break in weird and interesting ways if you break the block next to them (eg the chest) - try breaking and replacing the proxy itself.

#4 cocotoffee

  • Members
  • 12 posts

Posted 22 April 2015 - 12:20 AM

Yup it was the return false part. Thank you for that, I just set the loop to stop at the last mob to stop another error, thank you!

Also, whenever there isn't a net in the chest it gives an error. Is there a way to just make it skip these parts and just continue on?

Edited by cocotoffee, 22 April 2015 - 01:54 AM.


#5 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 22 April 2015 - 03:52 AM

instead of this...
print(data.captured)

try this...
if data then print(data.captured) end

EDIT: Correction - thanks, BombBloke

Edited by Dog, 22 April 2015 - 11:42 PM.


#6 Bomb Bloke

    Hobbyist Coder

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

Posted 22 April 2015 - 07:39 AM

Er, "if data then".

#7 cocotoffee

  • Members
  • 12 posts

Posted 22 April 2015 - 11:37 PM

Thank you! I have expanded on the code and I'm trying to use the TouchPoint API (By Lyqyd) but I'm not understanding how to format the while true do... for when the button is clicked to activate the function. He has a sample of how to use it but I'm lost on the while true do part. I understand its what makes it so when you click it does something but how would I do that for my first button, Lights, to toggle the lights?

TouchPoint API Troubles:
Spoiler

My Code (Bottom) :
Spoiler

Edited by cocotoffee, 22 April 2015 - 11:39 PM.


#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 April 2015 - 11:55 PM

If you're just wanting to use the functions on the buttons, and no other event inputs, you can just use t:run() instead of an event handling loop.

#9 cocotoffee

  • Members
  • 12 posts

Posted 23 April 2015 - 12:06 AM

Would I put the t:run() anywhere? Like next to the t:draw()? Or should it be somewhere more specific?

#10 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 April 2015 - 12:19 AM

Instead of the while loop down at the bottom.

Of course, if you wanted to use any other events other than button presses, that won't be a viable option.

#11 cocotoffee

  • Members
  • 12 posts

Posted 23 April 2015 - 10:30 PM

I added the t:run() part, but whenever I click the button it doesn't output the redstone signal to the yellow wire through the back. I just have a ProjectRed bundled cable on the back so it can send signals and I can do it manually through lua. The monitor is just on the right side but I can't seem to figure out why the button doesn't work. It doesn't even give an error so I must be missing something. Also have I set up toggleLights() function (near the bottom) correctly? It's my first time trying something like that.

Spoiler


#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 April 2015 - 12:03 AM

You need to add your button below the declaration for the toggleLights function, not above it.

#13 cocotoffee

  • Members
  • 12 posts

Posted 24 April 2015 - 04:46 AM

So when ever you reference another function it should after it? And I changed the code to be in the correct order but it doesn't seem to work still. :(

Spoiler


#14 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 April 2015 - 02:26 PM

Well, the touchpoint.new call should be called with "right" instead of "RIGHT". You've also got colors.combine in both of your redstone functions, where the off function probably should have colors.subtract. You're also setting the global lights variable to the string "1" or "0" and then comparing it against the number 1 or 0, so you should use either numbers or strings in both places.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users