#1
Posted 14 December 2012 - 07:34 PM
Thanks, help will be much appricated.
#2
Posted 14 December 2012 - 07:38 PM
times = read() for i = 1, tonumber(times) do -- do stuff end
#3
Posted 14 December 2012 - 07:41 PM
TheOriginalBIT, on 14 December 2012 - 07:38 PM, said:
times = read() for i = 1, tonumber(times) do -- do stuff end
I'm very very new to programing in computercraft, would you mind explaining how i would use this in my programs? pretty please...
#4
Posted 14 December 2012 - 08:01 PM
Falco, on 14 December 2012 - 07:41 PM, said:
Ok so for starters we are declaring a new variable called "times".
We then are calling the read() function. This function is a system function that reads the input from the terminal and only continues the program after enter/return is pressed.
Next we have a for loop. We declare the variable "i" as the number for the loop, and assign it to 1. the comma is similar to the ; in other programming languages. we then call another system function called tonumber() which converts the string the user has entered to a number. this specifies the maximum for our for loop. end specifies where the loop will go back to the start.
for loops can also have another comma and a 3rd number, this number is the increment amount. for example
for i = 0, 6 do would mean it loops from 0 to 6 in the default increment of 1
for i = 0, 6, 2 do would loop from 0 to 6 in increments of 2
for i = 6, 0, -1 do would loop from 6 to 0 in decrements of 1
So in terms of your program you would have something like this
-- Code up to the point of where you want user input times = read() -- the program will pause here until the user hits enter for i = 1, tonumber(times) do -- here say if the user enters 5 if will loop from 1 to 5 -- what you want the script to do end -- end of loop -- continue program if required
hope this helps
EDIT: I feel i should also point out that everything after -- in lua is ignored as -- tells the compiler its a comment
using --[[ will ignore all code until it finds ]]
#5
Posted 14 December 2012 - 08:03 PM
#6
Posted 14 December 2012 - 08:07 PM
TheOriginalBIT, on 14 December 2012 - 08:01 PM, said:
Falco, on 14 December 2012 - 07:41 PM, said:
Ok so for starters we are declaring a new variable called "times".
We then are calling the read() function. This function is a system function that reads the input from the terminal and only continues the program after enter/return is pressed.
Next we have a for loop. We declare the variable "i" as the number for the loop, and assign it to 1. the comma is similar to the ; in other programming languages. we then call another system function called tonumber() which converts the string the user has entered to a number. this specifies the maximum for our for loop. end specifies where the loop will go back to the start.
for loops can also have another comma and a 3rd number, this number is the increment amount. for example
for i = 0, 6 do would mean it loops from 0 to 6 in the default increment of 1
for i = 0, 6, 2 do would loop from 0 to 6 in increments of 2
for i = 6, 0, -1 do would loop from 6 to 0 in decrements of 1
So in terms of your program you would have something like this
-- Code up to the point of where you want user input times = read() -- the program will pause here until the user hits enter for i = 1, tonumber(times) do -- here say if the user enters 5 if will loop from 1 to 5 -- what you want the script to do end -- end of loop -- continue program if required
hope this helps
EDIT: I feel i should also point out that everything after -- in lua is ignored as -- tells the compiler its a comment
using --[[ will ignore all code until it finds ]]
Wow thank you very much for this information, I'll be sure to read it untill it sticks in my head... YOU ARE A GOD!!!
No seriously thank you very much. Is there anyway I can give rep or anything on this forum?
JoshhT, on 14 December 2012 - 08:03 PM, said:
Thanks for attempting to help me, but help has been found.
#7
Posted 14 December 2012 - 08:11 PM
Falco, on 14 December 2012 - 08:07 PM, said:
No seriously thank you very much. Is there anyway I can give rep or anything on this forum?
Haha, no problems, anytime, seriously, just PM me (PM through profiles).
Yes there is a way to give rep. As to how, that is something I don't know how to do. I know that there is the "Vote this post up" green arrow. And I think there may be a "star rating" thingy on profiles (Click the persons photo).
#8
Posted 15 December 2012 - 01:41 AM
TheOriginalBIT, on 14 December 2012 - 08:11 PM, said:
Falco, on 14 December 2012 - 08:07 PM, said:
No seriously thank you very much. Is there anyway I can give rep or anything on this forum?
Haha, no problems, anytime, seriously, just PM me (PM through profiles).
Yes there is a way to give rep. As to how, that is something I don't know how to do. I know that there is the "Vote this post up" green arrow. And I think there may be a "star rating" thingy on profiles (Click the persons photo).
Thanks, I'll will try my hardest to give you REP of some sort, you are a fine addition to this very helpful community.
#9
Posted 15 December 2012 - 01:50 AM
Falco, on 15 December 2012 - 01:41 AM, said:
TheOriginalBIT, on 14 December 2012 - 08:11 PM, said:
Falco, on 14 December 2012 - 08:07 PM, said:
No seriously thank you very much. Is there anyway I can give rep or anything on this forum?
Haha, no problems, anytime, seriously, just PM me (PM through profiles).
Yes there is a way to give rep. As to how, that is something I don't know how to do. I know that there is the "Vote this post up" green arrow. And I think there may be a "star rating" thingy on profiles (Click the persons photo).
Thanks, I'll will try my hardest to give you REP of some sort, you are a fine addition to this very helpful community.
Why thank you kind sir or madam
#10
Posted 15 December 2012 - 03:29 AM
TheOriginalBIT, on 15 December 2012 - 01:50 AM, said:
Falco, on 15 December 2012 - 01:41 AM, said:
TheOriginalBIT, on 14 December 2012 - 08:11 PM, said:
Falco, on 14 December 2012 - 08:07 PM, said:
No seriously thank you very much. Is there anyway I can give rep or anything on this forum?
Haha, no problems, anytime, seriously, just PM me (PM through profiles).
Yes there is a way to give rep. As to how, that is something I don't know how to do. I know that there is the "Vote this post up" green arrow. And I think there may be a "star rating" thingy on profiles (Click the persons photo).
Thanks, I'll will try my hardest to give you REP of some sort, you are a fine addition to this very helpful community.
Why thank you kind sir or madam
Sir
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users