"unicode object not callable" trying to have function argument specify which object is used in display [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
User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

"unicode object not callable" trying to have function argument specify which object is used in display [SOLVED]

#1 Post by TellerFarsight »

Hey, so I'm trying to simplify some code. I had one branching set of screen menus for Marl attacking and one for Gorb attacking, but I assume I should be able to have one screen and use the arguments to specify whether Marl or Gorb is doing the attacking. Problem is, when I click on the button to show the "act_menu," it returns a "unicode object is not callable" error. Is it some syntax error or am I just completely thinking about this the wrong way?

Code: Select all

init -1 python:
    from random import randint
    class Unit(object):
        def __init__(self,name,hp,attack,defense):
            self.name = name
            self.hp = hp
            self.attack = attack
            self.defense = defense
        def damage(self, enemy):
            damage = randint(1,self.attack) - enemy.defense
            if damage >=0 and enemy.hp != "DEAD":
                enemy.hp = enemy.hp - damage
            if enemy.hp <=0:
                enemy.hp = "DEAD"
            
default Marl = Unit("Marl",100,20,1)
default Gorb = Unit("Gorb",100,10,2)

screen dudes():
    button:
        background Solid("ff0000")
        text "[Marl.hp]" align (0.5,0.5)
        xpos 200
        action Show("act_menu","Marl")
    button:
        background Solid("0000ff")
        text "[Gorb.hp]" align (0.5,0.5)
        xpos 600
        action Show("act_menu","Gorb")

screen act_menu(char):
    text "[char.name]" xpos 100 ypos 100
    text "Attack Power: [char.attack]" xpos 100 ypos 150
    text "Defense: [char.defense]" xpos 100 ypos 200
    textbutton "Attack!" action Show("select_target", "char")

screen select_target(char):
    text "Select Target!"
    textbutton "-->" action (Function([char].damage,Gorb), Hide("act_menu"), Hide("select_target"))
    textbutton "<--" action (Function([char].damage,Marl), Hide("act_menu"), Hide("select_target"))
Last edited by TellerFarsight on Wed Aug 30, 2017 12:00 am, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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: "unicode object not callable" trying to have function argument specify which object is used in display

#2 Post by Remix »

It will be one (or all) of the lines where you are passing parameters as strings and then referencing them as objects... e.g.

Show( "screen_name_in_quotes_is_ok", variable_name_without_quotes_as_it_is_not_a_string )
Frameworks & Scriptlets:

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: "unicode object not callable" trying to have function argument specify which object is used in display

#3 Post by TellerFarsight »

I've tried that and the error is "Unit object is not callable"
The problem is where I'm trying to reference the objects. I was trying originally to pass them as strings and then reference them as strings which would then become the object, but now that I think about that it doesn't quite make sense.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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: "unicode object not callable" trying to have function argument specify which object is used in display

#4 Post by Remix »

The Function calls are likely the culprits... a standard char.damage rather than [char].damage should work.
The error output should tell you exactly which line is creating the glitch anyway
Frameworks & Scriptlets:

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: "unicode object not callable" trying to have function argument specify which object is used in display

#5 Post by TellerFarsight »

It looks like that's not the issue. I can't get the exact line of error because it's in a screen and it just points to the line in the script where I call the screen, but the error occurs only when I press this first button. I've also tried removing the parts where I call the attributes to be displayed. The problem is where I try to pass the Object name to the screen.

Code: Select all

screen dudes():
    button:
        background Solid("ff0000")
        text "[Marl.hp]" align (0.5,0.5)
        xpos 200
        action Show("act_menu",Marl)

screen act_menu(char):
    text "boo"
Even this code produces the same error.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: "unicode object not callable" trying to have function argument specify which object is used in display

#6 Post by TellerFarsight »

I still can't figure it out. Is there a way a python object can be passed as a parameter to a screen?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: "unicode object not callable" trying to have function argument specify which object is used in display

#7 Post by DannyGMaster »

TellerFarsight wrote: Mon Aug 28, 2017 4:31 pm I still can't figure it out. Is there a way a python object can be passed as a parameter to a screen?
Yes, the way you are doing it is just fine. The problem is the second argument of the Show action.

Show expects a string with the name of the screen, a transition, and then the arguments. In your code you are passing it the argument as the transition, therefore the error. Try:

Code: Select all

action Show('act_menu', None, Marl)
None, in this case, indicates that no transition should occur, but it can of course be substituted by any transition, like dissolve, but either way it should always follow the name of the screen, and be followed by any number of arguments you want to pass it.
The silent voice within one's heart whispers the most profound wisdom.

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: "unicode object not callable" trying to have function argument specify which object is used in display

#8 Post by TellerFarsight »

You are so correct Danny!
I realize now why I didn't catch it. I have done code before that calls screens with arguments, but I went back and checked and I had done all of those with dictionaries. Using that same logic, this also worked:

Code: Select all

actions Show("act_menu", char=Marl)
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: "unicode object not callable" trying to have function argument specify which object is used in display

#9 Post by DannyGMaster »

TellerFarsight wrote: Wed Aug 30, 2017 12:00 am this also worked:

Code: Select all

actions Show("act_menu", char=Marl)
Hey, I hadn't thought of that but it's actually a pretty nice idea, thank you!

Also glad I could help :D
The silent voice within one's heart whispers the most profound wisdom.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Ocelot