Coding Newb, need help mainly with User Input (Solved)
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Coding Newb, need help mainly with User Input (Solved)
I want to make a choose your own adventure style book, and I also want to do so with character customization, however, I don't know how to do the user input name thing; can someone please show me the code and explain? I've looked and can't find anything in the code. As far as I can see the tutorial game only says that it's possible; not how to do it.
I can barely even get it to run, but hopefully I'll muddle through on my own when I get to the other parts. xD Your help is greatly appreciated.
I can barely even get it to run, but hopefully I'll muddle through on my own when I get to the other parts. xD Your help is greatly appreciated.
Last edited by realaniram on Tue Sep 20, 2011 5:58 pm, edited 1 time in total.
Re: Coding Newb, need help mainly with User Input
This is the code for inputting a name.
"What is my name?" is the text that will display at the top, like so:
You can change that to whatever you want.
"u" is similar to when you define a character's name. Before a line of dialogue, if you want the player's inputted name to show up at the top of the box, you would put u, like this:
u "Gee it sure is a nice day!"
It doesn't have to be u, I just find that easy to remember since it's like "you".
The "pootzone" there is what the player's name will automatically be if they just press enter instead of putting in a name. It is the default name for the player. Obviously it doesn't have to be pootzone.
If you want another character to say the player's name, you would write %(u)s where the name would be.
x "Hi, %(u)s!"
Hope that helps!
Code: Select all
$ u = renpy.input("What is my name?")
$ u = u.strip()
if u == "":
$ u="pootzone"
You can change that to whatever you want.
"u" is similar to when you define a character's name. Before a line of dialogue, if you want the player's inputted name to show up at the top of the box, you would put u, like this:
u "Gee it sure is a nice day!"
It doesn't have to be u, I just find that easy to remember since it's like "you".
The "pootzone" there is what the player's name will automatically be if they just press enter instead of putting in a name. It is the default name for the player. Obviously it doesn't have to be pootzone.
If you want another character to say the player's name, you would write %(u)s where the name would be.
x "Hi, %(u)s!"
Hope that helps!
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Re: Coding Newb, need help mainly with User Input
It's giving me an indentation error for the u.strip line. Why? xD
Re: Coding Newb, need help mainly with User Input
Oh! For some reason when I pasted it, it indented that part. It should look like this in the editor:
edit: Apparently copying from my little code box up there will copy it correctly. Copy code out straight instead of writing it again yourself from now on, you'll probably have better results (assuming that's what you did)
edit: Apparently copying from my little code box up there will copy it correctly. Copy code out straight instead of writing it again yourself from now on, you'll probably have better results (assuming that's what you did)
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Re: Coding Newb, need help mainly with User Input
Okay, it's not giving me problems on that now (although pasting it did still do the indent, but I knew how it was supposed to look). But now it's saying something about the ui.key. xD I'm doing horribly for my first time. Beginner's luck doesn't apply to me, I guess.
The whole indent thing is a little new to me. When I coded in C++ a couple of years ago the indents in our program were just to help us organize functions and such.
The whole indent thing is a little new to me. When I coded in C++ a couple of years ago the indents in our program were just to help us organize functions and such.
Re: Coding Newb, need help mainly with User Input
Maybe just take the code straight from the cookbook then, which is found here: http://www.renpy.org/wiki/renpy/doc/coo ... r_own_name
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Re: Coding Newb, need help mainly with User Input
Okay, it's working well now, but the %(u)s thing won't work. It'll just put that instead of the name, maybe I'm not declaring the variable right?
Re: Coding Newb, need help mainly with User Input
Did you replace player_name in the cookbook thing with u? If you leave it as player_name you have to do %(player_name)s.
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Re: Coding Newb, need help mainly with User Input
Yeah, I replaced it with my variable name, f. I've made sure that all of the labels/names were changed... Hm. Do you know if there's an alternate code for that?
EDIT:
Here's a screen shot. The dialogue label changes, but she can't even say her own name.
EDIT:
Here's a screen shot. The dialogue label changes, but she can't even say her own name.
- Attachments
-
- screenshot0001.png (4.5 KiB) Viewed 1981 times
- Camille
- Eileen-Class Veteran
- Posts: 1227
- Joined: Sat Apr 23, 2011 2:43 pm
- Completed: Please see http://trash.moe
- Projects: the head well lost
- Organization: L3
- Tumblr: narihira
- Deviantart: crownwaltz
- itch: lore
- Contact:
Re: Coding Newb, need help mainly with User Input
If you're using the new Ren'Py 6.13, you need to define it as [f] instead of %(f)s because the syntax for that changed.
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Re: Coding Newb, need help mainly with User Input
Ahhh. Thanks, Camille.
So [] are only needed in the %[f]s? Or anything else that would call for () like that?
So [] are only needed in the %[f]s? Or anything else that would call for () like that?
- Camille
- Eileen-Class Veteran
- Posts: 1227
- Joined: Sat Apr 23, 2011 2:43 pm
- Completed: Please see http://trash.moe
- Projects: the head well lost
- Organization: L3
- Tumblr: narihira
- Deviantart: crownwaltz
- itch: lore
- Contact:
Re: Coding Newb, need help mainly with User Input
You don't need the % and s anymore. When you want to show a variable, it's just [variable].
-
- Regular
- Posts: 33
- Joined: Sun Sep 18, 2011 1:36 pm
- Projects: Shaeyu jun Ikkshaelun
- Contact:
Re: Coding Newb, need help mainly with User Input
Ah, okay. That's a lot simpler now. Thanks so much!
Who is online
Users browsing this forum: Bing [Bot]