Need some help from someone familiar with coding renpy

beefy1977

Newbie
Apr 6, 2019
54
47
Completely new to all this stuff and im in the middle of playing around with a script and learning basics of rynpy. I've so far been able to set side images of all the characters in the script fairly easily. Im hung up on the the MC though as I set his name to be custom (using "$ name = renpy.input("What's my name?"). The problem Im having is defining that characters name to set a side image for him.
so with another character I was able to do so with.... define k = Character("Kate", image="kate",window_left_padding) .....Im not sure how well it looks but it works!
the problem is when i try with [name] for the custom name tag it gives an error message.

I hope I was able to give enough info for someone to help. Like I said, im really new to this and could use simplified explanations.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,583
2,222
That's fine.

You need to think of the character name and the character object (and associated side images) as two separate things.

I think what you are looking for is something like:

define mc = Character("[player_name]", image="player",window_left_padding)

Where mc is the Character object name.
Where [player_name] is the indirect reference to a variable called "player_name" that holds the player's name.
Where image="player" is a reference the id for images (like side images) that are used by this character.

Just because you have "Kate" and image="kate", doesn't mean they need to be the same. It could be "Kate" and image="bobby" (not that that would make a whole lot of sense)... but it could be.

Now all you need is a (or a group of) image side player {blah, blah} image definition(s) for your "player" object in the same way you would have "image side kate {blah, blah}" definitions too.

You've used "name" instead of "player_name", that's fine. I'm just using my own example, I tend to worry that "name" might be a reserved word in some programming languages.
It doesn't need to be "mc" or "player" either, as long as each is unique.

You're 99% there, you just need that tweak to use image="player" instead of image="[name]" and then use "player" (or whatever ID you end up using) for defining your associated images.
 

AmazonessKing

Amazoness Entrepreneur
Aug 13, 2019
1,898
2,919
Would help more if you can post the error it gives.

I think, however, that yo are having the same problem I used to have. You need to input the player's name first, otherwise, whenever the game tried to look for your character name, it won't exist. The other option you have is having a default character name that can be changed, that name there will always be a character name.

Python:
define p = Character("[name]")

    $ name = renpy.input("What is your name?")
    $ name = name.strip()

    if not name:
         name = "Pat Smith"

laber start:

p "My name is [name]!"
Also, as 79flavors said, be careful with over simplifying names because they may be reserved. Use something like "povname" or player name. In my case, I actually store the character name in persistent memory, meaning that if you reset the game you don't need to put the name again, even if you start a new game, and later, like in the game options, you can give an option to change the name of the character.

Python:
label start:

if persistent.povname is None:
    $ povname = renpy.input("My name is")
    $ persistent.povname = povname.strip()

else:
    $ povname = persistent.povname
 
Last edited:
  • Like
Reactions: beefy1977

beefy1977

Newbie
Apr 6, 2019
54
47
OK thanks for that. The issue im having now is coding the the line like this:

image side kate = "side_kate.jpg"

in order to have a side image for the MC with custom name.

Thanks for your help!

***EDIT***
NVM, I figured it out! it was
image side player = "side_me.jpg"
 
  • Like
Reactions: AmazonessKing

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,375
15,288
Just one thing that always annoy the lazy and stubborn Perl addict I am ; if it can be done in one line and by pressing less keys, why bother with more ?

Python:
    $ name = renpy.input("What is your name?")
    $ name = name.strip()
This can be wrote [icode}$ name = renpy.input( "What is your name ?" ).strip()[/icode]. But it's really a small detail that have absolutely no importance.


This said, the principle stay the same for everything.
As long as something can be performed on the variable, it can also be performed when the value is assigned to the variable. There's few exceptions, but Ren'py will yell at you if it happen.
And suddenly it become less a detail since you need the $ thing that sometimes mess with the readability of the code when there's too much of them.

It also help to speed-up a little the code on slow devices for two reasons :
Firstly, because in Python each assignation recreate the variable. Therefore, if you have just one assignation, you gain one or two micro seconds... which is nothing by itself but start to represent something if it happen often and you add them all.
Secondly, because in Ren'py, each $ prefixed line is proceeded individually through a process that isn't totally transparent in regard of the time needed. Therefore, once again it will make you gain few micro seconds, that will add to the ones you gained previously.

There's also the possibility to use :
Code:
    python:
          [...]
in place of a bunch of $ prefixed lines. It will create a block that will be proceeded globally, in place of many lines proceeded individually. Therefore, here again it will make you gain few micro seconds.

This said, it's something to know, but not necessarily something to use.
If you use few inline python in your game, it don't worth going this far in the optimization ; the gain will be invisible for the player. But if you use many, and expect your game to be played on android devices or really old computers, it can really save the day for those players.

But, I insist on the fact that it's to know more than necessarily use. And it's someone who validate (and sometime over validate) all the data in his code (so someone who loose voluntarily a lot of micro seconds) who say that :D