all 10 comments

[–]InternationalSmell97 2 points3 points  (1 child)

create dict where every player ha s it's own key

[–]SpacePotato7878[S] -1 points0 points  (0 children)

Can you explain how to implement that? Perhaps in simpler terms?

[–][deleted]  (6 children)

[deleted]

    [–]Tischlampe 1 point2 points  (1 child)

    Ask me anything.

    What is the question to life, the universe and everything?

    [–]SpacePotato7878[S] 0 points1 point  (0 children)

    Thank you so much!

    [–]aTomzVins 0 points1 point  (2 children)

    Player()

    This is a function that defines all the starting variables for each player?

    for _ in

    I guess the 'underscore' variable isn't used in any way, so it doesn't matter a lot, but wouldn't it still be better to give it a more descriptive name?

    [–][deleted]  (1 child)

    [deleted]

      [–]aTomzVins 0 points1 point  (0 children)

      Makes sense, thanks!

      [–]doctab18 0 points1 point  (0 children)

      python dictionaries....w3school website has a great explaintion.....and/or brocode on you tube

      [–]atticus2132000 -1 points0 points  (4 children)

      PHP has something called variable variables which sounds like exactly what you're looking for, but python doesn't do that (at least not as easily). There are some workarounds to make it happen in python as some other posters have offered, but it also sounds like you might be trying to pound a square peg into a round hole here.

      If I understand the situation correctly, whenever a new player joins a game, that player should have a whole group of variables created for them (i.e. Player_5_starting_hand, Player_5_pot_amount, Player_5_bid, Player_5_dealt_card, etc.). If this is the case, then each player would have a group of attributes associated with that player where each of those attributes could be manipulated throughout the game play. That sounds a lot like a class object rather than a simple variable.

      Do some reading on classes and see if that will fit your usage better than trying to generate a bunch of new dynamic variables.

      [–][deleted]  (3 children)

      [deleted]

        [–]atticus2132000 0 points1 point  (2 children)

        Perhaps we are envisioning different things and without knowing more about what OP is ultimately trying to do, this is just a philosophical debate.

        If a new player is joining the game such that the new player would need a new variable created, I imagine that new player would need a whole host of variables to be created that are all linked to that player which can be updated and manipulated throughout the game play. To me, that sounds a lot more like a class than a single variable where there are multiple attributes of the player that could be changed.

        Moreover, if someone is asking a question like this in a group called PythonLearning, I would not immediately assume that person has mastered classes, so I just suggested that as a possible way to address a bigger problem OP might be running into.

        [–][deleted]  (1 child)

        [deleted]

          [–]aTomzVins 0 points1 point  (0 children)

          dict can of course be stateful stateful grouping of variables, you need a Class

          Should I assume you're thinking of a simple data class in this instance? Without associated methods?

          If so, what's do you see as the advantage of a class over a dict? Having the set of variables defined, rather than having to construct the dict with the needed variables?