Jump to content




reverting back to user input


  • You cannot reply to this topic
12 replies to this topic

#1 Crowdy199

  • Validating
  • 34 posts

Posted 06 September 2012 - 07: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")

#2 Magus

  • New Members
  • 14 posts

Posted 06 September 2012 - 07:25 PM

use the string.format function

name = read()
print(string.format( " The name is %s ", name))


#3 Crowdy199

  • Validating
  • 34 posts

Posted 06 September 2012 - 07:26 PM

thank u

#4 ben657

  • Members
  • 65 posts

Posted 06 September 2012 - 07:28 PM

Use string concatenation, just do "string"..variable
so:
print("Hello, what's your name?")
name = read()
print("Welcome,"..name)


#5 Crowdy199

  • Validating
  • 34 posts

Posted 06 September 2012 - 07: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

#6 ben657

  • Members
  • 65 posts

Posted 06 September 2012 - 07:31 PM

View PostCrowdy199, on 06 September 2012 - 07:30 PM, said:

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?

#7 Crowdy199

  • Validating
  • 34 posts

Posted 06 September 2012 - 07:32 PM

yah just like that

#8 ben657

  • Members
  • 65 posts

Posted 06 September 2012 - 07: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

#9 Crowdy199

  • Validating
  • 34 posts

Posted 06 September 2012 - 07:43 PM

listen i suck at tekkit can u be more specfic and acutly type the code i need for this exact situation

#10 ben657

  • Members
  • 65 posts

Posted 06 September 2012 - 07: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.

#11 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 06 September 2012 - 07: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

#12 Crowdy199

  • Validating
  • 34 posts

Posted 06 September 2012 - 07:50 PM

it says on line 4 = expected

#13 ben657

  • Members
  • 65 posts

Posted 06 September 2012 - 07:53 PM

View PostCrowdy199, on 06 September 2012 - 07:50 PM, said:

it says on line 4 = expected
put '--' before the second "open" on line 4, without the quotes





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users