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

Attempt to index ? (a function value)

Started by yosomith, 11 February 2013 - 12:29 PM
yosomith #1
Posted 11 February 2013 - 01:29 PM
Alright, so I was trying to get fancy with a line of code that didn't need to get fancy. My Coding is short and the function is not needed but I would like to know why it doesn't work.

Here is the code:


local side = back

local function Door()
	redstone.setOutput("side", true)
	sleep(0.5)
	redstone.setOutput("side", false)
  end

Door()
sleep(10)
Door()

I found the issue, I originally tried naming the function wrong, which gave me the error and it messed up the computer. Just picked it up and put it back down (with label cleared) and it kinda works, different error but I can work around that.
Kingdaro #2
Posted 11 February 2013 - 01:48 PM
Quotes are in the wrong places, buddy. Remove them around "side" and put them around back at the top.


local side = "back"

local function Door()
    redstone.setOutput(side, true)
    sleep(0.5)
    redstone.setOutput(side, false)
  end

Door()
sleep(10)
Door()
RoD #3
Posted 21 June 2013 - 12:22 PM
If you want to use a string you need to tell the code that the string is back (For example)

local side = back
is different from

local side = "back"
and when you want to use the string you need to do the opposite

redstone.setOutput ("side", false)
need to change to

redstone.setOutput (side, false)