Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetStat always fails #38

Open
dilpil opened this issue Apr 20, 2020 · 11 comments
Open

SetStat always fails #38

dilpil opened this issue Apr 20, 2020 · 11 comments
Assignees
Labels
bug Stuff related to general bugs callbacks Stuff related to Steam callbacks

Comments

@dilpil
Copy link

dilpil commented Apr 20, 2020

SetStatInt fails every time, returning false and printing no other info. Is there any way to debug whats going on?

My code is:

from steamworks import STEAMWORKS()
sw = STEAMWORKS()
sw.initialize()
sw.RequestCurrentStats()
sw.SetStat('wins', 1)

I've also tried calling

sw.run_callbacks()

which produces the following error each time:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-b1942092c4aa> in <module>
----> 1 sw.run_callbacks()

C:\PythonRL\steamworks\__init__.py in run_callbacks(self)
    191             raise SteamNotLoadedException('STEAMWORKS not yet loaded')
    192
--> 193         self.RunCallbacks()
    194         return True
    195

AttributeError: 'STEAMWORKS' object has no attribute 'RunCallbacks'

I feel like I must be doing something fundamentally incorrect here, but I have no idea what it might be.

@Gramps Gramps added bug Stuff related to general bugs callbacks Stuff related to Steam callbacks labels Apr 20, 2020
@Gramps
Copy link
Collaborator

Gramps commented Apr 20, 2020

Hey there. Hmm, I wonder if the stats issue has to do with the restructuring of the module. I assume you have "wins" set up in your Steamworks back-end. You should be able to run SetStats outside of the Steam client still.

Is it possible to try a simple test like you have using the legacy branch? I can attempt a test of the newer module system this week.

As for the callbacks issue, it seems a little odd it would raise the exception yet still try to run callbacks. Also I don't see the actual RunCallbacks function anywhere... so that needs fixed.

Thanks for bringing this all up and let me know if you can do the legacy branch test; and if so what happens!

@dilpil
Copy link
Author

dilpil commented Apr 23, 2020 via email

@dilpil
Copy link
Author

dilpil commented Apr 23, 2020 via email

@dilpil
Copy link
Author

dilpil commented Apr 23, 2020 via email

@Gramps
Copy link
Collaborator

Gramps commented Apr 23, 2020

As for legacy, it would require the older version of SteamworksPy.dll, I think. Which may or may not be the cause of that issue.

As far as examples, I pulled up my seven year old Python game to check and here are some relevant code chunks:

# Boot up Steam stuff
Steam.Init()
STEAM_NAME = SteamFriends.GetPlayerName()
STEAM_FRIENDS = SteamFriends.GetFriendCount()
SteamUserStats.RequestCurrentStats()

My first Python game project did not use callbacks and I was able to use stats and achievements fine. Making the call to RequestCurrentStats doesn't really need a callback; the callback just let's you know the call was successful or not, though it is generally a good idea to wait for a response before doing anything after that.

Here is setting stats and achievements, StoreStats is required for Steam to recognize either has happened:

SteamUserStats.SetStat('saboteurs', pc.BEEN_SABOTEUR)
SteamUserStats.SetAchievement(boot.ACHIEVE_NAME)

# Save statistics to Steam
SteamUserStats.StoreStats()

Here is getting stats and achievements:

pc.ASPIRIN_TOTAL = SteamUserStats.GetStatInt('immune_pills_all')

if SteamUserStats.GetAchievement('ACHIEVEMENT_1'):
		pc.ACHIEVEMENTS[1] = 'y'

Hopefully that helps.

Right now I am going through and updating SteamworksPy to 2.1, which is a rather large update including a lot of new stuff. Callbacks is one of them. As I don't make games in Python anymore, testing might be a bit tricky, though I wager I can still use my exist Steam games with Python in test.

@dilpil
Copy link
Author

dilpil commented Apr 28, 2020 via email

@Gramps
Copy link
Collaborator

Gramps commented Apr 28, 2020

Hmm, that is definitely a truncation issue. I know in C++ that'll happen if you use the wrong quotes; ' instead of " will not allow multiple characters.

Since we have a direct cause, that'll make it easy to solve and I'll make sure it is in the update I'm working on. Thanks for the info!

@dilpil
Copy link
Author

dilpil commented Jun 16, 2020

I figured out what was going on-
Python 3 auto encodes strings as unicode.
Ctypes deals in ascii.

The following works fine:

`
from steamworks import STEAMWORKS()

sw = STEAMWORKS()

sw.initialize()

sw.RequestCurrentStats()

sw.SetStat('wins'.encode('ascii'), 1)

`

@Gramps
Copy link
Collaborator

Gramps commented Jun 16, 2020

Huh, somewhat convenient it does that but not with Ctypes! That's really good to know and will help fix a few other things that don't quite work correctly. Good find!

@sudasana
Copy link
Contributor

This also occurs with GetStat - would it be possible to have both GetStat functions and the SetStat function always encode the name variable as ascii?

def SetStat(self, name: str, value: object) -> bool:
        """Set a statistic
        :param name: str
        :param value: float, int
        :return:
        """
        if isinstance(value, float):
            return self.steam.SetStatFloat(name.encode('ascii'), value)

        elif isinstance(value, int):
            return self.steam.SetStatInt(name.encode('ascii'), value)

        else:
            raise UnsupportedSteamStatValue("SetStat value can be only int or float")

@Gramps
Copy link
Collaborator

Gramps commented Aug 30, 2020

Definitely. If one is changed then it's partner should be changed too.

@Gramps Gramps self-assigned this Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Stuff related to general bugs callbacks Stuff related to Steam callbacks
Projects
None yet
Development

No branches or pull requests

3 participants