I am trying to make a drag and drop game, but I am encountering some errors with line 100. My game starts up but does not display the player character with an updated outfit. Here is the error:
While running game code:
File "game/script.rpy", line 100, in script
e "{color=#FFFFFF}{vspace=75}The {selected_outfit['name']} outfit was put on {droppable}.{/color}"
KeyError: "'name'"
Here is the full code:
init python:
# Define the outfit function first
def outfit(outfit_name):
# Your outfit logic here
if outfit_name == "top_0":
outfit_data = {
"name": "Top 0",
# Add other relevant data for top_0
}
elif outfit_name == "top_1":
outfit_data = {
"name": "Top 1",
# Add other relevant data for top_1
}
elif outfit_name == "top_2":
outfit_data = {
"name": "Top 2",
# Add other relevant data for top_2
}
else:
# Handle the case where an unknown outfit name is provided
raise ValueError(f"Unknown outfit name: {outfit_name}")
return outfit_data # Replace with the actual data for the outfit
# Declare characters used by this game. The color argument colorizes the
# name of the character.
define e = Character("Lon")
define top_0 = outfit("top_0")
define top_1 = outfit("top_1")
define top_2 = outfit("top_2")
init python:
# Define outfits using combinations of clothing items.
outfit_1 = [top_0]
outfit_2 = [top_1]
outfit_3 = [top_2]
def drag_placed(drags, drop):
if not drop:
return
store.draggable = drags[0].drag_name
store.droppable = drop.drag_name
return True
# The game starts here.
label start:
# Show a background. This uses a placeholder by default, but you can
# add a file (named either "bg room.png" or "bg room.jpg") to the
# images directory to show it.
scene bg room:
xzoom 3.27 yzoom 1.93
# This shows a character sprite. A placeholder is used, but you can
# replace it by adding a file named "eileen happy.png" to the images
# directory.
hide screen drag_sample1A
hide screen drag_sample1B
call screen drag_sample2
screen drag_sample():
vbox:
text "This is a drag sample screen."
textbutton "Close" action Return()
# Determine the selected outfit based on top_0, top_1, and top_2
python:
selected_outfit = None
droppable = None
# Your logic to determine the values of selected_outfit and droppable
if store.droppable == "The Left Circle":
xpos_var = 150
selected_outfit = top_0
droppable = "The Left Circle"
else:
xpos_var = 640
selected_outfit = top_1 if store.draggable == "triangle" else top_2
droppable = "Some Other Droppable" # Replace with the actual value
# Show the selected outfit based on the variable selected_outfit
if selected_outfit == top_0:
show circle:
xpos xpos_var ypos 460
elif selected_outfit == top_1:
show triangle:
xpos xpos_var ypos 460
elif selected_outfit == top_2:
show square:
xpos xpos_var ypos 460
e "{color=#FFFFFF}{vspace=75}The {selected_outfit['name']} outfit was put on {droppable}.{/color}"
# This ends the game.
return
return
screen drag_sample2:
draggroup:
drag:
drag_name "Top0"
child "top_0.png"
xpos 100
ypos 100
draggable True
droppable False
dragged drag_placed
drag_raise True
drag:
drag_name "Top0"
child "top_1.png"
xpos 400
ypos 100
draggable True
droppable False
dragged drag_placed
drag_raise True
drag:
drag_name "Top"
child "top_2.png"
xpos 700
ypos 100
draggable True
droppable True
dragged drag_placed
drag_raise True
drag:
drag_name "Lon"
xpos 0.75
ypos 0.0
child "sweet_base.png"
draggable False
droppable True
screen drag_sample3:
draggroup:
drag:
drag_name "Lon"
xpos 0.40
ypos 0.00
child "sweet_base.png"
draggable False
droppable False
Errors when making drag and drop dress up game
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.
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.
Re: Errors when making drag and drop dress up game
So I got my game to work, please ignore this message, the issue has been solved.
Who is online
Users browsing this forum: Google [Bot]