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

Serious programming help needed!

Started by Tassyr, 31 October 2012 - 05:37 AM
Tassyr #1
Posted 31 October 2012 - 06:37 AM
So I'm attempting to use computercraft to run a large system. The idea is that while a lever is on, it will output power to another line, and if the lever is off, it won't.

Also I plan to have an 'interrupt' command that will -temporarily- disable things, but resume them later… but I haven't got that far yet. Right now i'm still trying to get the first half to run.

function clear()
term.clear()
term.setCursorPos(1,1)
end

while true do
clear()
local event, param1 = os.pullevent("redstone")
local redState=rs.testBundledInput("bottom", colors.white)
if redState then
redstone.setBundledOutput("bottom", colors.red)
else
redstone.setBundledOutput("bottom", 0)
end
end


that's as far as I got. But every time I run it I get an error stating that: "Bios:206: [string "shield"]:14 ')' expected.


Help… I'm new to lua!
KaoS #2
Posted 31 October 2012 - 07:03 AM
local redState=rs.testBundledInput("bottom", color.white)

needs colors not color
Tassyr #3
Posted 31 October 2012 - 07:05 AM
Fixed that- that's an error in my reproduced code, not the actual code in tekkit. Still has the error. XP
Luanub #4
Posted 31 October 2012 - 07:14 AM
This:

local event, param1 = os.pullevent("redstone")

--should be

local event, param1 = os.pullEvent("redstone")

I don't see anything else wrong with what you have posted.
Tassyr #5
Posted 31 October 2012 - 07:41 AM
Corrected that- it still throws up an 'expected )' error about

redstone.setBundledOutput("bottom", 0)

But that's a standard code… I used it in another computer on the same map! Did I fry something in minecraft itself?
Luanub #6
Posted 31 October 2012 - 07:46 AM
Yeah that should work. I'll be to where I can play with it here shortly.

Go through and take a close look at it, make sure you don't have a period instead of comma or something like that.
Tassyr #7
Posted 31 October 2012 - 07:51 AM
That was it. I had a period in place of a comma x.x thanks for helping me out- you're awesome!

Since you seem to be in the knowhow, however… how would I make an 'interrupt' where I could say, tap a button, and have it break the output for a few seconds…?
Luanub #8
Posted 31 October 2012 - 08:31 AM
Just remove you're event filter and use the key events.

while true do
clear()
local event, param1 = os.pullEvent()
if event == "redstone" then
  local redState=rs.testBundledInput("bottom", colors.white)
  if redState then
	redstone.setBundledOutput("bottom", colors.red)
  else
	redstone.setBundledOutput("bottom", 0)
  end
elseif event == "key" then
  if param1 == 16 then -- q was pressed can change to what key you want or just remove so any key will work
   sleep(5) -- change the sleep to what you want it to do
  end
end
end

Here is a link to the key codes in case you do not know what they are: http://www.minecraftwiki.net/wiki/Key_Codes
Tassyr #9
Posted 31 October 2012 - 08:51 AM
Just remove you're event filter and use the key events.

while true do
clear()
local event, param1 = os.pullEvent()
if event == "redstone" then
  local redState=rs.testBundledInput("bottom", colors.white)
  if redState then
	redstone.setBundledOutput("bottom", colors.red)
  else
	redstone.setBundledOutput("bottom", 0)
  end
elseif event == "key" then
  if param1 == 16 then -- q was pressed can change to what key you want or just remove so any key will work
   sleep(5) -- change the sleep to what you want it to do
  end
end
end

Here is a link to the key codes in case you do not know what they are: http://www.minecraft.../wiki/Key_Codes


er, sorry I wasn't clear- I meant a -redstone- button specifically, instead. >.< and how would a single 'wait' deactivate things temporarily? o.o
Luanub #10
Posted 31 October 2012 - 09:18 AM
What exactly are you wanting to deactivate? Turn off all of the bundled output?

And to pick up a signal from a button/lever/etc… leave your os.pullEvent() with the redstone filter just add an other if statement to check to see if it is getting a redstone signal to the side that you have the button wired up to.

local event,param1 = os.pullEvent("redstone")
local redState=rs.testBundledInput("bottom", colors.white)
if redState then
  redstone.setBundledOutput("bottom", colors.red)
else
  redstone.setBundledOutput("bottom", 0)
end
if rs.getInput("change to your side") then
  --to deactivate the bundled
  local wasOn = rs.getBundledInput("bottom")
  rs.setBundledOutput("bottom", 0)
  os.pullEvent("key") -- will wait for a key press, change to what you want sleep/redstone signal etc..
  rs.setBundledOutput("bottom", wasOn)
end
Tassyr #11
Posted 31 October 2012 - 09:29 AM
aright, so here's exactly what I'm doing. I've set up a shield generator that runs if a lever inside it is on, with a small delay in case anyone needs to get out before it goes up/etc. I've also given a few people remote redstone controls, so they can deactivate it and slip inside should they somehow be trapped OUTSIDE.

I've wired the 'main' lever to white, the output to the shield to red, and the 'remote' redstone to black.

basically what I want is that if you get a signal from black it temporarily cuts the power if the shield is on. sort of a five-to-ten second 'interrupt.'
Luanub #12
Posted 31 October 2012 - 09:56 AM
Ahh very simple here you go:


while true do
clear()
local event,param1 = os.pullEvent("redstone")
local redState=rs.testBundledInput("bottom", colors.white)
if redState then
  redstone.setBundledOutput("bottom", colors.red)
else
  redstone.setBundledOutput("bottom", 0)
end
if rs.testBundledInput("bottom", colors.black) then

  rs.setBundledOutput("bottom", 0)
  sleep(5) --adjust accordingly
  if redState then
    rs.setBundledOutput("bottom", colors.red)
  end
end
end
Tassyr #13
Posted 31 October 2012 - 10:20 AM
Aha, thanks. Will test this tomorrow morning :P/>/>
Tassyr #14
Posted 01 November 2012 - 12:59 AM
It worked, thanks! :P/>/>