Ok let me try to re-explain what I am doing (full demo script at the end of this block):
Here is a simple dialog script:
Code: Select all
label scene_1:
A "Hello!"
B "Hello, how are you?"
A "I'm fine, thank you! And you?"
B "I'm fine too, let's have fun now!"
A "Yes! Here are the sausages!"
While playing this, I want the player to have, at any time, the ability to do special actions.
Special actions are basically like choices BUT you can do them at any moment in a dialog, so you don't have to actual hint that tells you that the story is branching now.
It's just a gameplay feature.
So, I have this menu with buttons displayed, which is defined something like this:
Code: Select all
screen special_actions_screen():
window id "special_actions_window":
# place the window on the right of the screen
vbox:
# ...
button:
text "Smile/Grin"
action Jump("on_smile_1") # for this example, let's assume that this never change
button:
text "Punch In The Face"
action Jump("on_punch_1") # for this example, let's assume that this never change
The player then have the possibility to punch anyone in the face at any moment and to smile/grin at any moment too,
which might have or not an actual effect on the ongoing context.
Now let's say I have these reactions:
Code: Select all
label on_smile_1:
"My grin shines a lot."
"It makes everybody smile in the room too!"
"I feel happy but a bit dumb too, but oh well..."
return #Back to the previous dialog.
label on_punch_1:
"After this, everything went very fast."
"I ended up in jail..."
"...and stayed there until the end of my life."
# The game ends here.
Take notice of the "return" command at the end of on_smile_1.
on_punch_1 is designed as a simple branch in the story: if the player punch someone in the face with no reason,
he ends up in jail. It's just a branch.
In this case, defining the punch button action as shown before:
does work because "jump" just branch the story to somewhere else without keeping the call "stack".
So it is fine.
However, on_smile_1 is designed so that this small bit of dialogue gets "injected" into the dialog being played at the point the player pressed the button.
In this example's code, you can see that at the end of on_smile_1 we "return" because after this small ellipsis we need to get back
to the previous dialog, whatever it is, at whatever point it was when the player pressed the button.
So at this point, what I need is actually
the "call" statementas the action to be run when the smile/grin button is pressed.
Something that would look like this:
Code: Select all
action Call("on_smile_1") # Error: Call does not exists
Unfortunately this does not work. I see a "renpy.Call" class in the Renpy source code but it does not seem to be accessible from this point.
This seems consistent with
the actions documentation describing a Jump action (equivalent to the jump statement) but not a Call action (which would have been equivalent to the call statement).
Now, another way to do what I want here, that actually seem to work, is to use the
Function action which calls an arbitrary python callable. I assumed that the "call" statement was a callable and wrote something like this:
Code: Select all
action Function(renpy.call, label="on_smile_1") # equivalent to "call on_smile_1", ugly but seems to work
This works: pressing the button will run the on_smile_1 dialog, and it's "return" statement will jump back to the previous dialog.
Now a run of the game where I press the smile button at a random point of the scene would look like this (from the player POV):
A "Hello!"
B "Hello, how are you?"
# HERE I PRESS THE SMILE BUTTON
"My grin shines a lot."
"It makes everybody smile in the room too!"
"I feel happy but a bit dumb too, but oh well..."
A "I'm fine, thank you! And you?"
B "I'm fine too, let's have fun now!"
# HERE I PRESS THE SMILE BUTTON AGAIN, BECAUSE I CAN
"My grin shines a lot."
"It makes everybody smile in the room too!"
"I feel happy but a bit dumb too, but oh well..."
A "Yes! Here are the sausages!"
Here is a complete renpy script demonstrating how it works.
Code: Select all
screen special_actions_screen():
window id "special_actions_window":
at topright
# place the window on the right of the screen
vbox:
at right
# ...
button:
text "Smile/Grin"
action Function(renpy.call, label="on_smile_1") # ugly but works as expected
button:
text "Punch In The Face"
action Jump("on_punch_1")
label start:
show screen special_actions_screen
define A = Character(name="Anna")
define B = Character(name="Barbara")
jump scene_1
label scene_1:
A "Hello!"
B "Hello, how are you?"
A "I'm fine, thank you! And you?"
B "I'm fine too, let's have fun now!"
A "Yes! Here are the sausages!"
"Happy Ending."
return
label on_smile_1:
"My grin shines a lot."
"It makes everybody smile in the room too!"
"I feel happy but a bit dumb too, but oh well..."
return #Back to the previous dialog.
label on_punch_1:
"After this, everything went very fast."
"I ended up in jail..."
"...and stayed there until the end of my life."
"BAD ENDING"
return
Just try to "smile" at any point in the dialog and you will see that you get back right at the point you branched out.
Now, my question is: why isn't there a "Call" action already? There is a "Jump" one, but no "Call".
Or does the developers need a pull request? I'm not sure I can find the time but I can try.