Drag/Drop, Appending Lists, & Multiple Character Assignments

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.
Post Reply
Message
Author
StValentines
Regular
Posts: 37
Joined: Mon Aug 26, 2019 2:08 am
Projects: St. Valentine's Academy for Magical Girls
Contact:

Drag/Drop, Appending Lists, & Multiple Character Assignments

#1 Post by StValentines »

This is gonna take some explaining, so thanks/sorry in advance.

I'm working on a story-based travel sim. Each week of travel, the player chooses how they'll go about it, such as travel speed and what activities to focus, and the week plays out with a series of randomized events based on those choices. One of the main mechanics here is the player assigning characters to specific roles for the week (security to fight off unexpected attacks, hunting to find food, diplomacy to parlay with anyone they meet, etc.).

I managed to make a (very) basic drag/drop interface for making the assignments, thanks to this forum post, and once I made some adjustments for my purposes it's worked wonders. The attached screenshots show it in action (with, again, not-even-remotely-final design or art assets), for reference. It works perfectly as it currently stands.

The issue is that there are multiple characters the player can choose to take on the journey with them. I have four programmed in right now, but will add more, and the player chooses anywhere between 1-3 of them to bring with them for the whole game. Theoretically, this should be possible, because the code for the assignments screen uses a list:

Code: Select all

    $ items_list = [
        {"name":"brawler", "child":"icon_brawler.png", "default_x_pos":1500, "default_y_pos":420, "x_pos":1500, "y_pos":420},
        {"name":"politician", "child":"icon_politician.png", "default_x_pos":1500, "default_y_pos":740, "x_pos":1500, "y_pos":740},
        {"name":"reader", "child":"icon_reader.png", "default_x_pos":1500, "default_y_pos":100, "x_pos":1500, "y_pos":100},
        ]
And the code in the screen uses all the information on each list entry to place each of the appropriate icons in those three spots on the right side of the screen:

Code: Select all

    draggroup:

        for each_slot in slots_list:
            drag:
                drag_name each_slot["name"]
                draggable False
                child each_slot["child"]
                xpos each_slot["x_pos"] ypos each_slot["y_pos"]

        for each_item in items_list:
            drag:
                drag_name each_item["name"]
                child each_item["child"]
                droppable True
                dragged my_dragged
                xpos each_item["x_pos"] ypos each_item["y_pos"]
But of course, I can't just drop all the characters in that list, because not all characters will be in the game at the same time. So I think I need to start this list off empty, and add each character as I go. But I tried using append.item and I get an invalid syntax error, which I was afraid of since the only reference I can find for append.item only uses single-word terms, rather than the multi-part items that came as part of that code I used. I assume append.item doesn't know what to do with all the extra stuff in each of those list entries, and I don't know how to fix that if so.

So in short, I need to figure out how to add items like the ones above to a list, and append.items isn't doing it. How can I make this work so I can pick characters near the beginning of the game and have the choices added to the list so they work in this drag/drop screen?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Drag/Drop, Appending Lists, & Multiple Character Assignments

#2 Post by Remix »

You can still keep that (base) list just for the data and just iterate the team you want...

Code: Select all

## Note: Using default, not $
## This is just data
default items_list = [
        {"name":"brawler", "child":"icon_brawler.png", "default_x_pos":1500, "default_y_pos":420, "x_pos":1500, "y_pos":420},
        {"name":"politician", "child":"icon_politician.png", "default_x_pos":1500, "default_y_pos":740, "x_pos":1500, "y_pos":740},
        {"name":"reader", "child":"icon_reader.png", "default_x_pos":1500, "default_y_pos":100, "x_pos":1500, "y_pos":100},
        ]

## Our team
##
## This is the list we add/delete/tweak when the player chooses their team members
##
default chosen_team = ["brawler", "reader"]

screen whatever():
     # ...
        # Using list comprehension we create a dynamic list using only those items where the "name" is in our team
        for each_item in [k for k in items_list if k['name'] in chosen__team]: 
            drag:
                drag_name each_item["name"]
                child each_item["child"]
                droppable True
                dragged my_dragged
                xpos each_item["x_pos"] ypos each_item["y_pos"]

Frameworks & Scriptlets:

StValentines
Regular
Posts: 37
Joined: Mon Aug 26, 2019 2:08 am
Projects: St. Valentine's Academy for Magical Girls
Contact:

Re: Drag/Drop, Appending Lists, & Multiple Character Assignments

#3 Post by StValentines »

Thanks so much! I tried implementing it, and I think it works, but I'll have to test it more thoroughly after I charge my laptop.

One more question; does this provide a way for me to make their default positions on the drag/drip vary, too? I don't want empty spots for characters that aren't in the party, so I want the three party members to show up in the order they were picked (so they'll always take up the same three slots instead of static locations). I already have ways for the game to know what order they were picked in, so my first thought is to include three variants on the list entries so I can add the appropriate one when a character is picked at the beginning. But I feel like that's kind of an inelegant solution.

Post Reply

Who is online

Users browsing this forum: Google [Bot], recreation, voluorem