"Sayer '%s' is not defined."

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
Hasuko
Newbie
Posts: 18
Joined: Thu Jun 27, 2013 9:58 pm
Projects: 안녕U.F.O
Contact:

"Sayer '%s' is not defined."

#1 Post by Hasuko »

Hi all, first post here.. I'm trying to get conditional side portraits to work using the Ren'Py tutorial, however it is throwing errors and saying "sayer not defined" when I use the code from the Wiki (http://www.renpy.org/wiki/renpy/doc/coo ... ide_Images):


init python:
def conditional_portrait(status_var, filename_prefix, states):
args = []
for s in states:
args.append( "%s == '%s'" % (status_var, s) )
# The following line defines the template for your image files
args.append( Image("%s_%s.png" % (filename_prefix, s)) )
return ConditionSwitch(*args)


$ s = Character(
'Shimji',
color = "#c8ffc8",
window_left_padding = 160,
show_side_image = conditional_portrait("express", "s", ["robehappy", "o0happy"])
)


I'd actually tried modifying it to do 3 args instead of 2 (so the outfit had its own arg) but while the problem of it throwing "sayer not defined" exists I can't test to see if that works.

The specific error message:
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script.rpy", line 31, in script
Exception: Sayer 's' is not defined.

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

Full traceback:
File "D:\Work\Annyeong\renpy-6.14.1-sdk\renpy\execution.py", line 288, in run
node.execute()
File "D:\Work\Annyeong\renpy-6.14.1-sdk\renpy\ast.py", line 431, in execute
raise Exception("Sayer '%s' is not defined." % self.who.encode("utf-8"))
Exception: Sayer 's' is not defined.

Windows-7-6.1.7601-SP1
Ren'Py 6.15.7.374
A Ren'Py Game 0.0


Anyone have any input for me..? I'd appreciate it!

User avatar
Suwamoto
Regular
Posts: 66
Joined: Wed Sep 05, 2012 7:36 am
Contact:

Re: "Sayer '%s' is not defined."

#2 Post by Suwamoto »

Your ConditionSwitch is missing the None and True conditions >w< For the case that your status_var doesn't have anything stored.
And I'm not sure where you declared your variables.
But it should work like this:

Code: Select all

init python:
    def conditional_portrait(status_var, filename_prefix, states):
        args = []
        args.append("%s == None"%status_var)
        # The image that should be shown when no mood is defined
        args.append("%s_normal.png"%filename_prefix)
        for s in states:
            args.append( "%s == '%s'" % (status_var, s) )
            # The following line defines the template for your image files
            args.append( Image("%s_%s.png" % (filename_prefix, s)) )
        args.append("True")
        args.append("%s_normal.png"%filename_prefix)
        return ConditionSwitch(*args)


init:
    $ express = "happy"
    $ emotions = ["happy", "sad"]
    
define s = Character('Shimji', color = "#c8ffc8", window_left_padding = 160, show_side_image = conditional_portrait("express", "s", emotions))
Last edited by Suwamoto on Fri Jun 28, 2013 10:45 am, edited 2 times in total.

User avatar
Hasuko
Newbie
Posts: 18
Joined: Thu Jun 27, 2013 9:58 pm
Projects: 안녕U.F.O
Contact:

Re: "Sayer '%s' is not defined."

#3 Post by Hasuko »

I see thank you! I copied it directly from the Wiki. ^^; I'm new to Python so thank you for the heads up!

If I wanted to add a third arg, would I do it like this?

Code: Select all

init python:
  def conditional_portrait(status_var, filename_prefix, outfits, states):
        args = []
        args.append("%s == None"%status_var)
        # The image that should be shown when no mood is defined
        args.append("%s_normal"%filename_prefix)
        for o in outfits:
            args.append( "%s == '%s'" % (status_var, o) )
        for s in states:
            args.append( "%s == '%s'" % (status_var, s) )
# The following line defines the template for your image files
            args.append( Image("%s_%s_%s.png" % (filename_prefix, o, s)) )
        args.append("True")
        args.append("%s_normal.png"%filename_prefix)
        return ConditionSwitch(*args)
I ask because every character has multiple outfits for each set of emotions, but putting outfit1happy, outfit2happy, etc. in the emotions is somewhat tedious so I was wondering if it was possible to split them into a 3rd arg category.

User avatar
Suwamoto
Regular
Posts: 66
Joined: Wed Sep 05, 2012 7:36 am
Contact:

Re: "Sayer '%s' is not defined."

#4 Post by Suwamoto »

Edit: Wait hold on the code I just wrote doesn't work XD' Gimme one minute.

Edit2: To change the outfit of the character, do it like this:

Code: Select all

init python:
    current_outfit = "outfit1"
    current_mood = "happy"

    def draw_shimji(st, at):
        return LiveComposite(
            (200, 200), # Image size
            (0, 0), "s_%s_%s.png"%(current_outfit, current_mood),
            ),.1

init:
    image shimji sideimage = DynamicDisplayable(draw_shimji)

define s = Character('Shimji', color = "#c8ffc8", window_left_padding = 160, show_side_image = "shimji sideimage")

label start:
    s "I wear the standard outfit and am happy."
    
    $ current_mood = "sad"
    
    s "Now I am wearing the standard outfit and am sad"
    
    $ current_outfit = "outfit2"
    
    s "So I went changing my outfit but am still sad D: "

The contra of this solution is that you would have to declare new variables and new copies of the function for every character you change the outfit for. But since I think you won't bother to change outfits for all charas ingame, you can use this one combined with the solution before XD'
Otherwise, you will have to type "outfit1" etc again and again XD
Maybe there's some other way to do this but I wouldn't know how...yet >w<"

Edit 3: The reason why I wouldn't use the ConditionSwitch for the outfits would be because you would have a double for loop. Those are a pain in my opinion cause they can cause bugs rly easily.

User avatar
Hasuko
Newbie
Posts: 18
Joined: Thu Jun 27, 2013 9:58 pm
Projects: 안녕U.F.O
Contact:

Re: "Sayer '%s' is not defined."

#5 Post by Hasuko »

I see! Thank you so much for all your help!!

The three main characters of the game will have different outfits a lot, and one of them is a dynamic character who can change his appearance at will (think of the Bit from Tron) which is why the outfit switch was important to me.

So I'd use your first code for single outfit characters with multiple expressions, but second code for the other three, right?

User avatar
Suwamoto
Regular
Posts: 66
Joined: Wed Sep 05, 2012 7:36 am
Contact:

Re: "Sayer '%s' is not defined."

#6 Post by Suwamoto »

Yes, for single outfit characters with multiple expressions you can use my first code.

For characters with multiple expressions, you can use this method. I have tried around a bit and I think it's better to save the character bases with emotions and the outfits on seperate layers. (You know like those dress up games? ) Otherwise, you will have a HELL lot of images in your game folder and your game will take up too much space.

The code would be like this:

Code: Select all

## PYTHON CODE
init python:
    def conditional_portrait(status_var, filename_prefix, states):
        args = []
        args.append("%s == None"%status_var)
        # The image that should be shown when no mood is defined
        args.append("%s_%s.png"%(filename_prefix, states[1]))
        for s in states:
            args.append( "%s == '%s'" % (status_var, s) )
            # The following line defines the template for your image files
            args.append( Image("%s_%s.png" % (filename_prefix, s)) )
        args.append("True")
        args.append("%s_%s.png"%(filename_prefix, states[1]))
        return ConditionSwitch(*args)

    def draw_chara(st, at, status_var, filename_prefix, states, outfit_var, outfits):
        return LiveComposite(
            (300, 600), # Image size
            (0, 0), conditional_portrait(status_var, filename_prefix, states),
            (0, 0), conditional_portrait(outfit_var, filename_prefix, outfits),
            ),.1

## STUFFS YOU NEED TO DECLARE FOR EVERY CHARACTER
init:
    ## THE MOOD LIST FOR THE CHARACTER, IF ALL CHARACTERS HAVE THE SAME, YOU CAN JUST RE-USE IT
    $ total_moodlist = ["normal", "happy", "sad"]
    
    ## THE CURRENT MOOD STATUS OF YOUR CHARACTER
    $ chara_mood = "normal"
    
    ## THE CURRENT OUTFIT YOUR CHARACTER IS WEARING
    $ chara_outfit = "outfit1"
    
    ## THE WHOLE LIST OF OUTFITS YOUR CHARACTER GOT, IF YOUR CHARACTER ONY GOT ONE OUTFIT, THAT'S OKAY TOO
    $ total_outfitlist = ["outfit1", "outfit2"]
    
    ## MAKE RENPY CREATE THE IMAGE OF YOUR CHARACTER, CHANGE EVERYTHING AFTER draw_chara ACCORDING TO YOUR CHARACTER'S VARIABLES
    ## DynamicDisplayable(draw_chara, status_var, filename_prefix, mood_list, current_outfit, total_outfits)
    
    image chara mainimage = DynamicDisplayable(draw_chara, "chara_mood", "c", total_moodlist, "chara_outfit", total_outfitlist)

## Declare your character like always

define c = Character('Chara', color = "#c8ffc8", window_left_padding = 160, show_side_image = "chara mainimage")

## Remember that the character size is 300 x 600, which is too big for the side image.
## To make it look like the side image, go to screens.rpy
## Search for this code
##    if side_image:
##        add side_image
## And change it to
##    if side_image:
##        add side_image xpos 0 ypos 300
## xpos and ypos can be changed to place your character at the right position, which is faster than creating a new function just for that


# The game starts here.
label start:
    show chara mainimage
    "This shows the character in his standard appearance."
    
    $ chara_mood = "happy"
    "Now the character looks happy....kinda."
    
    $ chara_outfit = "outfit2"
    "Now the character changed his outfit <3"

    return
I attached my project to this post. You can download it and see how I saved the files and everything :D It would be easy to make a dress up game from this lol
Attachments
Multiple Expressions and Outfits.zip
Sample Project
(186.24 KiB) Downloaded 61 times

User avatar
Hasuko
Newbie
Posts: 18
Joined: Thu Jun 27, 2013 9:58 pm
Projects: 안녕U.F.O
Contact:

Re: "Sayer '%s' is not defined."

#7 Post by Hasuko »

Sorry it took me so long to reply. Real life happened and I only recently returned to the project.

Thanks again so much for this. I may even use it to make a dress-up bonus game for my characters in my visnov. :)

Post Reply

Who is online

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