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

First program

Started by Inumel, 09 May 2013 - 12:49 AM
Inumel #1
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 :)/>
Inumel #2
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/>
theoriginalbit #3
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"
Inumel #4
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!
Inumel #5
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
Inumel #6
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/>
theoriginalbit #7
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/r5xA91LQ

As 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.
Inumel #8
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/r5xA91LQ

As 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 :)/>
M4sh3dP0t4t03 #9
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'
Inumel #10
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!
theoriginalbit #11
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.
superaxander #12
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
theoriginalbit #13
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?
thegreatstudio #14
Posted 09 May 2013 - 09:01 AM
Hmm. Well actually the program is kinda buggy it gives me an error at the bios.
theoriginalbit #15
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…
tonkku107 #16
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
PixelToast #17
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
Lyqyd #18
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.
superaxander #19
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…
Inumel #20
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
tonkku107 #21
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