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

reverting back to user input

Started by Crowdy199, 06 September 2012 - 06:21 PM
Crowdy199 #1
Posted 06 September 2012 - 08:21 PM
i am making a program on my computer the first part of the program is print whats your name then the user puts in there name then i want to have it print welcome and then the name they put in.

this is what i have so far i don t no how to have it print what they typed i put ?? where i am confused on what to do
—–
print("hello whats your name")
–they type in there name here there name is printed in the next line
print("welcome –there name i dont no how to put that there plz help thank u")
Magus #2
Posted 06 September 2012 - 08:25 PM
use the string.format function


name = read()
print(string.format( " The name is %s ", name))
Crowdy199 #3
Posted 06 September 2012 - 08:26 PM
thank u
ben657 #4
Posted 06 September 2012 - 08:28 PM
Use string concatenation, just do "string"..variable
so:

print("Hello, what's your name?")
name = read()
print("Welcome,"..name)
Crowdy199 #5
Posted 06 September 2012 - 08:30 PM
guys i got another quetion can i make it so that there name is saved into the code of a program called names automasticly when they type it
ben657 #6
Posted 06 September 2012 - 08:31 PM
guys i got another quetion can i make it so that there name is saved into the code of a program called names automasticly when they type it
You mean like a save file? so it has a list of peoples names?
Crowdy199 #7
Posted 06 September 2012 - 08:32 PM
yah just like that
ben657 #8
Posted 06 September 2012 - 08:35 PM
<Shameless Self Promotion>
Well, i've just released an API which helps you save data to a file, so you could use that for a quick solution:
Here
</Shameless Self Promotion>

Or you can read up on the fs API on the wiki and write your own functions to sort out the data
There
Crowdy199 #9
Posted 06 September 2012 - 08:43 PM
listen i suck at tekkit can u be more specfic and acutly type the code i need for this exact situation
ben657 #10
Posted 06 September 2012 - 08:45 PM
I'll give you a hand in a little when i'm not busy, but really, it's a much better idea to at least read through the docs on the wiki, or use somebody elses API, it'll help you get better.
sjele #11
Posted 06 September 2012 - 08:46 PM

while true do
write("What is you're name: ")
name = read()
file = fs.open("filename", "w") open the file filename in write mode
file.writeLine(name)  --Writes the variable name to the file filename
file.close()  --Prevents it messing up
end

I belive that works
Crowdy199 #12
Posted 06 September 2012 - 08:50 PM
it says on line 4 = expected
ben657 #13
Posted 06 September 2012 - 08:53 PM
it says on line 4 = expected
put '–' before the second "open" on line 4, without the quotes