This code allows you to wait until the user clicks an NPC, then you talk to the NPC, then once finished, it returns you to where you were before. You could click on the NPC over and over again if you want. IMPORTANT: With this code, you can create a scene with arrow navigation/movement as imagebuttons, multiple npc's who wait to be spoken to (represented as imagebuttons), or objects(bucket, hammer) laying about that you can interact with, represented as imagebuttons. The important part is that it always returns to the original waiting for input mode, which Ren'py achieves through the use of call screen.
CLICK FOR ANIMATED GIF PREVIEW - wait 2 seconds for it to kickin. This forum cannot show an animated gif, or maybe it can?
Code: Select all
image bg forestbackground = "areas/forest.jpg"
label start:
#show your background
scene bg forestbackground
jump loopTest
return
label loopTest:
#this screen contains imagebuttons of npcs, objects, navigation arrows, whatever you want.
call screen wait_for_user_input
# this screen houses your imagebuttons of npcs, interactable objects like a hammer, bucket, or arrows that allow you to move from room to room
# see where it says ACTION JUMP?? You can perform any action there, like calling a function that moves you to a different location
# or jumps to a conversation with an npc, or jumps to a function after clicking a hammer, etc.
screen wait_for_user_input():
modal True
zorder 0
hbox:
xalign 0.5
yalign 0.5
imagebutton:
# this string represents npc_idle.png and npc_hover.png in the image folder
auto "npc_%s.png"
focus_mask True
action Jump ("talk_to_NPC_Bob")
label talk_to_NPC_Bob:
"hello, i'm bob npc, let us speak."
"I'm the player, bla bla bla"
"we're finished."
#IMPORTANT - this is the most important part, it returns back to the loop.
# basically what happened is that you saw the npc, clicked on him, he disappears, from the background and can come to the foreground to talk with player
# then after he's done talking, he returns back to the background.
jump loopTest