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

[Help] Updating string in a loop

Started by Shazh, 07 April 2015 - 01:43 PM
Shazh #1
Posted 07 April 2015 - 03:43 PM
Hello. I am trying to make a graphic of my Mana Pool (from Botania) based on a redstone signal. Its currently working, but I dont know how can I update the graphic, because the variable is defined at the beggining of the program, so if the rs signal changes it doesnt update. I tried re-defining the rs string but it breaks the while loop so the function getClick() (from DW20's button api) doesnt work… Any ideas of how can I solve this? Thanks!

PASTEBIN

button api: pastebin get 6JdU2ckP button (http://pastebin.com/6JdU2ckP)

mana program: pastebin get 1bWQhi2u mana (http://pastebin.com/1bWQhi2u)
ItsRodrick #2
Posted 07 April 2015 - 04:13 PM
First: you are re-defining the Redstone API (rs), so you shoukd change the var in line 5 (and other lines that use it) to something like rsMana…

You could create a function like this to automatically update the redstone input:
local function updateRedstone()
  while true do
    os.pullEvent("redstone") --yields til a redstone update
    rsMana = rs.getAnalogInput("top")
    mana() --updates monitor
  end
end

Also, put the function getClick() in a while true do loop, and put this instead of the last loop:
parallel.waitForAny(updateRedstone,getClick) --run both functions at the same time
Shazh #3
Posted 07 April 2015 - 08:07 PM
Thanks dude! Finally its working!! That parallel.waitForAny was the key.

Thanks again.