How would I go about making a program I am writing recieve user input through typing?
The context of this is for an RPG that requires knowing if a user types up down left right, etc.
2
Reading User Input
Started by MadCrayolaz, Aug 07 2012 12:46 AM
12 replies to this topic
#1
Posted 07 August 2012 - 12:46 AM
#2
Posted 07 August 2012 - 12:53 AM
You mean using key presses? You need to use events. Here's a simple example:
while true do local evt, key = os.pullEvent("key") print("Key ", key, " pressed") end
#3
Posted 07 August 2012 - 01:03 AM
MysticT, on 07 August 2012 - 12:53 AM, said:
You mean using key presses? You need to use events. Here's a simple example:
while true do local evt, key = os.pullEvent("key") print("Key ", key, " pressed") end
I'll give a different example.
I am also working on a login system.
I want to promp the user to enter their username.
How would I do that?
#4
Posted 07 August 2012 - 01:06 AM
Oh, that's easier.
local input = read() print("You entered: ", input)
#5
Posted 07 August 2012 - 02:57 AM
Danke />
#6
Posted 07 August 2012 - 07:39 PM
Another thing, if I wanted there to be text prefacing the place to type, how would I do that?
I want it to look like this:
Username: <entered text>
I want it to look like this:
Username: <entered text>
#7
Posted 07 August 2012 - 07:41 PM
Using write:
write("Username: ") local username = read()You should check out the wiki to see what functions are in CC and what they do.
#8
Posted 07 August 2012 - 07:58 PM
MysticT, on 07 August 2012 - 07:41 PM, said:
Using write:
write("Username: ") local username = read()You should check out the wiki to see what functions are in CC and what they do.
That's just it, I did that, but it put it on a new line, and I didn't specify a new line char.
#9
Posted 07 August 2012 - 08:07 PM
Did you use write("text") or print("text")?
#10
Posted 07 August 2012 - 08:18 PM
It was write, but after restarting the server, it seemed to fix. Thanks.
#11
Posted 08 August 2012 - 03:38 AM
Need any tips writing the program or have you made text adventures in console programs before?
#12
Posted 12 October 2016 - 10:41 PM
What about storing numbers from read()?
#13
Posted 13 October 2016 - 12:39 AM
local yourVar = tonumber( read() )
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users