Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Chaz Serir

Matching an argument to a list of names

Question

Hey there! So I'm trying to make a program that controls a bundled redstone cable, and opens a series of doors (For context I'm building a storage building with ten rooms - six Standard storage rooms ( S1 through S6 ), two Premium storage rooms (P1 and P2), a Utility room and the Office.

With that in mind I want to write a program where I pass an argument, have it check to see if it matches any of the doors in the list, and then opens that door, or throws an error if no match is found. For example:

"open s1" would open door S1, while "open foobar" would just return "That isn't a door."

Here's the code I have so far, on Pastebin.

Unfortunately I'm getting tripped up somewhere with this, and getting "Expected number, got string" errors. Any advice on this would be appreciated!

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  • Solution

I've made some small changes.. I think this is what you're looking for :)

arg1=...
cm=require("component")
si=require("sides")
s=si.east
c=require("colors")
rs=cm.redstone

doors = {
 -- # key, value list of door id's and their respective colors
	["s1"] = 'red',
	["s2"] = 'green',
	["s3"] = 'brown',
	["s4"] = 'blue',
	["s5"] = 'purple',
	["s6"] = 'cyan',
	["p1"] = 'pink',
	["p2"] = 'lime',
	["office"] = 'yellow',
	["utility"] = 'orange'
}

function openDoor(id, doorlist)
  local color = doorlist[ id ]
  if color then
    rs.setBundledOutput(s, c[ color ], 255)
  else
	print(("[%s] is not a valid door id."):format(id))
  end
end

openDoor(arg1, doors)

Hope this helps.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.