How to allow the player to choose their character?

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.
Message
Author
nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

How to allow the player to choose their character?

#1 Post by nanashine »

In my game, the player will always see everything as in "first-person". Their character will never show up in the scene.
But I wanted to let them choose their side imagem. It will be static and won't change according to the story. It's just like a profile picture.
I'll make a menu giving them the options of avatar they have, and those images will show up when they speak (as a side image).
This will not change the character they are, only the picture. Even because I let them choose their names.

I'm new on Renpy, so can you give me some help?
I wanted to know what code I should use to do this.
Thanks in advance.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

Tekamutt
Newbie
Posts: 8
Joined: Thu Nov 30, 2017 7:33 pm
Tumblr: fatrat66
Contact:

Re: How to allow the player to choose their character?

#2 Post by Tekamutt »

I've just learned how to do something similar so maybe it will help you.

I think you should look into DynamicImages. You can assign a variable to your portrait, and after the player chooses an avatar, assign a number to it.

First of all, say you have 3 different avatars to choose from, name them something like this:

Code: Select all

"character1.jpg"
"character2.jpg"
"character3.jpg"
Then at the top of your script, where the variables are inititally set, define one for your character's portraits and set up the dynamic image, something like this:

Code: Select all

default avatar = 1

image characterPortrait = DynamicImage("character[avatar].jpg" )
That will set the default character to 1, and prepare the dynamic image for later.

Then you let the player choose which one they want to be, so you need some kind of menu with the 'avatar' variable gets set. It'll look something like this:

Code: Select all

menu:
    "Choose Character 1":
        $ avatar = 1

    "Choose Character 2":
        $ avatar = 2

    "Choose Character 3":
        $ avatar = 3
Now that the player has chosen their avatar, you just need to reference it wherever you want the portrait image to appear. To show it, you just need to show the dynamic image that we set up:

Code: Select all

show characterPortrait
That should work. Let me know if you get stuck.

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: How to allow the player to choose their character?

#3 Post by nanashine »

Thank you so much! I'm gonna try it :)
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: How to allow the player to choose their character?

#4 Post by nanashine »

Unluckly it said:

I'm sorry, but an uncaught exception occurred.

While running game code:
File "renpy/common/00start.rpy", line 188, in script
python:
File "renpy/common/00start.rpy", line 189, in <module>
renpy.execute_default_statement(True)
File "game/script.rpy", line 27, in set_default
default avatar = 2
Exception: store.avatar is being given a default a second time.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to allow the player to choose their character?

#5 Post by Remix »

The hint is in the exception response:

Exception: store.avatar is being given a default a second time.

Are you using 'default avatar = ????' more than once?

After setting default once, just alter the value normally where needed (without using 'default' again)
Frameworks & Scriptlets:

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: How to allow the player to choose their character?

#6 Post by nanashine »

Thanks for your help :)
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
chungy
Regular
Posts: 26
Joined: Sun Sep 23, 2018 9:07 pm
Contact:

Re: How to allow the player to choose their character?

#7 Post by chungy »

Hello, i'm a complete noob at this, is this up to date? If not can someone who's experienced help me with this?
https://gutrotz.itch.io/
Check out my itch.io!

viewtopic.php?f=62&t=52002&p=496592#p496592
Sprite commissions closed!

User avatar
chungy
Regular
Posts: 26
Joined: Sun Sep 23, 2018 9:07 pm
Contact:

Re: How to allow the player to choose their character?

#8 Post by chungy »

Tekamutt wrote: Tue Dec 05, 2017 4:48 pm I've just learned how to do something similar so maybe it will help you.

I think you should look into DynamicImages. You can assign a variable to your portrait, and after the player chooses an avatar, assign a number to it.

First of all, say you have 3 different avatars to choose from, name them something like this:

Code: Select all

"character1.jpg"
"character2.jpg"
"character3.jpg"
Then at the top of your script, where the variables are inititally set, define one for your character's portraits and set up the dynamic image, something like this:

Code: Select all

default avatar = 1

image characterPortrait = DynamicImage("character[avatar].jpg" )
That will set the default character to 1, and prepare the dynamic image for later.

Then you let the player choose which one they want to be, so you need some kind of menu with the 'avatar' variable gets set. It'll look something like this:

Code: Select all

menu:
    "Choose Character 1":
        $ avatar = 1

    "Choose Character 2":
        $ avatar = 2

    "Choose Character 3":
        $ avatar = 3
Now that the player has chosen their avatar, you just need to reference it wherever you want the portrait image to appear. To show it, you just need to show the dynamic image that we set up:

Code: Select all

show characterPortrait
That should work. Let me know if you get stuck.
heyo is this up to date?
https://gutrotz.itch.io/
Check out my itch.io!

viewtopic.php?f=62&t=52002&p=496592#p496592
Sprite commissions closed!

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: How to allow the player to choose their character?

#9 Post by mitoky »

chungy wrote: Mon Sep 24, 2018 5:50 pm
Tekamutt wrote: Tue Dec 05, 2017 4:48 pm I've just learned how to do something similar so maybe it will help you.

I think you should look into DynamicImages. You can assign a variable to your portrait, and after the player chooses an avatar, assign a number to it.

First of all, say you have 3 different avatars to choose from, name them something like this:

Code: Select all

"character1.jpg"
"character2.jpg"
"character3.jpg"
Then at the top of your script, where the variables are inititally set, define one for your character's portraits and set up the dynamic image, something like this:

Code: Select all

default avatar = 1

image characterPortrait = DynamicImage("character[avatar].jpg" )
That will set the default character to 1, and prepare the dynamic image for later.

Then you let the player choose which one they want to be, so you need some kind of menu with the 'avatar' variable gets set. It'll look something like this:

Code: Select all

menu:
    "Choose Character 1":
        $ avatar = 1

    "Choose Character 2":
        $ avatar = 2

    "Choose Character 3":
        $ avatar = 3
Now that the player has chosen their avatar, you just need to reference it wherever you want the portrait image to appear. To show it, you just need to show the dynamic image that we set up:

Code: Select all

show characterPortrait
That should work. Let me know if you get stuck.
heyo is this up to date?
I think it is, at least i see no reason why it shouldnt be working.

User avatar
chungy
Regular
Posts: 26
Joined: Sun Sep 23, 2018 9:07 pm
Contact:

Re: How to allow the player to choose their character?

#10 Post by chungy »

mitoky wrote: Mon Sep 24, 2018 7:28 pm
I think it is, at least i see no reason why it shouldnt be working.
i'm not sure exactly where to put what variables since im pretty new at this. Is there an easy way to explain where to place things? Also ty for responding! ^__^
https://gutrotz.itch.io/
Check out my itch.io!

viewtopic.php?f=62&t=52002&p=496592#p496592
Sprite commissions closed!

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: How to allow the player to choose their character?

#11 Post by mitoky »

chungy wrote: Mon Sep 24, 2018 8:13 pm
mitoky wrote: Mon Sep 24, 2018 7:28 pm
I think it is, at least i see no reason why it shouldnt be working.
i'm not sure exactly where to put what variables since im pretty new at this. Is there an easy way to explain where to place things? Also ty for responding! ^__^
Oh ok, no problem.

Okay, so lets start with this part first:

Code: Select all

"character1.jpg"
"character2.jpg"
"character3.jpg"
Basically, only make sure your files inside your project folder for the avatar are named accordingly.
So this part of the code only tells you that you must name your files in the same way and is not part of the code itself.

The next part is this one:

Code: Select all

default avatar = 1

image characterPortrait = DynamicImage("character[avatar].jpg" )
This part declares the variable named "avatar" and the image "characterPortrait"
On default, declared images etc are inside the script.rpy on the top, but you can make a seperate .rpy file too to declare it there as Ren'Py reads all files as "one".
So which file isn't really important. The only important thing is that they have to be declared outside of any labels etc to work correctly and without any intending.

Example how it could look inside the script.rpy:

Code: Select all

default avatar = 1

image characterPortrait = DynamicImage("character[avatar].jpg" )

label start:
    "Your game starts here--"
The next part is the menu part:

Code: Select all

menu:
    "Choose Character 1":
        $ avatar = 1

    "Choose Character 2":
        $ avatar = 2

    "Choose Character 3":
        $ avatar = 3
This is used inside a label. So if we were to add it at the very start of the game, it would look like this:

Code: Select all

label start:
    "Chose your Avatar!"
    menu:
        "Choose Character 1":
            $ avatar = 1

        "Choose Character 2":
            $ avatar = 2

        "Choose Character 3":
            $ avatar = 3
and the last part, hence this one:

Code: Select all

show characterPortrait
is used to show the image.

All summed up, teh example would look like this:

Code: Select all

default avatar = 1

image characterPortrait = DynamicImage("character[avatar].jpg" )

label start:
    "Chose your Avatar!"
    menu:
        "Choose Character 1":
            $ avatar = 1

        "Choose Character 2":
            $ avatar = 2

        "Choose Character 3":
            $ avatar = 3
            
    show characterPortrait   
    "Hey, thats you!"        
I hope this helps!

User avatar
chungy
Regular
Posts: 26
Joined: Sun Sep 23, 2018 9:07 pm
Contact:

Re: How to allow the player to choose their character?

#12 Post by chungy »

mitoky wrote: Mon Sep 24, 2018 9:46 pm I hope this helps!
this works perfect! is there a way to do it w/ images? not sure if image maps would to best with that?
https://gutrotz.itch.io/
Check out my itch.io!

viewtopic.php?f=62&t=52002&p=496592#p496592
Sprite commissions closed!

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: How to allow the player to choose their character?

#13 Post by mitoky »

chungy wrote: Tue Sep 25, 2018 9:21 pm
mitoky wrote: Mon Sep 24, 2018 9:46 pm I hope this helps!
this works perfect! is there a way to do it w/ images? not sure if image maps would to best with that?
When using images i think it would be the best to make a character selection screen instead and call it.

User avatar
chungy
Regular
Posts: 26
Joined: Sun Sep 23, 2018 9:07 pm
Contact:

Re: How to allow the player to choose their character?

#14 Post by chungy »

mitoky wrote: Mon Sep 24, 2018 9:46 pm
When using images i think it would be the best to make a character selection screen instead and call it.
is there a certain recipe/thread i should look into for that? If not would you recc i start a new thread? or is this something simple enough to answer here?
https://gutrotz.itch.io/
Check out my itch.io!

viewtopic.php?f=62&t=52002&p=496592#p496592
Sprite commissions closed!

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: How to allow the player to choose their character?

#15 Post by mitoky »

chungy wrote: Wed Sep 26, 2018 6:19 pm
mitoky wrote: Mon Sep 24, 2018 9:46 pm
When using images i think it would be the best to make a character selection screen instead and call it.
is there a certain recipe/thread i should look into for that? If not would you recc i start a new thread? or is this something simple enough to answer here?
It would be easy to write a code but if you plan to code the game it would be good to get familiar with coding and try it yourself first as this is more bacis ( no scolding, only advice (: )

For what you need look up "renpy documentation" and look into 1.) screens and 2.) buttons (imagebuttons, imagemaps or imagebuttons). And try to write the code yourself first. If it doesnt works, then try to seek for help.

Doing things from scratch rather than someones base helps to learn and understand.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]