Hi everyone, I've been experimenting with this question again, wanting to see if I could get a better answer than I gave.
So I created a tester project and came up with three different ways to achieve the result. Although all of them ultimately didn't pass information back, they just modified information in the character given.
I'll show you what I did:
Code: Select all
init python:
class Char():
def __init__(self, name, mhp, skills=None):
self.name = name
self.curHP = mhp
self.maxHP = mhp
self.skills = skills
self.active_skill = None
screen battle(char):
default skill = None
frame align (1.0, 0.0):
vbox:
label "[char.name]"
text "[char.curHP]/[char.maxHP] HP"
text "Skill to Use: [char.active_skill]"
text "-----"
textbutton "Choose Skill, Show Screen" action Show("choose", char=char)
textbutton "Choose Skill Renpy Func" action Function(renpy.call_in_new_context, "chooselabel", char)
textbutton "Choose Skill Ui Call" action ui.callsinnewcontext("choosetest", char)
textbutton "End Choice" action [Hide("battle")]
screen choose(char):
modal True
frame align (0.0, 0.0):
vbox:
label "[char.name]'s Skills"
for sk in char.skills:
textbutton "[sk]" action [SetField(char, "active_skill", sk), Hide("choose")]
label chooselabel(char):
call screen choose2(char)
return
screen choose2(char):
modal True
frame align (0.0, 0.0):
vbox:
label "[char.name]'s Skills"
for sk in char.skills:
textbutton "[sk]" action [SetField(char, "active_skill", sk)]
label nested_screens:
$pc = Char("Tim", 15, ["Attack", "Defend", "Talk"])
show screen battle(pc)
"Click on each one of the buttons in turn to show how it works."
"Test Over"
hide screen battle
return
Okay, that all works. But I've been pondering the original question of returning information. So...I've been experimenting with this.
This is my experiment:
Code: Select all
init python:
class Char():
def __init__(self, name, mhp, skills=None):
self.name = name
self.curHP = mhp
self.maxHP = mhp
self.skills = skills
self.active_skill = None
screen battle(char):
default skill = None
default result = None
$result = _return
frame align (1.0, 0.0):
vbox:
label "[char.name]"
text "[char.curHP]/[char.maxHP] HP"
text "Skill to Use: [char.active_skill]"
text "Return: [result]"
text "-----"
textbutton "Choose Skill" action Show("choose", char=char)
textbutton "Choose Skill Func" action Function(renpy.call_in_new_context, "choosetest", char)
textbutton "Choose Skill Ui Call" action ui.callsinnewcontext("choosetest", char)
textbutton "End Choice" action [Hide("battle")]
screen choose(char):
modal True
frame align (0.0, 0.0):
vbox:
label "[char.name]'s Skills"
for sk in char.skills:
textbutton "[sk]" action [SetField(char, "active_skill", sk), Hide("choose")]
label choosetest(char):
call screen choose2(char)
"Returning from the choose 2 screen: [_return]"
return(_return)
screen choose2(char):
modal True #I added this for my new experiment
frame align (0.0, 0.0):
vbox:
label "[char.name]'s Skills"
for sk in char.skills:
textbutton "[sk]" action [SetField(char, "active_skill", sk), Return(sk)]
label check():
"Hello"
return("Goodbye")
label nested_screens:
$pc = Char("Tim", 15, ["Attack", "Defend", "Talk"])
"Testing return with expression."
call check
$result = _return
"Returning from the check label: [result]"
show screen battle(pc)
"Test out the three buttons."
"Test Over"
hide screen battle
return
So what you'll see that I've done is to test sending information back from a label.
So...I start with a little label check...calling that label, printing "Hello" and then returning "Goodbye." Which I print. All is good.
Then I call up the battle screen. And the battle screen has Goodbye as the return text...interesting.
Okay, so now if you try one of the two buttons that calls the chooselabel interesting things happen.
That label calls the choose2 screen. That screen then returns whichever skill you chose. You can see that it does actually return that skill because I print it.
Then I return that skill back to the first screen...but it never shows up in that battle screen.
I imagine that must have something to do with the calling in new context?
So...is there way to return a variable back to a calling screen? It worked with the random goodbye..but nothing afterwards.
Thoughts?