16 posts
Posted 18 October 2012 - 06:38 PM
hello!
This is the first cc program i have made all by myself no copying parts from others :)/>/>
but i feel that it is not that good :P/>/> beacause it is restarting the pc evry time to check. how do i create a loop? or what ever it is called so i don't need to restart the pc all the time?
the program is the "startup" program to the pc that activates the forcefield who protects the house against a nuclear explotion.
function startalarm()
rs.setOutput("top", true)
sleep(1.7)
rs.setOutput("top", false)
end
function force()
if redstone.getInput( "left" ) then
startalarm()
rs.setOutput("right", true)
sleep(2)
if redstone.getInput( "left" ) == true then
force()
else
end
end
end
function starter()
force()
sleep(3)
os.reboot()
end
starter()
864 posts
Location
Sometime.
Posted 18 October 2012 - 06:41 PM
hello!
This is the first cc program i have made all by myself no copying parts from others :)/>/>
but i feel that it is not that good :P/>/> beacause it is restarting the pc evry time to check. how do i create a loop? or what ever it is called so i don't need to restart the pc all the time?
the program is the "startup" program to the pc that activates the forcefield who protects the house against a nuclear explotion.
function startalarm()
rs.setOutput("top", true)
sleep(1.7)
rs.setOutput("top", false)
end
function force()
if redstone.getInput( "left" ) then
startalarm()
rs.setOutput("right", true)
sleep(2)
end
end
function starter()
force()
sleep(3)
os.reboot()
end
starter()
There you go, you don't need all that other unnecessary stuff.
16 posts
Posted 18 October 2012 - 06:46 PM
There you go, you don't need all that other unnecessary stuff.
Thanks ;D but it still reboots all the time, does it need to? :P/>/>
16 posts
Posted 18 October 2012 - 06:47 PM
What if i want it to do nothing intil it gets a redstone signal? is that possible? :P/>/>
136 posts
Posted 18 October 2012 - 07:25 PM
repeat
--Put your code here
os.setTimer(.05)
until os.pullEvent() == "redstone"
This will run until it gets a redstone event (I'm pretty sure…).
The timer makes it so the os.pullEvent() will only pause your program for a maximum of 0.05 seconds (1 tick)
Edit: That is a terrible idea. Use this instead.
repeat
--Put your code here
until rs.getInput("back")
That will run until it gets redstone power from the back.
16 posts
Posted 18 October 2012 - 09:39 PM
repeat
--Put your code here
os.setTimer(.05)
until os.pullEvent() == "redstone"
This will run until it gets a redstone event (I'm pretty sure…).
The timer makes it so the os.pullEvent() will only pause your program for a maximum of 0.05 seconds (1 tick)
Edit: That is a terrible idea. Use this instead.
repeat
--Put your code here
until rs.getInput("back")
That will run until it gets redstone power from the back.
Thank you! :P/>/> that will make it atlest look alot better :)/>/>
2088 posts
Location
South Africa
Posted 18 October 2012 - 09:44 PM
You can do almost anything with lua…
16 posts
Posted 18 October 2012 - 09:59 PM
Thank you all! the program is now as good as it will ever be :P/>/> i'm happy with how it works now :)/>/>
here is the code if you want to take a look :)/>/>
function startalarm()
rs.setOutput("top", true)
end
function stopalarm()
rs.setOutput("top", false)
end
function force()
if redstone.getInput( "left" ) then
startalarm()
rs.setOutput("right", true)
sleep(2)
else
stopalarm()
rs.setOutput("right", false)
end
end
function starter()
force()
sleep(2)
os.reboot()
end
starter()
16 posts
Posted 18 October 2012 - 10:01 PM
and yes, i know i don't need a function for the starting and stopping of the redstone signal :P/>/> but i like the training :)/>/>
42 posts
Posted 19 October 2012 - 02:26 AM
i use a function if im typing something more then 10 times like if im constantly sending out a redstone signal i will make a function called redInOn() redInOff() so don't think its a bad thing + it good to train