115 posts
Posted 09 May 2013 - 02:49 AM
Okay! So I made a program, and it's a silly one..! this is it
xval = 0
x = redstone.getInput("left")
print(x)
while x == true do
x = redstone.getInput("left")
xval = xval + 1
sleep(1)
print("Redstone was on for: " .. xval .. " seconds" )
if x == false then
print("Signal was shut off")
end
if xval == 50 then
rs.setOutput("top", true)
sleep(5)
rs.setOutput("top", false)
end
end
That's pretty much it, I am just learning LUA so this was something fun for me to do :)/>
115 posts
Posted 09 May 2013 - 02:52 AM
WHoops just realised this doesnt really belong in the turtle section! .. thats just where im coding it on :P/>
7508 posts
Location
Australia
Posted 09 May 2013 - 02:56 AM
It's good to see someone not making a door lock for their first program.
I have one question. What is the purpose of outputting a signal after 50 loops?
Also as for when you post in the wrong section, or if you wish a topic to be locked, press the 'report' link and type in your request for the moderator, i.e. something like "Wrong section, please move to x"
115 posts
Posted 09 May 2013 - 02:59 AM
The purpose of outputting after 60(Changed to one minute) is to see if I could, quite honestly! I am going to see if I can make a count down, to nothing particular! using while loops inside while loops.. changing from seconds, to minutes, to hours!
115 posts
Posted 09 May 2013 - 03:18 AM
An update to my silly program
sval = 0
mval = 0
hval = 0
x = redstone.getInput("left")
print(x)
while x == true and sval <= 60 do
x = redstone.getInput("left")
sval = sval + 1
sleep(1)
print("Redstone was on for: " .. sval .. " seconds" )
if x == false then
print("Signal was shut off")
end
while x == true and sval >= 60 do
x = redstone.getInput("left")
mval = mval + 1
sleep(60)
print("Redstone was on for: " .. mval .. " minutes")
if x == false then
print("Signal was shut off")
end
end
end
115 posts
Posted 09 May 2013 - 03:20 AM
Any suggestions, tips or if you just wanna tell me how much it sucks! I am always happy to hear :P/>
7508 posts
Location
Australia
Posted 09 May 2013 - 03:22 AM
Ok so here is a program that I just wrote that dives deeper into some of the powers of ComputerCraft that we can do. I have heavily commented the code, so I suggest you read all the comments and take a look at all the extra info links I provided too. I hope that me detailing this at an early stage in your programming will help you understand it easier, and be able to use some more powerful techniques in your future programs.
Program:
http://pastebin.com/r5xA91LQAs always if you have any questions about how any of the code works, of just want some more explanation feel free to ask or send me a PM and I will reply as soon as I can.
115 posts
Posted 09 May 2013 - 03:23 AM
Ok so here is a program that I just wrote that dives deeper into some of the powers of ComputerCraft that we can do. I have heavily commented the code, so I suggest you read all the comments and take a look at all the extra info links I provided too. I hope that me detailing this at an early stage in your programming will help you understand it easier, and be able to use some more powerful techniques in your future programs.
Program:
http://pastebin.com/r5xA91LQAs always if you have any questions about how any of the code works, of just want some more explanation feel free to ask or send me a PM and I will reply as soon as I can.
Thank you! I look forward to looking at this :)/>
570 posts
Location
Germany
Posted 09 May 2013 - 03:32 AM
Well it's a nice first program but I think this isn't really useful for something.
Edit: (talking to Theoriginalbit but im to lazy to quote it) why didn't you use os.pullevent("redstone") instead of this os.pullevent() and an if event == 'redstone'
115 posts
Posted 09 May 2013 - 03:35 AM
Well it's a nice first program but I think this isn't really useful for something.
No, definitely not! I am just having fun learning really, not trying to do anything too useful yet!
7508 posts
Location
Australia
Posted 09 May 2013 - 03:58 AM
Edit: (talking to theoriginalbit but im to lazy to quote it) why didn't you use os.pullevent("redstone") instead of this os.pullevent() and an if event == 'redstone'
Because there is a timer too.
620 posts
Location
Holland
Posted 09 May 2013 - 05:01 AM
Edit: (talking to theoriginalbit but im to lazy to quote it) why didn't you use os.pullevent("redstone") instead of this os.pullevent() and an if event == 'redstone'
Because there is a timer too.
and it still returns even if it's not a redstone event then it returns nil
7508 posts
Location
Australia
Posted 09 May 2013 - 08:25 AM
and it still returns even if it's not a redstone event then it returns nil
Huh? What now?
160 posts
Location
I am on your computer
Posted 09 May 2013 - 09:01 AM
Hmm. Well actually the program is kinda buggy it gives me an error at the bios.
7508 posts
Location
Australia
Posted 09 May 2013 - 09:19 AM
Hmm. Well actually the program is kinda buggy it gives me an error at the bios.
You have typed it out wrong as there are no errors in the OP code. Also your feedback is useless, when telling people about errors you should do the
same thing you do in the 'Ask a Pro' section; post the
full error message…
197 posts
Location
Finland
Posted 09 May 2013 - 10:31 AM
It's good to see someone not making a door lock for their first program.
haha! I would not make the door lock as my first program if would not have been requesting to do one.
I would have made an chat program cleverbot style.
Are you sure this is your FIRST program?
those xvals and svals looks soooooooooo advanced
2217 posts
Location
3232235883
Posted 09 May 2013 - 01:01 PM
a door lock was my first program :P/>
and why does everything good have to be first, it dosent matter
8543 posts
Posted 09 May 2013 - 01:40 PM
and it still returns even if it's not a redstone event then it returns nil
This is simply not true.
620 posts
Location
Holland
Posted 09 May 2013 - 02:12 PM
and it still returns even if it's not a redstone event then it returns nil
This is simply not true.
It has been that way for me…Weird…
115 posts
Posted 09 May 2013 - 03:07 PM
It's good to see someone not making a door lock for their first program.
haha! I would not make the door lock as my first program if would not have been requesting to do one.
I would have made an chat program cleverbot style.
Are you sure this is your FIRST program?
those xvals and svals looks soooooooooo advanced
This is my first program with computercraft and lua, but I know a bit of java and c++ too! and they arent all that different
197 posts
Location
Finland
Posted 10 May 2013 - 05:09 AM
It's good to see someone not making a door lock for their first program.
haha! I would not make the door lock as my first program if would not have been requesting to do one.
I would have made an chat program cleverbot style.
Are you sure this is your FIRST program?
those xvals and svals looks soooooooooo advanced
This is my first program with computercraft and lua, but I know a bit of java and c++ too! and they arent all that different
Lua is my first coding lagnuage i can actually write, not just understand a little