philippj / SteamworksPy

A working Python API system for Valve's Steamworks.
MIT License
212 stars 39 forks source link

Python 3 automatically encodes strings as unicode, but Ctype deals with strings in ascii #81

Open AdamKormos opened 1 year ago

AdamKormos commented 1 year ago

Hey all, I just found this API today because I was requested to implement steam achievements for a game. I automatized the achievement example sample code a bit, and had to debug for a long session, trying to figure out why setting stats and achievements (SetStat() and SetAchievement()) didn't go through. I've looked up many websites and scrolled the official steamworks documentation quite a lot, until I found this post: https://lightrun.com/answers/philippj-steamworkspy-setstat-always-fails This person also fought the same issue, and figured out the strings passed into the API's parameters need to be explicitly told to be encoded to ascii. After I put ".encode('ascii')" after every string parameter for getter/setter API functions, things started to work for me! I'd advise adding the same encoding functions to string parameters before they're passed to the actual function, as such:

    def SetAchievement(self, name: str) -> bool:
        """Set a given achievement

        :param name: str
        :return: bool
        """
        return self.steam.SetAchievement(name.encoding('ascii'))
philippj commented 1 year ago

Hi, thanks for reporting this. I will check out the described behavior.