How do I make a program run by itself when weather changes ?

Started by folglaive, Apr 05, 2024, 05:26 PM

Previous topic - Next topic

folglaive

Hello everyone,

Sorry in advance if my question is dumb, I'm brand new to LUA and CC, actually learning with passion :)

I'm currently trying to make a program that will output automatically a string to my monitor whenever the weather changes.

For this, I'm using Advanced peripheral's Environment Detector which can detec isRaining and isSunny.

The program works well when I manually launch it and detects the weather changes perfectly, the only thing is that I'd like to make it "automatic" but I'm quite lost.

My current code is as follows, I'm lost if I have to go get a os.pullEvent, a while loop, or else honestly and was wondering if you guys could have an answer ?


local detector = peripheral.find("environmentDetector")
local my_monitor = peripheral.wrap("top")

my_monitor.clear()


if  detector.isRaining() then
    my_monitor.setCursorPos(1,1)
    my_monitor.write ("It is raining")

else detector.isSunny()
    my_monitor.setCursorPos(1,1)
    my_monitor.write ("It is Sunny")
end


Thanks A LOT in advance !!!!

folglaive

Hello back !

I made it work :)

local detector = peripheral.find("environmentDetector")
local my_monitor = peripheral.wrap("top")

my_monitor.clear()

while true do
if  detector.isRaining() then
    my_monitor.clear()
    my_monitor.setCursorPos(1,1)
    my_monitor.write ("It is raining")

else detector.isSunny()
    my_monitor.clear()
    my_monitor.setCursorPos(1,1)
    my_monitor.write ("It is Sunny")
end
end