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

Require help with multiple inputs/outputs

Started by white5pirit, 14 June 2015 - 12:23 PM
white5pirit #1
Posted 14 June 2015 - 02:23 PM
Hi. I won't lie, I'm a noob when it comes to coding, but I would really like to learn. Basically, I am trying to write a program for my mobfarm, which includes the user to input certain commands, and the computer to output redstone signals through different RedNet cable colours. I can't nail down the user input part.

Overall, I want the user to be able to specify which mob he wants to spawn, by typing it's name, for example "Skeleton" or "Witch". This is then translated into a different colour of the cable.
I have a basic idea of what the code should look like, but I do not know the functions required.
Here is my idea of the code:

if userInput == "Skeleton"
then rs.setBundledOutput("back",colour.gray)
print (Spawning Skeletons")
elseif userInput == "Blaze"
then rs.setBundledOutput("back".colour.yellow)
print (Spawning Blazes")

This can then be repeated with other mobs etc. The problem occurs, as I said, with the correct capturing, and translation of the user input into the mobs names, into redstone signals.
If anyone would be kind enough to help me sort this out, and possibly give me some tips, I'd be VERY grateful! Thanks!
@edit: Added the indentations.
Edited on 14 June 2015 - 05:51 PM
shamefulChris #2
Posted 14 June 2015 - 09:04 PM
well as far as user input you could use something as simple as



term.clear()
term.setCursorPos(1,1)
print("Name of your program or machine")
term.setCursorPos(1,3)
write("Enter the mob you wish to spawn: ")
local userInput = read()

if userInput == "Skeleton"
then rs.setBundledOutput("back", colors.gray)
print ("Spawning Skeletons")
os.sleep(3)
os.reboot()
elseif userInput == "Blaze"
then rs.setBundledOutput("back", colors.yellow)
print ("Spawning Blazes")
os.sleep(3)
os.reboot()

ect.

Edited on 14 June 2015 - 07:19 PM
jerimo #3
Posted 16 June 2015 - 03:39 AM
Another way, which I believe would be simpler is to make a table with your mobs and the colors they represent.

Mobs = {["Skeleton"] = colors.gray, other mobs here}[\code]

And then read the input and do this 
[code]
rs.setBundleOutput("back", Mobs[input])
[\code]
This has no error checking though, but would be simple to add in
Edited on 16 June 2015 - 01:42 AM
The Crazy Phoenix #4
Posted 16 June 2015 - 05:37 PM
You could also set the user input string to all uppercase or all lowercase using one of the Lua string methods and then just check the output with a string of the mob name using the same case. Testing for plural mob names shouldn't be so hard either.