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

Redstone Color's Code

Started by Privexx, 29 August 2017 - 11:05 PM
Privexx #1
Posted 30 August 2017 - 01:05 AM
Hi, I'm noob in at LUA coding. I'm working in a spawner controlled by redstone. I've modified a little bit a code that I found in youtube, because I need to use it whit bundled cable. Unfortunately I get error at 26 line: Expected string, number. So, how can I fix it? I'm using the touchpoint api's Lyqyd. The code is unfinished, i'm testing it before ending it. Thanks

os.loadAPI("touchpoint")

mon = peripheral.wrap("right")

local t1 = touchpoint.new("right")
local t = t1

function writeButtons()
t1:add("Mobs", nil, 2, 2, 18, 6, colors.red, colors.lime)
t1:add("Blazes", nil, 22, 2, 38, 6, colors.red, colors.lime)
t1:add("Skeletons", nil, 2, 8, 18, 12, colors.red, colors.lime)
t1:add("Wither", nil, 22, 8, 38, 12, colors.red, colors.lime)
t1:add("Villagers", nil, 2, 14, 18, 18, colors.red, colors.lime)
t1:add("Pechs", nil, 22, 14, 38, 18, colors.red, colors.lime)
t = t1
t:draw()
end

function checkRs()
  if rs.getBundledInput("back", colors.white) == true then t:toggleButton("Mobs") end
  if rs.getBundledInput("back", colors.orange) == true then t:toggleButton("Blazes") end
  if rs.getBundledInput("back", colors.magenta) == false then t:toggleButton("Skeletons") end
end

function toggleRs(rsOut)
rs.setBundledOutput(rsOut, not rs.getBundledOutput(rsOut))
end

function checkClick(p1)
  if p1 == "Mobs" then
	toggleRs("back", 1)
	--rs.setBundledOutput("back", 1)
  end
end

writeButtons()
checkRs()

while true do
local event, p1 = t:handleEvents(os.pullEvent())
  if event == "button_click" then
	t:toggleButton(p1)
	print(p1)
	checkClick(p1)
  end
end
Dog #2
Posted 30 August 2017 - 03:48 AM
Bundled cable requires a side and a color (string and number). On line 26 you have essentially provided two booleans. Instead of

function toggleRs(rsOut)
  rs.setBundledOutput(rsOut, not rs.getBundledOutput(rsOut))
end

try something like this…

function toggleRs(side, color)
  if colors.test(rs.getBundledOutput(side), color) then --# if the color is already switched on then...
    rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color)) --# ... switch it off by subtracting the color from the other present colors
  else --# if the color is currently off then...
    rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color)) --# switch it on by combining the color with the other present colors
  end
end

EDIT: Added comments to code (d'oh!)
Edited on 30 August 2017 - 01:52 AM
Bomb Bloke #3
Posted 30 August 2017 - 03:52 AM
Note that under CC1.74, colours.subtract() is bugged. If "color" is enabled, using "rs.getBundledOutput(side) - color" instead will produce the desired effect.
Privexx #4
Posted 31 August 2017 - 11:24 AM
Thank you for your help guys!! :)/> :P/> Now it works perfectly. At the moment there aren't any bugs, and I'm running CC 1.5, at minecraft 1.6.4. The code is almost finished. Here is:

os.loadAPI("touchpoint")

mon = peripheral.wrap("top")

local t1 = touchpoint.new("top")
local t = t1

function writeButtons()
t1:add("Mobs", nil, 2, 2, 18, 6, colors.red, colors.lime)
t1:add("Blazes", nil, 22, 2, 38, 6, colors.red, colors.lime)
t1:add("Skeletons", nil, 2, 8, 18, 12, colors.red, colors.lime)
t1:add("Pechs", nil, 22, 8, 38, 12, colors.red, colors.lime)
t1:add("Villagers", nil, 2, 14, 18, 18, colors.red, colors.lime)
t1:add("Villagers Trap", nil, 22, 14, 38, 18, colors.red, colors.lime)
t = t1
t:draw()
end

function checkRs()
  if rs.getBundledInput("back", colors.white) == true then t:toggleButton("Mobs") end --Lights
  if rs.getBundledInput("back", colors.orange) == true then t:toggleButton("Mobs") end --Door
  if rs.getBundledInput("back", colors.magenta) == true then t:toggleButton("Blazes") end --Spawner
  if rs.getBundledInput("back", colors.lightBlue) == true then t:toggleButton("Blazes") end --Door
  if rs.getBundledInput("back", colors.yellow) == true then t: toggleButton("Skeletons") end --Spawner
  if rs.getBundledInput("back", colors.lime) == true then t:toggleButton("Skeletons") end --Door
  if rs.getBundledInput("back", colors.pink) == true then t:toggleButton("Pechs") end --Spawner
  if rs.getBundledInput("back", colors.gray) == true then t:toggleButton("Pechs") end --Door
  if rs.getBundledInput("back", colors.cyan) == true then t:toggleButton("Villagers") end --Spawner
  if rs.getBundledInput("back", colors.purple) == true then t:toggleButton("Villagers") end --Door
  if rs.getBundledInput("back", colors.blue) == true then t:toggleButton("Villagers Trap") end --Trap
end

function toggleRs(side, color)
  if colors.test(rs.getBundledOutput(side), color) then
    rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
  else
    rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
  end
end
	
function checkClick(p1)
  if p1 == "Mobs" then
    toggleRs("back", colors.white) --Lights
    toggleRs("back", colors.orange) --Door
  end
  if p1 == "Blazes" then
    toggleRs("back", colors.magenta) --Spawner
    toggleRs("back", colors.lightBlue) --Door
  end
  if p1 == "Skeletons" then
    toggleRs("back", colors.yellow) --Spawner
    toggleRs("back", colors.lime) --Door
  end
  if p1 == "Pechs" then
    toggleRs("back", colors.pink) --Spawner
    toggleRs("back", colors.gray) --Door
  end
  if p1 == "Villagers" then
    toggleRs("back", colors.cyan) --Spawner
    toggleRs("back", colors.purple) --Door
  end
  if p1 == "Villagers Trap" then
    toggleRs("back", colors.blue) --Trap
  end 
end

writeButtons()
checkRs()

while true do
local event, p1 = t:handleEvents(os.pullEvent())
  if event == "button_click" then
    t:toggleButton(p1)
    print(p1)
    checkClick(p1)
  end
end