Issues with Generating Lists

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.
Message
Author
User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Issues with Generating Lists

#1 Post by hyperionthunder »

I am having issues with my codes I am working on for the game project. I am trying to compile a list to be filled in automatically at launch for the player to adjust and customize the abilities available.

Code: Select all

init python:
    #sets up max config for displayables
    maxnumx = 7
    maxnumy = 5

    #creates class AbilityCode to store data
    class AbilityCode:
        def __init__(self, name, icon, mindamage, maxdamage, element, elementicon, target, range, equipped):
            self.name = name
            self.icon = icon
            self.mindamage = mindamage
            self.maxdamage = maxdamage
            self.element = element
            self.elementicon = elementicon
            self.target = target
            self.range = range
            self.equipped = equipped
            self.refresh_equipped()
            self.equip()

        def refresh_equipped(self):
            notequipped = False
            if not self.equipped:
                notequipped = True
            self.is_notequipped = notequipped

        def equip(self):
            if self.equipped:
                self.equipped = False
            else:
                self.equipped = True

    ability_codes = []
    #prepopulates the list with default ability codes at start of Chapter 2 Day 7
    # Name, Min Damage, Max Damage, Elemental, Target, All or Single , Active
    ability_codes.append(AbilityCode("Code: Fire", "code/code-fire.png", 15, 50, "Fire", "code/element-fire.png" "Enemy", "Single", True))
    ability_codes.append(AbilityCode("Code: Water", "code/code-water.png", 15, 50, "Water", "code/element-water.png" "Enemy", "Single", True))
    ability_codes.append(AbilityCode("Code: Wind", "code/code-wind.png", 15, 50, "Wind", "code/element-wind.png" "Enemy", "Single", True))
    ability_codes.append(AbilityCode("Code: Earth", "code/code-earth.png", 15, 50, "Earth", "code/element-earth.png" "Enemy", "Single", True))
    ability_codes.append(AbilityCode("Code: Heart", "code/code-heart.png", -200, -400, "None", "code/element-none.png" "Party", "Single", True))
when I executed it it gave me an error saying __init__ takes exactly 10 argument (9 given).

I am aware there is nine given from the ability_codes.append portion, assuming self is automatically given by python. but I am at my wits end trying to debug this.
help

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#2 Post by kivik »

I think you missed the object part of the class statement?

Code: Select all

    class AbilityCode(object):

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Re: Issues with Generating Lists

#3 Post by hyperionthunder »

I forgot a comma in each of the list. it now works correct. derp!

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#4 Post by kivik »

Btw, just had a look at your functions, you can simplify them a little bit:

Code: Select all

        def refresh_equipped(self):
            self.is_notequipped = not self.equipped # you just set it to the opposite of self.equipped

        def equip(self):
            self.equipped = not self.eqiupped # again, you can toggle a boolean variable by saying not itself

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#5 Post by kivik »

hyperionthunder wrote: Fri May 18, 2018 2:29 pm I forgot a comma in each of the list. it now works correct. derp!
Ah! Sorry I missed that, and just read up on python, looks like skipping the (object) part automatically makes it an object. Learnt something new today!

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Re: Issues with Generating Lists

#6 Post by hyperionthunder »

Now I am trying to get the screen to display toggle-able buttons to mark items equipped by the player.
Here is the image displayed on screen.

Code: Select all

## Ability Codes screen ########################################################
##
## This is an Ability Codes menu for configuring the player's five.
## ability codes slots.
screen ability_codes_menu:
    tag menu
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
        style_prefix "ability_codes_menu"
        $ ac_start = 0
        $ ac_end = len(ability_codes)
        vbox:
            text "This is a placeholder for the ability codes configuration screen."
            grid ac_maxnumx ac_maxnumy:
                text _("Code Icon")
                text _("Code Name")
                text _("Element")
                text _("Target")
                text _("Range")
                text _("Equipped")
                for i in range(ac_start, ac_end):
                    add ability_codes[i].icon
                    text ability_codes[i].name
                    if not ability_codes[i].element == "None":
                        add ability_codes[i].elementicon
                    else:
                        null
                    text ability_codes[i].target
                    text ability_codes[i].range
                    $ ability_codes[i].refresh_equipped()
                    if ability_codes[i].is_notequipped:
                        imagebutton idle "code/code-notequipped.png":
                            action ability_codes[i].equip()
                    else:
                        imagebutton idle "code/code-equipped.png":
                            action ability_codes[i].equip()

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#7 Post by kivik »

I'm confused about this, why do you need that variable when you can already access ability_codes.equipped anyway? Also I think you can condense your statement as well:

Code: Select all

                    default equip_image = "code/code-equipped.png" if ability_codes[i].equipped else "code/code-notequipped.png"
                    imagebutton:
                        idle equip_image
                        action ability_codes[i].equip()
If equipped and is_notequipped are just the opposite of each other, why have two variables? You can check equipped or not equipped and don't have to worry about refreshing the is_notequipped attribute.

You should also probably change the equip() function to be called toggle_equip() to be more reflective of what it actually does.


Finally, I'd propose another thing you can do to manage equipped abilities: use different lists and a dictionary:

Code: Select all

# define unchanged list of all abilities
define all_abilities = {} # the dictionary to store all the available abilities

label start: # let's initialise our abilities in the start label, but you can do it in another label
    python:
        all_abilities["Fire"] = AbilityCode("Code: Fire", "code/code-fire.png", 15, 50, "Fire", "code/element-fire.png" "Enemy", "Single", True)
        all_abilities["Water"] = AbilityCode("Code: Water", "code/code-water.png", 15, 50, "Water", "code/element-water.png" "Enemy", "Single", True)
        all_abilities["Wind"] = AbilityCode("Code: Wind", "code/code-wind.png", 15, 50, "Wind", "code/element-wind.png" "Enemy", "Single", True)
        all_abilities["Earth"] = AbilityCode("Code: Earth", "code/code-earth.png", 15, 50, "Earth", "code/element-earth.png" "Enemy", "Single", True)
        all_abilities["Heart"] = AbilityCode("Code: Heart", "code/code-heart.png", -200, -400, "None", "code/element-none.png" "Party", "Single", True)

        # declare your lists inside a label so that it'll be saved
        available_abilities = [all_abilities["Fire"], all_abilities["Water"], all_abilities["Wind"]]
        equipped_abilities = [all_abilities["Fire"]]
    return
This way you have an immediate access to a list of all available abilities, or equipped abilities - without having to loop through every single ability and checking whether it's equipped or not (during your battles).You can also present you equipped abilities and available abilities in two columns and click to add abilities to your equipped list. Also, if you want to know if your player has hit maximum available slots, you just do check if len(equipped_abilities) > 5.
If you struggle with that, let us know.

Meanwhile, you can still perform a check to see whether an ability is in your list or not. If you don't know already - the dicts and lists are all just storing pointers to the actual ability, so you can do:

Code: Select all

for ability in available_abilities:
    # just reference ability instead of ability_codes[i], read up on python for loops through lists
    # add your other code (modified) as needed here
    default equip_image = "code/code-equipped.png" if ability in equipped_abilities else "code/code-notequipped.png"
    imagebutton:
        idle equip_image
        action If(ability in equipped_abilities, RemoveFromSet(equipped_abilities, ability), AddToSet(equipped_abilities, ability))
What's happening here is, I'm using if ability in equipped_abilities, it checks whether ability is in the equipped_abilities list. I did a shorthand above, to set the image to show, but it's equivalent to:

Code: Select all

if ability in equipped_abilities:
    default equip_image = "code/code-equipped.png"
else:
    default equip_image = "code/code-notequipped.png"
That sets the image, and then I use the If function in the button's action: https://www.renpy.org/doc/html/screen_actions.html#If

This evaluates the results of the first parameter (if the ability is in equipped), if it's True then run the function(s) in the second parameter. RemoveFromSet is as you expect, it removes an item from a set, in this case the ability from the equipped_abilities list / set. If it's False, it adds it to the set.

All this is to take advantage of the data structures that are designed to contextualise items in your game. It should be easy to visual it as well, so I hope it's helpful!

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Re: Issues with Generating Lists

#8 Post by hyperionthunder »

I made some progress with the codes, right now i am at the point i will need to create two separate lists that is side by side horizontaly. The equipped will be on the left, and Available codes will be on the right.

In each row they will list the code icon, the name, the element icon, the target type, the range
If the item is equipped it will be on the left side, otherwise it will be on the right.

This is what I have so far.... though I got little lost on understanding the change from what I had set up before to this:

Code: Select all

## Ability Codes screen ########################################################
##
## This is an Ability Codes menu for configuring the player's five.
## ability codes slots.
screen ability_codes_menu:
    tag menu
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
        style_prefix "ability_codes_menu"
        $ ac_maxnumx = 6
        ## need to split this into two lists...
        vbox:
            grid 2 2:
                xfill True
                yfill True
                text _("Equipped Ability Codes")
                text _("Available Ability Codes")
                #equipped codes list
                grid ac_maxnumx 5):
                    xspacing 10
                    ymaximum 48
                    yspacing 2
                    for ability in equipped_ability_codes:
                        add equipped_ability_codes[ability].icon
                        text equipped_ability_codes[ability].name
                        if not equipped_ability_codes[ability].element == "None":
                            add equipped_ability_codes[ability].elementicon
                        else:
                            null
                        text equipped_ability_codes[i].target
                        text equipped_ability_codes[i].range
                        default equip_image = "code/code-equipped.png" if ability in equipped_ability_codes else "code/code-notequipped.png"
                        imagebutton:
                            idle equip_image
                            action If(ability in equipped_ability_codes, RemoveFromSet(equipped_ability_codes, ability), AddToSet(equipped_ability_codes, ability))

                #available ability codes
                viewport:
                    mousewheel True
                    draggable True
                    scrollbars "vertical"
                    side_xalign 0.5
                    #needs work on cleaning up GUI
                    grid ac_maxnumx len(available_ability_codes):
                        xspacing 10
                        ymaximum 48
                        yspacing 2
                        for ability in available_ability_codes:
                            add available_ability_codes[ability].icon
                            text available_ability_codes[ability].name
                            if not available_ability_codes[ability].element == "None":
                                add available_ability_codes[ability].elementicon
                            else:
                                null
                            text available_ability_codes[i].target
                            text available_ability_codes[i].range
                            default equip_image = "code/code-equipped.png" if ability in equipped_ability_codes else "code/code-notequipped.png"
                            imagebutton:
                                idle equip_image
                                action If(ability in equipped_ability_codes, RemoveFromSet(equipped_ability_codes, ability), AddToSet(equipped_ability_codes, ability))

updated the code slightly

now i get an error

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/ability_codes_menu.rpy", line 5, in execute
    screen ability_codes_menu:
  File "game/ability_codes_menu.rpy", line 5, in execute
    screen ability_codes_menu:
  File "game/ability_codes_menu.rpy", line 7, in execute
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
  File "game/screens.rpy", line 417, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 417, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 426, in execute
    frame:
  File "game/screens.rpy", line 429, in execute
    hbox:
  File "game/screens.rpy", line 435, in execute
    frame:
  File "game/screens.rpy", line 438, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 467, in execute
    transclude
  File "game/ability_codes_menu.rpy", line 7, in execute
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
  File "game/ability_codes_menu.rpy", line 11, in execute
    $ ac_maxnumx = 6
  File "game/ability_codes_menu.rpy", line 12, in execute
    $ ac_maxnumy = 5
  File "game/ability_codes_menu.rpy", line 17, in execute
    text _("Code Icon")
  File "game/ability_codes_menu.rpy", line 21, in execute
    text _("Range")
  File "game/ability_codes_menu.rpy", line 22, in execute
    text _("Equipped")
TypeError: list indices must be integers, not AbilityCode

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_load_save.rpym", line 35, in script
    $ ui.interact()
  File "C:\renpy\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\renpy\renpy\python.py", line 1906, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_load_save.rpym", line 35, in <module>
    $ ui.interact()
  File "C:\renpy\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\renpy\renpy\display\core.py", line 2649, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "C:\renpy\renpy\display\core.py", line 3033, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\renpy\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\renpy\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\renpy\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\renpy\renpy\display\core.py", line 511, in visit_all
    d.visit_all(callback)
  File "C:\renpy\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "C:\renpy\renpy\display\core.py", line 3033, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "C:\renpy\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "C:\renpy\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/ability_codes_menu.rpy", line 5, in execute
    screen ability_codes_menu:
  File "game/ability_codes_menu.rpy", line 5, in execute
    screen ability_codes_menu:
  File "game/ability_codes_menu.rpy", line 7, in execute
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
  File "game/screens.rpy", line 417, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 417, in execute
    screen game_menu(title, scroll=None, yinitial=0.0):
  File "game/screens.rpy", line 426, in execute
    frame:
  File "game/screens.rpy", line 429, in execute
    hbox:
  File "game/screens.rpy", line 435, in execute
    frame:
  File "game/screens.rpy", line 438, in execute
    if scroll == "viewport":
  File "game/screens.rpy", line 467, in execute
    transclude
  File "game/ability_codes_menu.rpy", line 7, in execute
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
  File "game/ability_codes_menu.rpy", line 11, in execute
    $ ac_maxnumx = 6
  File "game/ability_codes_menu.rpy", line 12, in execute
    $ ac_maxnumy = 5
  File "game/ability_codes_menu.rpy", line 17, in execute
    text _("Code Icon")
  File "game/ability_codes_menu.rpy", line 21, in execute
    text _("Range")
  File "game/ability_codes_menu.rpy", line 22, in execute
    text _("Equipped")
  File "<screen language>", line 22, in <module>
TypeError: list indices must be integers, not AbilityCode

Windows-8-6.2.9200
Ren'Py 7.0.0.108
The Wanderers 0.90
Fri May 18 21:08:57 2018

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#9 Post by kivik »

Reread the for loop i posted, you no longer reference the list when you use a for loop to iterate through the list items itself. The idea of for item in list_of_items is that it just loops through every item in your list, so you can directly manipulate the item within the scope of the for loop:

Pseudo code (for reading the concept only, not executable code)

for item in list_of_items:
> item < this is the item in the list you directly manipulate, no need to use indices . In fact i doesn't exist, i only exists when you do for i in range(0, 5) for example.

Have a read through this as well where it explains the different types of for loops you can do in python: http://treyhunner.com/2016/04/how-to-lo ... in-python/

Hopefully that clears up what's going on and will help you figure out how to redo your list.

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Re: Issues with Generating Lists

#10 Post by hyperionthunder »

I have made major progress and I am getting very close to having this screen done. Instead of making two separate list on screen, i simplified it to a grid of 8x8 to display all available abilities the player can equip and then have the user click on the icon to toggle the equip status. It still uses two separate dict/set to track them.

here is the screen code:

Code: Select all

## Ability Codes screen ########################################################
##
## This is an Ability Codes menu for configuring the player's five.
## ability codes slots.
screen ability_codes_menu:
    tag menu
    use game_menu(_("Ability Codes Configuration"), scroll="ability_codes_menu"):
        style_prefix "ability_codes_menu"
        ## need to split this into two lists...
        vbox:
            grid 8 8:
                xmaximum 50
                ymaximum 50
                spacing 10
                for ability in range(len(available_ability_codes)):
                    # plot in each available codes in grid of 8 x 8
                    # totalling up to 64 possible codes. If they
                    # are not found, they will be marked as locked.

                    if available_ability_codes[ability].found:
                        #checks if the AC is equipped, otherwise it will be unequipped.
                        default equip_image = available_ability_codes[ability].icon if ability in equipped_ability_codes else available_ability_codes[ability].unequipicon
                        imagebutton:
                            idle equip_image
                            action If(ability in equipped_ability_codes, RemoveFromSet(equipped_ability_codes, ability), AddToSet(equipped_ability_codes, ability))
                            hovered SetVariable("ac_look", ability)
                    else:
                        #if found is flagged false, then lock image is shown
                        add available_ability_codes[ability].locked
                for i in range(total_ac_count, 64):
                    add "locked_ac"

            # text "Number of codes available: [total_ac_count]"
            grid 8 2:
                xfill True
                yspacing 10
                #shows a detailed information about the hovered ability code
                text _("Icon")
                text _("Ability Name")
                text _("Element")
                text _("Min Damage / Heal")
                text _("Max Damage / Heal")
                text _("Target")
                text _("Range")
                text _("Status Effect")
                add available_ability_codes[ac_look].unequipicon
                text available_ability_codes[ac_look].name
                add available_ability_codes[ac_look].elementicon
                if available_ability_codes[ac_look].mindamage > 0:
                    text "%s" % available_ability_codes[ac_look].mindamage
                else:
                    text "%s" % available_ability_codes[ac_look].minheal
                if available_ability_codes[ac_look].maxdamage > 0:
                    text "%s" % available_ability_codes[ac_look].maxdamage
                else:
                    text"%s"  % available_ability_codes[ac_look].maxheal
                text available_ability_codes[ac_look].target
                text available_ability_codes[ac_look].range
                text available_ability_codes[ac_look].status
            text available_ability_codes[ac_look].desc
#### Functions
label EquipAbility(value):
    if len(equipped_ability_codes) < 5:
        #Have less than 5 equipped. Can add more.I
        if value in equipped_ability_codes:
            $ RemoveFromSet(equipped_ability_codes, value)
        else:
            $ AddToSet(equipped_ability_codes, value)
    else:
        #limit of 5 codes exceeded. Can not add more.
        $ renpy.notify("You can not equip no more than 5 Ability Codes!")
    return
And the list system:

Code: Select all

init python:

    #define unchanged list of all abilities
    all_ability_codes = {} #defines full dictionary to house ability codes

    #creates class AbilityCode to store data
    class AbilityCode:
        def __init__(self, name, desc, icon, unequipicon, mindamage, maxdamage, minheal, maxheal, element, elementicon, target, range, status, found, locked="locked_ac"):
            self.name = name
            self.desc = desc
            self.icon = icon
            self.unequipicon = unequipicon
            self.mindamage = mindamage
            self.maxdamage = maxdamage
            self.minheal = minheal
            self.maxheal = maxheal
            self.element = element
            self.elementicon = elementicon
            self.target = target
            self.range = range
            self.status = status
            self.found = found
            self.locked = locked

    #might move this into it's own .rpy file to house all of the available codes.
    # Name, Min Damage, Max Damage, Elemental, Target, All or Single , Active
    all_ability_codes["Fire"] = AbilityCode("Code: Fire ɑ", "A small ball of firey death.", "code_fire_a_on", "code_fire_a_off", 15, 50, 0, 0, "Fire", "element_fire", "Enemy", "Single", "none", True)
    all_ability_codes["Water"] = AbilityCode("Code: Water ɑ", "A small ball of watery death.", "code_water_a_on", "code_water_a_off",15, 50, 0, 0, "Water", "element_water", "Enemy", "Single", "none", True)
    all_ability_codes["Wind"] = AbilityCode("Code: Wind ɑ", "A small ball of windy death.", "code_wind_a_on", "code_wind_a_off",15, 50, 0, 0, "Wind", "element_wind", "Enemy", "Single", "none", True)
    all_ability_codes["Earth"] = AbilityCode("Code: Earth ɑ", "A tiny ball of stone.", "code_earth_a_on", "code_earth_a_off",15, 50, 0, 0, "Earth", "element_earth", "Enemy", "Single", "none", True)
    all_ability_codes["Light"] = AbilityCode("Code: Heal ɑ", "A simple healing spell. Nuff said.", "code_heal_a_on", "code_heal_a_off",  0, 0, 200, 400, "Light", "element_light", "Party", "Single", "none", True)
    all_ability_codes["Dark"] =  AbilityCode("Code: Dark ɑ", "Dark energy that also blinds target.", "code_dark_a_on", "code_dark_a_off", 120, 140,  0, 0, "Dark", "element_dark", "Enemy", "All", "Blind", False)
    all_ability_codes["Physical"] = AbilityCode("Code: Heavy Swing", "A moderate physical attack that can also stun.", "code_heavyswing_on", "code_heavyswing_off", 60, 80,  0, 0, "Physical", "element_physical", "Enemy", "Single", "Stun", False)
    all_ability_codes["Psychic"] = AbilityCode("Code: Scan", "Scans your target for elemental weakness.", "code_scan_on", "code_scan_off", 0, 0, 0, 0, "Psychic", "element_psychic", "Enemy", "Single", "Scan", False)
    available_ability_codes = [all_ability_codes["Fire"], all_ability_codes["Water"], all_ability_codes["Wind"],all_ability_codes["Earth"],all_ability_codes["Light"],all_ability_codes["Dark"],all_ability_codes["Physical"],all_ability_codes["Psychic"]]
    equipped_ability_codes = [all_ability_codes["Fire"], all_ability_codes["Water"] ]

    total_ac_count = len(available_ability_codes)
    max_ac_display = 64 - total_ac_count
    ac_look = 0
Issue #1
The displayable works fine, but I ran into two issues that I am trying to figure out.

Firstly the icons all show like this instead of their correct icons.
Mousing over the icons shows the correct icons in the detail information section however.

Issue #2
For some reason the equipped icon is not switching, or displaying the equipped icon correctly. I have put the two abilities into the equipped list to check and see if the logic is working.


Do you have any ideas about these two issues?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#11 Post by kivik »

You issue 1 won't make sense to us as we don't know how it's supposed to look.

Although one mistake I've spotted (from my code) is that default probably shouldn't be declared inside the loop but at the start of the screen. I'm not sure if it causes an issue.

Code: Select all

screen ability_codes_menu:
    default equip_image = ""

...
# inside your for loop:
equip_image = whatever it should be here (this is not code)
Also, you're still not using the for loop properly, you're still creating a range when you don't need to... You're making it way way way way way way way way way more complicated than it should be, and it's probably what's cause Issue 2. Did you read the link I sent you from start to finish? It talks about iterating through lists in it, but you may have missed it if just you skim read it.


For loop works by just iterating through a list of values:

Code: Select all

for items in [item1, item2, item3]:
    items == item1 in first iteration, item2 in second iteration, item3 in third iteration
In fact when you do for i in range(0, 10):, what's happening is that a list is created with [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] in it, and each iteration goes through the list one by one.

So when you have a list of items, you don't want to do any ranges at all, because you can actually just iterate through the items directly, hence my code above:

Code: Select all

for ability in available_abilities:
    # just reference ability instead of ability_codes[i], read up on python for loops through lists
    # add your other code (modified) as needed here

What happened in your case was, you have two lists, and their indices refer to different items. You then used the index of one list on your second list, which points to a different item. That's not how it works.

So once again, please, read what I'm telling you above. No codes, learn for loops, learn how it works, understand it, then revisit your code :)

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Re: Issues with Generating Lists

#12 Post by hyperionthunder »

After reading through your suggestions, i finally figured it out and made it work. My next step is to code in a way to cap the number of equipped abilities to 5. I am looking at this portion of the code and I am figuring out how to program the logic in a button.

Code: Select all

action If(ability in equipped_ability_codes, RemoveFromSet(equipped_ability_codes, ability), AddToSet(equipped_ability_codes, ability))
if i want to limit it like this with len() < 5

Code: Select all

if len(equipped_ability_codes) < 5:
        #Have less than 5 equipped. Can add more.
        if value in equipped_ability_codes:
            $ RemoveFromSet(equipped_ability_codes, ability)
        else:
            $ AddToSet(equipped_ability_codes, ability)
    else:
        #limit of 5 codes exceeded. Can not add more.
        $ renpy.notify("You can not equip no more than 5 Ability Codes!")
how can i trigger this following logic from the button? Should I have it called like a function?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#13 Post by kivik »

Yes, function should work.

https://www.renpy.org/doc/html/screen_a ... l#Function

You may want to look into objects and classes in the long run though, it'll make your code a lot more readable and you can group logic together based on context.

User avatar
hyperionthunder
Regular
Posts: 51
Joined: Fri May 18, 2018 2:10 pm
Projects: The Wanderers
Deviantart: hyperionthunder
itch: hyperionthunder
Contact:

Re: Issues with Generating Lists

#14 Post by hyperionthunder »

Ok this is what I think it should be:
for imagebutton

Code: Select all

action Function(CheckEquip(), ability)
and the function to call it

Code: Select all

init python:
	class CheckEquip:
     	   def __call__(self, check):
       	    	self.check = check
            	if len(equipped_ability_codes) < 6:
                	if self.check in equipped_ability_codes:
                    		RemoveFromSet(equipped_ability_codes, self.check)
                	else:
                    		AddToSet(equipped_ability_codes, self.check)
            	else:
                	renpy.Notify("You can not equip more than 5 Ability Codes at once!")
Am I on the right track?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issues with Generating Lists

#15 Post by kivik »

Tweaked it a bit for you, not sure if that's everything though. I tend to test my code for errors as I'm not that sharp on picking up errors!

I can't remember if you need to use global or not in functions as well.

Code: Select all

action Function(CheckEquip, equipment=ability) # remove the brackets, just need function name, add parameter name just to be on the safe side

Code: Select all

init python:
    def CheckEquip(ability): # define a function, not a class, also use a more contextual variable name
        if len(equipped_ability_codes) < 5: # this should be 5 or they can equip a 6th abililty
            if ability in equipped_ability_codes:
                equipped_ability_codes.append(ability) # use python functions in python, not screen actions
            else:
                equipped_ability_codes.remove(ability)
        else:
            renpy.Notify("You can not equip more than 5 Ability Codes at once!")    

Post Reply

Who is online

Users browsing this forum: No registered users