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

help please, this gives no sense to me that it ain't working

Started by nicolaieno, 13 August 2014 - 07:30 PM
nicolaieno #1
Posted 13 August 2014 - 09:30 PM

water="on"
function await()
repeat
  event, param1 = os.pullEvent()
  if water=="on" then
    water="off"
  elseif water=="off" then
    water="on"
  end
until event=="char" and param1=="17"
watercontrol()
end
function watercontrol()
  term.clear()
  term.setCursorPos(10,5)
  write("W: ")
  if water=="on" then
    redstone.setOutput("left", true)
    print("Water cooling: ".. water .. " ")
  elseif water=="off" then
    redstone.setOutput("left", false)
    print("Water cooling: ".. water)
  end
await()
end
watercontrol()
Cranium #2
Posted 13 August 2014 - 09:52 PM
Moved to Ask a Pro.
Could you tell us what error you're getting? The error includes the filename and line number, as well as the reason it's not working.
We just need more info as to what is not working.
TheOddByte #3
Posted 13 August 2014 - 10:33 PM
You're using the event system wrong

until event == "char" and param1 == "17"
because this would never be possible, the event 'char' returns the key pressed by it's id or what you could call it, so for example if I pressed the spacebar it would return ' ', now if I used "key" instead of "char" it would return 57 which is the keycode for spacebar( if I remember correctly )
So basically to fix that part you would have to change it to

until event == "key" and param1 == 17
or

until event == "char" and param1 == "w"

Now I agree with Cranium, a little more information would be good
Edited on 13 August 2014 - 09:04 PM
flaghacker #4
Posted 13 August 2014 - 10:43 PM
You're using the event system wrong

until event == "char" and param1 == "17"
because this would never be possible, the event 'char' returns the key pressed by it's id or what you could call it, so for example if I pressed the spacebar it would return ' ', now if I used "key" instead of "char" it would return 57 which is the keycode for spacebar( if I remember correctly )
So basically to fix that part you would have to change it to

until event == "key" and param1 == 17
or

until event == "key" and param1 == "w"

Now I agree with Cranium, a little more information would be good
You made a mistake, the second one has to be "char".
TheOddByte #5
Posted 13 August 2014 - 11:04 PM
You made a mistake, the second one has to be "char".
Whoops, edited now :)/>
Gumball #6
Posted 31 August 2014 - 04:55 AM
water = "on"
function await()
repeat
event, param1 = os.pullEvent()
if water == "on" then
water= "off"
elseif water == "off" then
water = "on"
end
until event == "char" and param1 == "17"
watercontrol()
end
function watercontrol()
term.clear()
term.setCursorPos(10,5)
write("W: ")
if water == "on" then
redstone.setOutput("left", true)
print("Water cooling: "..water " ")
elseif water=="off" then
redstone.setOutput("left", false)
print("Water cooling: ".. water)
end
await()
end
watercontrol()
Hope this help! :P/>
Edited on 31 August 2014 - 02:56 AM
TheOddByte #7
Posted 31 August 2014 - 06:11 PM
-Snip-
Please use code tags when posting code
[.code] Code here [./code] ( Without the period )
Gumball #8
Posted 13 September 2014 - 06:27 AM
..
Edited on 13 September 2014 - 04:28 AM
Dog #9
Posted 13 September 2014 - 06:48 AM
Not sure if this is the problem, but I see a recursion issue with watercontrol calling await, calling watercontrol, and on and on. This would probably be better handled with a loop. Additionally, variables/functions should be localized unless they're required to be global for some reason.