On usage of ShowingSwitch

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
mms
Newbie
Posts: 10
Joined: Mon Dec 25, 2006 10:02 am
Contact:

On usage of ShowingSwitch

#1 Post by mms »

I've tried to use ShowingSwitch in the game I'm making, taking code from here, but it's not showing images for me. Instead, I get the 'Undefined Images' message showing ingame.

Code: Select all

$ a = Character(
        'Alle', 
        color="#ffe38b",
        window_right_padding=160,
        show_side_image=ShowingSwitch(
            "alle serious", "alle_serious.png",
            "alle neutral", "alle_neutral.png",
            "alle surprised", "alle_shock.png",
            "alle smile", "alle_smile.png",
            None, Null(),
            xalign=0.0, yalign=640.0))
What do I have to change to make it work?

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: On usage of ShowingSwitch

#2 Post by Aleema »

Are the files "alle_smile.png", etc in a folder within your game, or are they just inside the game folder? If they're in a folder, you have to locate them, like "characters/alle_smile.png".

Um, OH, holy crap. I think I see another problem. Does "yalign=640.0" work for you? Because, that would make the image 640 whole screens below everything. When working with xalign/yalign, the greatest amount you can specify is 1.0 (unless you want things off the screen). This is because 1.0 represents 100% of the screen. 0.5 represents half. If you want to precisely place the image according to pixels, you must use the position property xpos/ypos. So you should instead say "ypos=640" (no point-zero).

mms
Newbie
Posts: 10
Joined: Mon Dec 25, 2006 10:02 am
Contact:

Re: On usage of ShowingSwitch

#3 Post by mms »

Yes, all the graphic files are in the default game folder.

AH, I see! *takes note of it for future refference* Although, it acts the same with different character, and yalign=1.0
The whole code:

Code: Select all

$ a = Character(
        'Alle', 
        color="#ffe38b",
        window_right_padding=160,
        show_side_image=ShowingSwitch(
            "alle serious", "alle_serious.png",
            "alle neutral", "alle_neutral.png",
            "alle surprised", "alle_shock.png",
            "alle smile", "alle_smile.png",
            None, Null(),
            xalign=0.0, yalign=1.0))
    $ c = Character(
        'Carl', 
        color="#ffe38b",
        window_left_padding=160,
        show_side_image=ShowingSwitch(
            "carl neutral", "carl_neutral.png",
            "carl smile", "carl_smile.png",
            "carl anger", "carl_anger.png",
            None, Null(),
            xalign=0.0, yalign=1.0))

I included the screenshot.
Attachments
Screen01.png

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: On usage of ShowingSwitch

#4 Post by Aleema »

Have you set up your sprite characters that are called "alle neutral", etc? It may be that for ShowingSwitch to work, you need to have already defined the sprites so that Ren'Py can check to see if it's showing. Meaning, you have to have:

Code: Select all

image alle neutral = "alle_sprite_neutral.png"
image alle mad = "alle_sprite_mad.png"
... where "alle_sprite_neutral.png" is the full-sized version of the side-image "alle_neutral.png".

Now, if you DON'T have full-sized sprites, then that's where the problem is coming from. And if you don't plan on having full sprites for your game, You should use a ConditionSwitch instead of a ShowingSwitch. That one looks for a variable to switch the images, so you could have a variable that is equal to an emotion. (I prefer that sooo much over ShowingSwitch).

mms
Newbie
Posts: 10
Joined: Mon Dec 25, 2006 10:02 am
Contact:

Re: On usage of ShowingSwitch

#5 Post by mms »

I tried the first, with defining sprites, and it shows two images when I want to show only one next to the message box. Since I want to show only side-images with these two characters without using the full sprites, it's now working.

As for the ConditionSwitch, how could it be used to show the side-images?

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: On usage of ShowingSwitch

#6 Post by Aleema »

mms wrote:I tried the first, with defining sprites, and it shows two images when I want to show only one next to the message box. Since I want to show only side-images with these two characters without using the full sprites, it's now working.

As for the ConditionSwitch, how could it be used to show the side-images?
Yeah, that's the problem. ShowingSwitch is only used when showing both full-sized sprites and side images. Very overrated, too.

If you want to use just the side-image, here's an example:

Code: Select all

$ a = Character(
        'Alle', 
        color="#ffe38b",
        window_right_padding=160,
        show_side_image=ConditionSwitch(
            "a_mood = 'serious'", "alle_serious.png",
            "a_mood = 'smile'", "alle_smile.png",
            "a_mood = 'shock'", "alle_shock.png",
            "a_mood = None", "alle_neutral.png",
            xalign=0.0, yalign=1.0))
And later, in your script, you can change emotions like this:

Code: Select all

$ a_mood = None
a "Hi!"
b "You suck."
$ a_mood = "shock"
a "Whaaat!?"
Make sure you initialize the "a_mood" variable as None in an init block.

Alternatively, you can make a new character for every mood and not use a Condition switch, which might save your fingers some typing:

Code: Select all

$ a = Character(
        'Alle', color="#ffe38b",window_right_padding=160,
        show_side_image=Image("alle_serious.png",xalign=0.0, yalign=1.0))
$ a shock = Character('Alle', show_side_image=Image("alle_shock.png",xalign=0.0, yalign=1.0), kind=a)
$ a serious = Character('Alle',show_side_image=Image("alle_serious.png",xalign=0.0, yalign=1.0), kind=a)
$ a smile = Character('Alle', show_side_image=Image("alle_smile.png",xalign=0.0, yalign=1.0), kind=a)
"kind=a" will copy the character a, and only change the attributes you didn't define in the new character, so you'd only have to make changes to the character "a" to make changes to all the "a" emotions chars.

mms
Newbie
Posts: 10
Joined: Mon Dec 25, 2006 10:02 am
Contact:

Re: On usage of ShowingSwitch

#7 Post by mms »

I tried the second solution, and unfortunately the script won't even start.

Code: Select all

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


On line 61 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
a tired "I'm so tired."
  ^

On line 69 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
a surprised "Huh? What do you mean?"
  ^

On line 77 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
a serious "Stop it!"
  ^

On line 87 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
c happy "Oh my~"
  ^

On line 119 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
a surprised "What?"
  ^

On line 150 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
a smile "I just want to have fun outside."
  ^

On line 209 of C:\Documents and Settings\*\My documents\renpy-6.10.2\one special day/game/script.rpy: expected statement.
a smile "Of course!"
  ^

Ren'Py Version: Ren'Py 6.10.2e

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: On usage of ShowingSwitch

#8 Post by Aleema »

Haha, my bad ... you can't have spaces in character calls. If you add underscores to all of them, they should work. Sorry, I just typed it out without testing. :)

a smile > a_smile
a surprised > a_surprised
etc.

waterpieces
Newbie
Posts: 18
Joined: Wed Feb 16, 2011 11:04 am
Projects: Robin - Escape!
Contact:

Re: On usage of ShowingSwitch

#9 Post by waterpieces »

Aleema wrote:
mms wrote:I tried the first, with defining sprites, and it shows two images when I want to show only one next to the message box. Since I want to show only side-images with these two characters without using the full sprites, it's now working.

As for the ConditionSwitch, how could it be used to show the side-images?
Yeah, that's the problem. ShowingSwitch is only used when showing both full-sized sprites and side images. Very overrated, too.

If you want to use just the side-image, here's an example:

Code: Select all

$ a = Character(
        'Alle', 
        color="#ffe38b",
        window_right_padding=160,
        show_side_image=ConditionSwitch(
            "a_mood = 'serious'", "alle_serious.png",
            "a_mood = 'smile'", "alle_smile.png",
            "a_mood = 'shock'", "alle_shock.png",
            "a_mood = None", "alle_neutral.png",
            xalign=0.0, yalign=1.0))
And later, in your script, you can change emotions like this:

Code: Select all

$ a_mood = None
a "Hi!"
b "You suck."
$ a_mood = "shock"
a "Whaaat!?"
Make sure you initialize the "a_mood" variable as None in an init block.

Alternatively, you can make a new character for every mood and not use a Condition switch, which might save your fingers some typing:

Code: Select all

$ a = Character(
        'Alle', color="#ffe38b",window_right_padding=160,
        show_side_image=Image("alle_serious.png",xalign=0.0, yalign=1.0))
$ a shock = Character('Alle', show_side_image=Image("alle_shock.png",xalign=0.0, yalign=1.0), kind=a)
$ a serious = Character('Alle',show_side_image=Image("alle_serious.png",xalign=0.0, yalign=1.0), kind=a)
$ a smile = Character('Alle', show_side_image=Image("alle_smile.png",xalign=0.0, yalign=1.0), kind=a)
"kind=a" will copy the character a, and only change the attributes you didn't define in the new character, so you'd only have to make changes to the character "a" to make changes to all the "a" emotions chars.
Hi~ I used that technique but it comes out like this:
Picture 30.png
and that character was suppose to be like this:
Soo hwa game icon happy.png
Soo hwa game icon happy.png (51.06 KiB) Viewed 2745 times
I wrote like this:

Code: Select all

  $ r = Character(
        'Robin', color="#ffe38b",window_right_padding=160,
        show_side_image=Image("Soo hwa game icon.png",xalign=0.0, yalign=1.0))
      $ r_shock = Character('Robin', show_side_image=Image("Soo hwa game icon surprised.png",xalign=0.0, yalign=1.0), kind=r)
      $ r_smile = Character('Robin',show_side_image=Image("Soo hwa game icon happy.png",xalign=0.0, yalign=1.0), kind=r)
      $ r_angry = Character('Robin', show_side_image=Image("Soo hwa game icon angry.png",xalign=0.0, yalign=1.0), kind=r)
and I applied it like this:

Code: Select all

 $ r_smile
     r "No worries mate. But I have to get going now"
Can you please help me how I can place the wordings next to the icon? :(

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: On usage of ShowingSwitch

#10 Post by Aleema »

Are you making a short-haired girl main character named Robin too? Small world! I feel increasingly uncreative every day! xD

You're misunderstanding the differences between my first example and my second example. In the first one, you'd call a variable before your character spoke, however, in the second one, the variable is the character's name, so you don't do that. With the method you're using, you created a character for each emotion. No variable needed. So you'd use it like:

Code: Select all

r smile "No worries mate. But I have to get going now"
r angry "Oh darn I forgot something"
See? Look at the code you're using, not just copy/paste it. See how it has the character calls, just different side images? You'd use them the same way you used "r". Which is, when they speak.

Now, to answer your question, you should look at my thread here and look to change the left_padding for your characters that need it.

waterpieces
Newbie
Posts: 18
Joined: Wed Feb 16, 2011 11:04 am
Projects: Robin - Escape!
Contact:

Re: On usage of ShowingSwitch

#11 Post by waterpieces »

Ahaha, yeah what a coincidence. ^^ But it's okay, at least my Robin is not a musician,,, she's a computer hacker. Your WIPs look really awesome! I'm really amazed how you make those menu so creatively!! Also, the stories you have are gorgeous! and really creative!!

Anyways, thanks so much!! I really appreciate it :) ~ the icon did change but there is still one more problem.

The side icon still overlaps the wording like this:
Picture 30.png
How can I make the wording go next to the icon?

I wrote this:

Code: Select all

$ r = Character(
        'Robin', color="#ffe38b",window_right_padding=160,
        show_side_image=Image("Soo hwa game icon.png",xalign=0.0, yalign=1.0))
      $ r_shock = Character('Robin', show_side_image=Image("Soo hwa game icon surprised.png",xalign=0.0, yalign=1.0), kind=r)
      $ r_smile = Character('Robin',show_side_image=Image("Soo hwa game icon happy.png",xalign=0.0, yalign=1.0), kind=r)
      $ r_angry = Character('Robin', show_side_image=Image("Soo hwa game icon angry.png",xalign=0.0, yalign=1.0), kind=r)
and under it, like this:

Code: Select all

 
r_smile "No thanks. I can get there myself. It's only few meters down." 
I'm sorry for asking too many questions but this is my first ever project on this afterall~~ :( Please help this helpless n00b out please?

User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: On usage of ShowingSwitch

#12 Post by Aleema »

<---- This is Left, This is Right ---->
You wanted window_left_padding=160, not right.

And thank you for the compliments of my WIPs! Your game looks very fun as well. Playing as a computer slacker hacker would be so comfortable for me, lol. :mrgreen:

waterpieces
Newbie
Posts: 18
Joined: Wed Feb 16, 2011 11:04 am
Projects: Robin - Escape!
Contact:

Re: On usage of ShowingSwitch

#13 Post by waterpieces »

Ahh yes~ ^^ I would love to play yours once it's finished! :D

And thanks so much! The problem is wiped off! Ahaha my bad for doing a silly mistake ^^; thanks you once again! I really do appreciate it! xD

Post Reply

Who is online

Users browsing this forum: No registered users