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.
-
Baal7734
- Newbie
- Posts: 11
- Joined: Tue Dec 08, 2015 2:03 pm
-
Contact:
#1
Post
by Baal7734 » Wed Apr 13, 2016 4:26 am
Here's what I'm trying to do.
Code: Select all
label start:
show expression Text("{color=ff1200}Wanna talk to Joe about fishing?",
size=50,
yalign=0.1,
xalign=0.5,
drop_shadow=(2, 2)) as text
menu:
"yes":
call Test(Joe, Fishing)
return
"no":
hide text with dissolve
show expression Text("{color=ff1200}TOO BAD!",
size=50,
yalign=0.1,
xalign=0.5,
drop_shadow=(2, 2)) as text
pause
call Test(Joe, Fishing)
return
label Test(namevariable, topicvariable):
call namevariable_topicvariable #<----------------I know this is wrong. Is there a way to do this though?
"It really does."
return
label Joe_Fishing(namevariable, topicvariable):
hide text with dissolve
"You don't know anybody named Joe and fishing sucks"
return
Last edited by
Baal7734 on Wed Apr 13, 2016 7:09 am, edited 3 times in total.
-
Roboduck
- Newbie
- Posts: 11
- Joined: Wed Oct 14, 2015 3:09 pm
-
Contact:
#2
Post
by Roboduck » Wed Apr 13, 2016 4:56 am
I can't guarantee this will work as I have no way of testing it atm but I would try it this way:
Code: Select all
init python:
def Test(namevar,topicvar):
return (namevar+'_'+topicvar)
[...]
"no":
[...]
$newlabel = Test('joe','fishing')
$renpy.call(newlabel)
[...]
label joe_fishing:
"Fishing sucks."
return
Last edited by
Roboduck on Wed Apr 13, 2016 6:15 am, edited 1 time in total.
-
Onishion
- Veteran
- Posts: 295
- Joined: Mon Apr 20, 2015 10:36 am
-
Contact:
#3
Post
by Onishion » Wed Apr 13, 2016 5:11 am
Can you call the result of a variable? I'm not sure. If not, then the only solution I could offer would be to call a long chain of if statements, if the variable is X, call Y, etc.
-
Baal7734
- Newbie
- Posts: 11
- Joined: Tue Dec 08, 2015 2:03 pm
-
Contact:
#4
Post
by Baal7734 » Wed Apr 13, 2016 5:45 am
That's
Roboduck wrote:I can't guarantee this will work as I have no way of testing it atm but I would try it this way:
Code: Select all
init python:
def Test(namevar,topicvar):
return (namevar+'_'+topicvar)
[...]
"no":
[...]
$newlabel = Test('joe','fishing')
call newlabel
[...]
label joe_fishing:
"Fishing sucks."
return
Did you mean ?
Otherwise You're just setting a variable, and calling the variable as a label.
I want to make a call statement using
only the arguments to populate the label it's calling.
-
Roboduck
- Newbie
- Posts: 11
- Joined: Wed Oct 14, 2015 3:09 pm
-
Contact:
#5
Post
by Roboduck » Wed Apr 13, 2016 6:14 am
Onishion wrote:Can you call the result of a variable? I'm not sure. If not, then the only solution I could offer would be to call a long chain of if statements, if the variable is X, call Y, etc.
It definitely works for renpy.call_in_new_context(label_variable)
But I just realized, it should be
$renpy.call(newlabel) instead of just
call newlabel, I'll edit my reply above.
Baal7734 wrote:
Did you mean ?
Sure, if you declare the variables at some point as strings, like
$namevar = 'joe'
$topicvar = 'fishing'
-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#6
Post
by xela » Wed Apr 13, 2016 6:25 am
Don't create new contexts without a good reason to. Try:
Code: Select all
label Test(namevariable, topicvariable):
call expression namevariable + "_" + topicvariable
"It really does."
return
label Joe_Fishing:
hide text with dissolve
"You don't know anybody named Joe and fishing sucks"
return
You normally want to name use lowercase letters for label names as a general guideline.
Like what we're doing? Support us at:

-
Baal7734
- Newbie
- Posts: 11
- Joined: Tue Dec 08, 2015 2:03 pm
-
Contact:
#7
Post
by Baal7734 » Wed Apr 13, 2016 6:51 am
xela wrote:Don't create new contexts without a good reason to. Try:
Code: Select all
label Test(namevariable, topicvariable):
call expression namevariable + "_" + topicvariable
"It really does."
return
label Joe_Fishing:
hide text with dissolve
"You don't know anybody named Joe and fishing sucks"
return
You normally want to name use lowercase letters for label names as a general guideline.
Here's the traceback.
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 72, in script call
call Test(joe, fishing)
File "game/script.rpy", line 85, in script
label Test(namevariable, topicvariable):
File "game/script.rpy", line 72, in <module>
call expression namevariable + "_" + topicvariable
TypeError: unsupported operand type(s) for +: 'Person' and 'str'
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 72, in script call
call Test(joe, fishing)
File "game/script.rpy", line 85, in script
label Test(namevariable, topicvariable):
File "C:\Users\godis\Desktop\renpy-6.99.7-sdk\renpy\ast.py", line 1311, in execute
args, kwargs = self.arguments.evaluate()
File "C:\Users\godis\Desktop\renpy-6.99.7-sdk\renpy\ast.py", line 180, in evaluate
args.append(renpy.python.py_eval(v, locals=scope))
File "C:\Users\godis\Desktop\renpy-6.99.7-sdk\renpy\python.py", line 1489, in py_eval
return py_eval_bytecode(code, globals, locals)
File "C:\Users\godis\Desktop\renpy-6.99.7-sdk\renpy\python.py", line 1484, in py_eval_bytecode
return eval(bytecode, globals, locals)
File "game/script.rpy", line 72, in <module>
call expression namevariable + "_" + topicvariable
TypeError: unsupported operand type(s) for +: 'Person' and 'str'
Windows-8-6.2.9200
Ren'Py 6.99.7.858
Ren'Py Tutorial 6.99 "Here's to the crazy ones."
-
xela
- Lemma-Class Veteran
- Posts: 2481
- Joined: Sun Sep 18, 2011 10:13 am
-
Contact:
#8
Post
by xela » Wed Apr 13, 2016 7:02 am
Do you assume that I'm psychic?
How do you know that an instance of "Person" class is called "Joe"? You prolly have something like Person.name there so you should use something like:
Code: Select all
call expression namevariable.name + "_" + topicvariable
or overload __repr__ or __string__ special methods. I don't really understand why you're doing this but you should be able to get stuff like this to work (more often than not).
Like what we're doing? Support us at:

-
Baal7734
- Newbie
- Posts: 11
- Joined: Tue Dec 08, 2015 2:03 pm
-
Contact:
#9
Post
by Baal7734 » Wed Apr 13, 2016 7:08 am
That worked. Thanks Xela!
