Side Image [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
SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Side Image [SOLVED]

#1 Post by SketchFoxsky »

I want to make an Easter egg involving the side image when you name the Player a certain way. For example, if you name the player it shows their side image as that character.


Ex:If they name their Player as "Friend" it gives the player a side image of "Friend's" Character
Last edited by SketchFoxsky on Thu Jun 07, 2018 9:07 pm, edited 3 times in total.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Side Image [HELP]

#2 Post by kivik »

There're different ways of doing it, depending on what your images are like.

If you're using the most convention method of setting up side images (docs: https://www.renpy.org/doc/html/side_image.html):

Code: Select all

define e = Character("Eileen", image="eileen")

image eileen happy = "eileen_happy.png"
image eileen concerned = "eileen_concerned.png"

image side eileen happy = "side_eileen_happy.png"
image side eileen = "side_eileen.png"
You'd need to create some extra images for friend first:

Code: Select all

# add these before label start
image friend happy = "friend_happy.png"
image friend concerned = "friend_concerned.png"

image side friend happy = "side_friend_happy.png"
image side friend = "side_friend.png"
Now when player chooses the character name, let's say player_name is the name variable (replace it with whatever you actually use in your game) and your player character's e (as the above code)

Code: Select all

if player_name.strip().lower() == "friend": # make sure all lower case
    e.image = "friend"
This effectively changes all associated images for your player to the friend images. I assume that's what you would want if you're swapping the side image, since it'd be weird if your player has different side images than main image.


Let us know if this seems like the approach for you, but if you're already doing different things for your images like using dynamic images, then show us how you declare your images and we can point you in the right direction with other methods :)

SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Re: Side Image [HELP]

#3 Post by SketchFoxsky »

The player is never seen on screen besides when you activate this so how can I use this, also I'm getting an error.

Code: Select all

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


File "game/script.rpy", line 81: expected statement.
    s.image = "Sketch"
            ^

File "game/script.rpy", line 97: expected statement.
    s.image = "Sketch"
            ^
Ren'Py Version: Ren'Py 6.99.14.1.3218
Thu Jun 07 17:30:45 2018

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Side Image [HELP]

#4 Post by kivik »

My bad: add a $ in front to make it a python statement.

Code: Select all

$ s.image = "Sketch"

SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Re: Side Image [HELP]

#5 Post by SketchFoxsky »

My image is not appearing at all

here is all the coding involving the player name and player images.

image side Sketch = "Sketch.png"
image side Sketch Nervous = "SketchNervous.png"
image side Null = "Null.png"
image side Null Nervous = "Null.png"

The null set is a plank transparent png file

define s = Character("[player_name]", image="null", color="#ffffff", who_outlines=[ (5, "#000000") ], what_outlines=[ (3, "#000000") ])


$ player_name = renpy.input("What is your name?")
$ player_name = player_name.strip()
if player_name == "":
$ player_name = "Spice"
if player_name.strip().lower() == "sketch": # make sure all lower case
$ s.image = "sketch"

any help with this would be great Thank you so much for taking time on this for me!

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Side Image [HELP]

#6 Post by kivik »

The images names are case sensitive I think, so you'd probably need to use "Sketch" instead of "sketch" in the last statement.

Also since you've already done .strip() to your player_name earlier, you can just use if player_name.lower() there. Note that you use lower case on the comparison statement because you're comparing it with a lower case version of player_name, which means it'll match "SKETCH", "Sketch", "SkEtCh" and all variations of cases.

SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Re: Side Image [HELP]

#7 Post by SketchFoxsky »

Still doesn't work?

Is it the

$ s.image = "Sketch"

it still doesn't show the image?


[EDIT]

Yes it is that line. It doesn't replace the "Null" set with the "Sketch" set
Not sure if the IF statement is working though?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Side Image [HELP]

#8 Post by kivik »

Hmm... looks like once the character is defined, you can't change the image by just replacing the image attribute. My google yield nothing so we'll cheat a little:

Code: Select all

image side Sketch = "Sketch.png"
image side Sketch Nervous = "SketchNervous.png"
image side Null = "Null.png"
image side Null Nervous = "Null.png"

define s = Character("[player_name]", image="Null", color="#ffffff", who_outlines=[ (5, "#000000") ], what_outlines=[ (3, "#000000") ])
define s_sketch = Character("[player_name]", image="Sketch", color="#ffffff", who_outlines=[ (5, "#000000") ], what_outlines=[ (3, "#000000") ])

label start:
    $ player_name = renpy.input("What is your name?")
    $ player_name = player_name.strip()
    if player_name == "":
        $ player_name = "Spice"
    if player_name..lower() == "sketch":
        $ s = s_sketch
Basically I've added a new character called s_sketch that's identical in every way except for the image - and if your player names themselves "Sketch", we make s become that character by doing s = s_sketch, and from then onwards it'll use the Sketch side images.

Also I've changed the casing for your original character. You had image="null" which would show nothing because you don't have an image called "null". You may not have noticed it because your null image is blank anyway - to which I ask, why not just have no image?

Code: Select all

define s = Character("[player_name]", color="#ffffff", who_outlines=[ (5, "#000000") ], what_outlines=[ (3, "#000000") ])
The only reason I can think of is that you actually have a normal image that you plan on using for the player - which is quite rare for VN games. I'm not sure, but if your player character isn't gonna have an image, then just don't give them one.

Also you should avoid using the word null as variable or names for anything - because null is a reserved word in most programming languages and you never know when it may break things in unexpected ways somewhere.

SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Re: Side Image [HELP]

#9 Post by SketchFoxsky »

Thank you so much, reason for the null set is cause any players who name themselves it doesn't assign an image and if i don't have one, whenever i use something like

s happy "yay"

it'll say there isn't a image tagged for Player_name

SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Re: Side Image [HEK HELP AGAIN!]

#10 Post by SketchFoxsky »

Now I'm given a syntax error!

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 98, in script
    if player_name..lower() == "sketch":
SyntaxError: invalid syntax (game/script.rpy, line 98)

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

Full traceback:
  File "game/script.rpy", line 98, in script
    if player_name..lower() == "sketch":
  File "C:\Users\EEEE\Desktop\lol\renpy-6.99.13-sdk\renpy\ast.py", line 1702, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\EEEE\Desktop\lol\renpy-6.99.13-sdk\renpy\python.py", line 1841, in py_eval
    code = py_compile(code, 'eval')
  File "C:\Users\EEEE\Desktop\lol\renpy-6.99.13-sdk\renpy\python.py", line 638, in py_compile
    raise e
SyntaxError: invalid syntax (game/script.rpy, line 98)

Windows-8-6.2.9200
Ren'Py 6.99.14.1.3218
Maria? 1.0
Thu Jun 07 20:08:08 2018

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Side Image [HEK HELP AGAIN!]

#11 Post by kivik »

Sorry I missed the typo in my tiredness when deleting the .strip() part of the code. Syntax error basically means there's typically a mistake with the code's format - it should be super obvious, I'd encourage you to try and figure this one out yourself :)

SketchFoxsky
Newbie
Posts: 12
Joined: Fri Apr 27, 2018 7:33 pm
Contact:

Re: Side Image [HEK HELP AGAIN!]

#12 Post by SketchFoxsky »

haha noticed it too, thanks!

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: Side Image [SOLVED]

#13 Post by Remix »

Just for info (as you already have a working solution):

Character objects hold their image attribute internally as self.image_tag so rather than s.image = "Sketch" you would have wanted s.image_tag = "Sketch"

On an aside and just as advice for the OP;
It might be a good idea to decide upon and stick to a naming convention for assets and references in your game.
Personally I use lowercase everywhere except class names (CamelCase) and constants (UPPER) in code and lowercase with underscores for naming images and other files.
Once you get familiar with a convention you will make less mistakes and not have to find the asset/code to check the name.
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Nozori_Games