4 posts
Posted 11 March 2013 - 03:14 AM
Title: [Lua][Question] Can someone help me with a program?
Hi, I'm really new to CC, and I'm trying to create a farm with a melee turtle.
1. What is the syntax for a turtle to detect a redstone pulse?
2. How do you make a loop for x amount of times?
3. Can someone point me in the right direction for functions?
42 posts
Posted 12 March 2013 - 03:50 AM
I dont know much about turtles but i think
Redstone.getInput( String Side )
A For loop is a nice loop. i is the count of the loop
for i = 1,x do
end
To make a function type
local function functionName()
end
To call a function type
functionName()
148 posts
Posted 12 March 2013 - 04:08 AM
So you're probably thinking of something like this:
while true do
os.pullEvent("redstone") --Will wait until any redstone input changes
if rs.getInput(side) then --Will check if the redstone on the specified side has changed, if not it scips the content of the if-statement.
--Replace side with any side
for i = 1, x do --Will loop through x amount of times. Don't forget to replace x with a number :)/>/>
turtle.attack() --Will attack (meele turtle)
end
break --This breaks the current loop (that's the while loop). If you don't want that remove it
end
--End of code enclosed by the while loop, will restart at the top again.
end
Edit: This code doesn't need to be a function, it will run just fine if you save it in a file.
If you still want it to be a function, write a function whatever() in the line before the while loop and another end at the end of the code.