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

[Question] This code is melting my brain!

Started by Matrixmage, 08 September 2012 - 11:18 PM
Matrixmage #1
Posted 09 September 2012 - 01:18 AM
I'm trying to get this code working but I can't seem to fix it, its melting my brain!

Spoiler


function whitetest()
local a = redstone.getBundledInput( "back" )
local white = colors.test( a, colors.white )
end

function pinktest()
local b = redstone.getBundledInput( "back" )
local pink = colors.test( b, colors.pink )
end

if white == true then
print("white on")
elseif white == false then
print("white off")
else
print("white failed")
end

if pink == true then
print("pink on")
elseif pink == false then
print("pink off")
else
print("pink failed")
end

The printing for testing purposes only.
Kingdaro #2
Posted 09 September 2012 - 01:23 AM
That's because your white and pink variables are both local to your functions and can't be access outside of them. That and you have to call them (by doing whitetest() and pinktest() ) before even being able to access the variables.

Try removing the word "local" from them, and then calling the functions before testing the variables.
Matrixmage #3
Posted 09 September 2012 - 01:31 AM
I expected it to be something this trivial… well thanks for the help! :D/>/>
ltstingray #4
Posted 09 September 2012 - 02:20 AM
Or if you wanted to keep them localized (for some reason)

function whitetest()
local a = redstone.getBundledInput( "back" )
local white = colors.test( a, colors.white )
return white
end

function pinktest()
local b = redstone.getBundledInput( "back" )
local pink = colors.test( b, colors.pink )
return pink
end

whitetest()
if white == true then
print("white on")
elseif white == false then
print("white off")
else
print("white failed")
end


pinktest()
if pink == true then
print("pink on")
elseif pink == false then
print("pink off")
else
print("pink failed")
end