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

RedPower bundled pulser

Started by PatrikF1, 08 November 2014 - 12:15 PM
PatrikF1 #1
Posted 08 November 2014 - 01:15 PM
Is there a way to read an input an them pulse redpowers bundled cable the number of times the input

print(" How Many?")
input = read()
a = input * 5
b = input
print("Gold On The Way")
rs.setBundledOutput("back".colors.red)
Its The last line that needs to be replaced i think
Edited on 08 November 2014 - 07:02 PM
Dragon53535 #2
Posted 09 November 2014 - 12:24 AM
Firstly you have to of course make sure that it works. Which it might, depending on the mods you have installed. And then you're going to need a loop. For your loop you're going to need a for loop and your "b" variable doesn't need to exist.


for q = 1, a do --# Starting at 1, with q being a new variable, and ending at a, increment by 1
  rs.setBundledOutput("back",colors.red) --#You had a period, needed a comma between back and colors
  sleep(0)--#Make it wait a second
  rs.setBundledOutput("back",0) --#Turn off all bundled output.
  sleep(0) --#Really it waits a game tick.
end
This loops through the code until q == a and once it does, it doesn't run through anymore
Edited on 08 November 2014 - 11:24 PM
Bomb Bloke #3
Posted 09 November 2014 - 12:47 AM
A couple of things, better to use tonumber() to convert read()'s output to an actual number. Generally read() returns a string - while Lua will let you treat strings as numbers (sometimes), it's better to be specific. Eg:

input = tonumber(read())

sleep(0) won't be sufficient - that'll only pause for a twentieth of a second (the minimum pause allowed, which happens to be the same time period as one MineCraft tick), but redstone only updates every tenth of a second. If you try to change state faster than that then you won't be able to detect the pulse at the other end. Use sleep(0.1) or perhaps even a greater time period.

You can read more on loops here.