[SOLVED] How to base an avatar on character select

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
User avatar
Soliloquy
Regular
Posts: 72
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

[SOLVED] How to base an avatar on character select

#1 Post by Soliloquy » Sun Nov 19, 2017 12:30 pm

I have a working character select screen, which will plug the names and classes into my dialogue boxes with no problem. I'm trying to figure out if it's possible to link the three character avatars to the same screen.

This is the select screen. The SetVariable("char_choice", "g") appears to be doing nothing so far, even in conjunction with the next bit of code.

Code: Select all

screen character_select:
    imagemap:
        ground "menu/character_select.png"
        hover "menu/character_select_frames.png"
    
        alpha False
        hotspot(19,16,238,568) action [SetVariable("name1", "Gemini"), SetVariable("class1", "Healer"), SetVariable("char_choice", "g"), Return("smth")]
        hotspot(286,15,238,568) action [SetVariable("name1", "Orin"), SetVariable("class1", "Queen"), Return("smth")]
        hotspot(548,15,240,567) action [SetVariable("name1", "Vyvian"), SetVariable("class1", "Black Widow"), Return("smth")]
This is the closest bit of code that I found online to help with this sort of problem.

Code: Select all

image char = ConditionSwitch(
    char_choice==o,"avatars/handsomeo.png",
    char_choice==g,"avatars/handsomeg.png",
    char_choice==v,"avatars/handsomev.png")
However, when I use that, I get this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/declared.rpy", line 30, in script
    image char = ConditionSwitch(
  File "game/declared.rpy", line 31, in <module>
    char_choice==o,"avatars/handsomeo.png",
NameError: name 'char_choice' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/declared.rpy", line 30, in script
    image char = ConditionSwitch(
  File "C:\Program Files (x86)\RenPy\renpy\ast.py", line 921, in execute
    img = renpy.python.py_eval_bytecode(self.code.bytecode)
  File "C:\Program Files (x86)\RenPy\renpy\python.py", line 1788, in py_eval_bytecode
    return eval(bytecode, globals, locals)
  File "game/declared.rpy", line 31, in <module>
    char_choice==o,"avatars/handsomeo.png",
NameError: name 'char_choice' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.99.13.2919
The Dark Court's Apprentice 0.0
I have absolutely no idea where to go from here, or if I'm even on the right track. If I am, I don't know how to plug any of this into the script to get it running. Can any Py-experts help?
Last edited by Soliloquy on Wed Nov 22, 2017 5:43 pm, edited 1 time in total.

User avatar
Scribbles
Miko-Class Veteran
Posts: 505
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island
Projects: As We Know It, By Moonlight, Possessed[hiatus],
Organization: Scribble Games
Tumblr: doodlesatbreakfast
Deviantart: breakfastdoodles
itch: scribbles
Location: Georgia
Contact:

Re: How to base an avatar on character select

#2 Post by Scribbles » Sun Nov 19, 2017 12:54 pm

you might need to have a default char_choice defined just as a backup.

default char_choice = o ##and then it can be changed in your character selection screen
Image - Image

User avatar
Soliloquy
Regular
Posts: 72
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Re: How to base an avatar on character select

#3 Post by Soliloquy » Sun Nov 19, 2017 11:03 pm

Scribbles wrote:
Sun Nov 19, 2017 12:54 pm
you might need to have a default char_choice defined just as a backup.

default char_choice = o ##and then it can be changed in your character selection screen
Where do I put that? I tried placing it in a few areas outside of the condition switch, which led to the same error as above, while placing it inside the condition switch led to an invalid syntax error.

User avatar
Scribbles
Miko-Class Veteran
Posts: 505
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island
Projects: As We Know It, By Moonlight, Possessed[hiatus],
Organization: Scribble Games
Tumblr: doodlesatbreakfast
Deviantart: breakfastdoodles
itch: scribbles
Location: Georgia
Contact:

Re: How to base an avatar on character select

#4 Post by Scribbles » Sun Nov 19, 2017 11:09 pm

Soliloquy wrote:
Sun Nov 19, 2017 11:03 pm
Scribbles wrote:
Sun Nov 19, 2017 12:54 pm
you might need to have a default char_choice defined just as a backup.

default char_choice = o ##and then it can be changed in your character selection screen
Where do I put that? I tried placing it in a few areas outside of the condition switch, which led to the same error as above, while placing it inside the condition switch led to an invalid syntax error.
What's the syntax error? I place it directly above the image definition:

(some of my rough code)

Code: Select all

default micah_eyes = "neutral"
default micah_face = "neutral"
image micah = LiveComposite((453, 1080),
                (0, 0), "images/sprites/micah/micah_base.png",
                (0, 0), ConditionSwitch(
                    "micah_eyes == 'neutral'", "images/sprites/micah/neutral_eyes.png",
                    "micah_eyes == 'mad'", "images/sprites/micah/mad_eyes.png",
                    "micah_eyes == 'happy'", "images/sprites/micah/happy_eyes.png",
                    ),
                (0, 0), ConditionSwitch(
                    "micah_face == 'neutral'", "images/sprites/micah/neutral_face.png",
                    "micah_face == 'mad'", "images/sprites/micah/mad_face.png",
                    "micah_face == 'happy'", "images/sprites/micah/happy_face.png",
                    ),
            )
Image - Image

User avatar
Soliloquy
Regular
Posts: 72
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Re: How to base an avatar on character select

#5 Post by Soliloquy » Sun Nov 19, 2017 11:17 pm

When I put the default inside of the condition switch I get this back:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.

File "game/declared.rpy", line 33: invalid syntax
        default char_choice = o
                           ^

Ren'Py Version: Ren'Py 6.99.13.2919

User avatar
Soliloquy
Regular
Posts: 72
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Re: How to base an avatar on character select

#6 Post by Soliloquy » Sun Nov 19, 2017 11:40 pm

Oooooooohhhh, I wrote the condition switch wrong. From the bit that I found online I didn't realize I had to wrap the first half in quotes. Now the error's gone, so thank you!

Now I just need to get the actual character select to work. The Set Variable doesn't seem to take, and I'm not sure how else to phrase it.

Code: Select all

screen character_select:
    imagemap:
        ground "menu/character_select.png"
        hover "menu/character_select_frames.png"
    
        alpha False
        hotspot(19,16,238,568) action [SetVariable("name1", "Gemini"), SetVariable("class1", "Healer"), SetVariable("char_choice", "g"), Return("smth")]
        hotspot(286,15,238,568) action [SetVariable("name1", "Orin"), SetVariable("class1", "Queen"), Return("smth")]
        hotspot(548,15,240,567) action [SetVariable("name1", "Vyvian"), SetVariable("class1", "Black Widow"), Return("smth")]

User avatar
Scribbles
Miko-Class Veteran
Posts: 505
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island
Projects: As We Know It, By Moonlight, Possessed[hiatus],
Organization: Scribble Games
Tumblr: doodlesatbreakfast
Deviantart: breakfastdoodles
itch: scribbles
Location: Georgia
Contact:

Re: How to base an avatar on character select

#7 Post by Scribbles » Mon Nov 20, 2017 12:41 am

I'm not sure about the setvariable() action, I've only ever used it with integers so maybe it's a string issue? Not sure how to make that part work for you, but hopefully someone else will!
Image - Image

User avatar
Remix
Veteran
Posts: 358
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet
Projects: An un-named 3d anime based trainer game
Contact:

Re: How to base an avatar on character select

#8 Post by Remix » Mon Nov 20, 2017 8:38 am

It probably does 'take' except the ConditionSwitch might well only run once, rather than every time char_choice is changed.

You might notice in Scribbles sample code that they used LiveComposite... an image type that re-evaluates itself repeatedly.

You could use similar, though I would advise to simplify and just use a DynamicImage...

Code: Select all

default char_choice = 'v'
image char = DynamicImage( "avatars/handsome[char_choice].png" )

User avatar
Soliloquy
Regular
Posts: 72
Joined: Tue Aug 25, 2015 3:42 pm
Location: Mt Holly, NJ
Contact:

Re: How to base an avatar on character select

#9 Post by Soliloquy » Mon Nov 20, 2017 7:04 pm

Remix wrote:
Mon Nov 20, 2017 8:38 am
It probably does 'take' except the ConditionSwitch might well only run once, rather than every time char_choice is changed.

You might notice in Scribbles sample code that they used LiveComposite... an image type that re-evaluates itself repeatedly.

You could use similar, though I would advise to simplify and just use a DynamicImage...

Code: Select all

default char_choice = 'v'
image char = DynamicImage( "avatars/handsome[char_choice].png" )
Thank you! I had no idea such a thing existed, but this appears to have done the trick. I appreciate it very much. ^^

Post Reply

Who is online

Users browsing this forum: Yahoo [Bot]