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.
Need some help/advice , I would like implement to our game "simple" minigame which consist of paper or photograph or map shattered to pieces and player have to put it together. I made basic set up like this :
init python:
def drag_placed(drags, drop):
if not drop:
return
store.draggable = drags[0].drag_name
store.droppable = drop.drag_name
return True
define p = Character ("Petr")
label start ():
scene pozadi
p "Hmmmm, nějaké smetí"
p "Co kdybych si s tím trochu pohrál ?"
call screen mapa
return
label mapa ():
screen mapa:
draggroup:
drag:
drag_name "mapa1"
xpos 300
ypos 500
child "mapa1.png"
draggable True
droppable False
dragged drag_placed
drag_raise True
drag:
drag_name "mapa2"
xpos 100
ypos 500
child "mapa2.png"
draggable True
droppable False
dragged drag_placed
drag_raise True
drag:
drag_name "mapa3"
xpos 200
ypos 500
child "mapa3.png"
draggable True
droppable False
dragged drag_placed
drag_raise True
return
call pokr
label pokr():
p" dfsdfsfsdfsdfsdfsdfsdf"
return
but there is lot of problems, it works but i dont know how to escpae or leave the screen with pieces and especialy how to check the pieces are in right places, how to check, player made it right.
Im sure im not first trying this type of puzzle, but i cant find solution, or i dont know how to ask google propperly.
# a puzzle piece
drag:
drag_name "piece1"
dragged obj_dragged
draggable True
droppable False
# a spot for a piece
drag:
drag_name "spot1"
draggable False
droppable True
When you drag a piece and drop it on a puzzle spot, then first obj_dragged is called for that piece. Now you just have to check if the correct piece was dropped onto it. You will leave the screen when you return something other than None.
def obj_dragged(drags, drop):
if not drop:
renpy.notify("You dropped it outside of the possible places.")
# leave the screen
return True
# something was dropped onto spot1
if drop.drag_name == "spot1"
if drags[0].drag_name == "piece1":
renpy.notify("Correct piece!")
else:
renpy.notify("Wrong piece!")
# this doesn't leave the screen
return
Last edited by m_from_space on Thu May 19, 2022 6:10 am, edited 1 time in total.
Mira1976 wrote: ↑Thu May 19, 2022 5:31 am
Need some help/advice , I would like implement to our game "simple" minigame which consist of paper or photograph or map shattered to pieces and player have to put it together. ...
Now i´m totaly lost.....After seeing this lines of codes and examples i have no idea where all that if statements and returns goes...
Try to make it easier only with two possible spots and one moveable object, but it is mess ...
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.
File "game/script.rpy", line 8: invalid syntax
if drags[0].drag_name == "ctverec" and drop.drag_name == "ctverec_drag"
Ren'Py Version: Ren'Py 7.4.11.2266
Fri May 20 11:44:00 2022
Mira1976 wrote: ↑Fri May 20, 2022 6:08 am
...Try to make it easier only with two possible spots and one moveable object, but it is mess ...
In screen 'mapa' the droppable object (the last one) should have drag_name 'ctverec_drag'.
In drag_puzzle function:
- if drags[0].drag_name=="ctverec" and drop.drag_name=="ctverec_drag" line should ends with the colon and next line (return) should be extra indented,
- in else block remove the first return otherwise values of 'draggable' and 'droppable' variables won't be stored (those lines won't be executed).
Mira1976 wrote: ↑Fri May 20, 2022 6:08 am
Now i´m totaly lost.....After seeing this lines of codes and examples i have no idea where all that if statements and returns goes...
If you call 'mapa' screen then 'return True' in 'drag_puzzle' function will end player's interactions with this screen (return from called screen) and 'return' will let player continue interactions with this screen, 'cause goal of interactions is not achieved yet.
Wow, it works. Some mistakes are still in code, I mean something about positions of objects, but i have no error messages. Great thanks for your effort.
init python:
def drag_puzzle(drags, drop):
if not drop:
return
store.draggable = drags[0].drag_name
store.droppable = drop.drag_name
if drop.drag_name == "ctverec":
if drags[0].drag_name == "ctverec_drag":
drags[0].snap(600, 500, 1.0)
renpy.notify ("correct")
else:
renpy.notify ("wrong")
define p = Character ("Petr")
label start ():
scene pozadi
p "Hmmmm, nějaké smetí"
p "Co kdybych si s tím trochu pohrál ?"
call screen mapa
return
label mapa ():
screen mapa:
draggroup:
drag:
drag_name "ctverec_drag"
xpos 1500
ypos 500
child "ctverec_drag.png"
draggable True
droppable False
dragged drag_puzzle
drag_raise True
drag:
drag_name "kruh"
xpos 100
ypos 500
child "kruh.png"
draggable False
droppable True
dragged drag_puzzle
drag_raise True
drag:
drag_name "ctverec"
xpos 600
ypos 500
child "ctverec.png"
draggable False
droppable True
dragged drag_puzzle
drag_raise True
return
label pokr:
p "dfsdfsfsdfsdfsdfsdfsdf"
palyer can move with object "ctverec_drag" and when place it to spot "ctverec" he get notify correct.(ctverec means square)
Some problems is still there. I dont know how to imlpemet this all to game, how to continue, where to call another screen or label ?
And can instead of renpy.notify my character comment what is going on ? Like " Yes i placed it right" ?
And im affraid i will not be able use this way for more pieces/shatters...
Mira1976 wrote: ↑Sat May 21, 2022 3:20 am
...palyer can move with object "ctverec_drag" and when place it to spot "ctverec" he get notify correct.(ctverec means square)
Some problems is still there. I dont know how to imlpemet this all to game, how to continue, where to call another screen or label ?
And can instead of renpy.notify my character comment what is going on ? Like " Yes i placed it right" ?
And im affraid i will not be able use this way for more pieces/shatters...
image red:
Solid("#c00")
size(100, 100)
image green:
Solid("#0c0")
size(100, 100)
image blue:
Solid("#00c")
size(100, 100)
image grey:
Solid("#ccc")
size(100, 100)
init python:
def drag_puzzle(drags, drop):
if not drop: # draggable is not dropped over droppable
return
# since droppable and draggable objects have the same names
# with differen suffixes (_drag/_drop - 5 symbols),
# will cut the suffixes and store names in variables
draggable = drags[0].drag_name[:-5]
droppable = drop.drag_name[:-5]
if draggable == droppable: # if names are match
# put the name of draggable object in a list
store.puzzle_objects_list.append(draggable)
# move draggable object to coordinates of droppable slot
drags[0].snap(drop.x, drop.y, 1.0)
# return the result of player's interaction
return "correct"
else: # names are not match
# return the result of player's interaction
return "wrong"
define p = Character ("Petr")
# list to store names of correct placed objects
default puzzle_objects_list = []
# var to turn on/off player's interaction
default can_click = True
screen mapa():
text "Move objects to the slots" align(0.15, 0.05)
draggroup:
drag:
# names of draggable objects have suffix "_drag"
# names of droppable objects have suffix "_drop"
drag_name "red_drag"
xpos 1500
ypos 200
child "red"
# object can be dragged if its name is not in 'puzzle_objects_list'
# and if player can interact with the game ('can_click')
draggable ("red" not in puzzle_objects_list and can_click)
droppable False
dragged drag_puzzle
drag_raise True
drag:
drag_name "green_drag"
xpos 1500
ypos 400
child "green"
draggable ("green" not in puzzle_objects_list and can_click)
droppable False
dragged drag_puzzle
drag_raise True
drag:
drag_name "blue_drag"
xpos 1500
ypos 600
child "blue"
draggable ("blue" not in puzzle_objects_list and can_click)
droppable False
dragged drag_puzzle
drag_raise True
drag:
drag_name "red_drop"
xpos 400
ypos 300
child "grey"
draggable False
droppable True
dragged drag_puzzle
drag_raise True
drag:
drag_name "green_drop"
xpos 400
ypos 500
child "grey"
draggable False
droppable True
dragged drag_puzzle
drag_raise True
drag:
drag_name "blue_drop"
xpos 400
ypos 700
child "grey"
draggable False
droppable True
dragged drag_puzzle
drag_raise True
# The game starts here.
label start:
p "Let's play some puzzle game."
# set the initial values for game vars
$ can_click = False
$ puzzle_objects_list = []
# if we show the screen it will be onscreen untill we hide it
show screen mapa
p "Your goal is to drop color objects over correct slots."
p "Ready. Stady. Go!"
label some_puzzle_game_loop: # game loop
$ can_click = True
$ res = ui.interact() # wait for user interaction
$ can_click = False # now user unable to interact with the game
# evaluate the result of interaction
if res == 'correct':
$ txt = renpy.random.choice(("Correct.", "Good.", "Go on."))
p "[txt]"
# we can use the information in 'puzzle_objects_list'
if len(puzzle_objects_list) == 1:
p "Still 2 to go."
elif len(puzzle_objects_list) == 2:
p "Move the last one."
else:
jump some_puzzle_game_win
elif res == 'wrong':
$ txt = renpy.random.choice(("Try the other slots.", "It doesn't fit.", "Wrong color."))
p "[txt]"
jump some_puzzle_game_loop
label some_puzzle_game_win:
p "Well done!"
hide screen mapa
"?!"
Ok im feeling like you have thought: " Jesus i have to write it for this idiot form A to Z "....
and i appreciate it and if i will not be able to finish what i want to make with this example, then i dont finish it ever.
Thank you very much.