Skip to content

Why are the functions defined using a private sub-function? #4

Description

@cowlicker12

This might be an advanced python technique that I'm not aware of, but why is there a private version of a function inside of the function? For example:

# Summon a card from deck to hand. Does not check validity rules.
def normal_summon(pf, player, cardind, fpos, cardfaceind=FACE_UP_ATK):
    def _normal_summon():
        pf.FIELD[player][fpos].insert(0, pf.HAND[player].pop(cardind))
        pf.FIELD[player][fpos][0]["cardface"] = cardfaceind
        pf.PREV_NORM_SUMMON = pf.ROUND_CNT
        return pf.FIELD[player][fpos]

    pf.AS.append(_normal_summon)

Inside of normal_summon(), we have _normal_summon(). Why is this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions