Coding Newb, need help mainly with User Input (Solved)

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
realaniram
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)

#1 Post by realaniram »

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.
Last edited by realaniram on Tue Sep 20, 2011 5:58 pm, edited 1 time in total.

corny
Regular
Posts: 41
Joined: Sun Sep 18, 2011 1:08 pm
Contact:

Re: Coding Newb, need help mainly with User Input

#2 Post by corny »

This is the code for inputting a name.

Code: Select all

$ u = renpy.input("What is my name?")
    $ u = u.strip()
    if u == "":
        $ u="pootzone"
"What is my name?" is the text that will display at the top, like so:

Image

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!

realaniram
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

#3 Post by realaniram »

It's giving me an indentation error for the u.strip line. Why? xD

corny
Regular
Posts: 41
Joined: Sun Sep 18, 2011 1:08 pm
Contact:

Re: Coding Newb, need help mainly with User Input

#4 Post by corny »

Oh! For some reason when I pasted it, it indented that part. It should look like this in the editor:

Image

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)

realaniram
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

#5 Post by realaniram »

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.

corny
Regular
Posts: 41
Joined: Sun Sep 18, 2011 1:08 pm
Contact:

Re: Coding Newb, need help mainly with User Input

#6 Post by corny »

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

realaniram
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

#7 Post by realaniram »

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?

corny
Regular
Posts: 41
Joined: Sun Sep 18, 2011 1:08 pm
Contact:

Re: Coding Newb, need help mainly with User Input

#8 Post by corny »

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.

realaniram
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

#9 Post by realaniram »

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.
Attachments
screenshot0001.png
screenshot0001.png (4.5 KiB) Viewed 1982 times

User avatar
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

#10 Post by Camille »

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.

realaniram
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

#11 Post by realaniram »

Ahhh. Thanks, Camille.

So [] are only needed in the %[f]s? Or anything else that would call for () like that?
Shaeyu jun Ikkshaelun-- A work in progress.

Forever Newb

User avatar
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

#12 Post by Camille »

You don't need the % and s anymore. When you want to show a variable, it's just [variable].

realaniram
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

#13 Post by realaniram »

Ah, okay. That's a lot simpler now. Thanks so much!
Shaeyu jun Ikkshaelun-- A work in progress.

Forever Newb

Post Reply

Who is online

Users browsing this forum: snotwurm