Help with packp3d?

I’m creating a game and I’m compiling with packp3d. Everything compiles perfectly, but when I run the app, I get this error:

Traceback (most recent call last):
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\p3d\Ap
pRunner.py", line 638, in run
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\task\T
ask.py", line 502, in run
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\task\T
ask.py", line 460, in step
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\showba
se\Messenger.py", line 424, in __taskChainDispatch
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\showba
se\Messenger.py", line 482, in __dispatch
  File "C:\buildslave\release_rtdist_win32\build\panda3d\built_cmu\direct\p3d\Ap
pRunner.py", line 751, in __startIfReady
TypeError: main() takes no arguments (1 given)
:TaskManager: TaskManager.destroy()
:display: Closing wglGraphicsWindow
Failure on startup.

Any explanation on why the AppRunner isn’t functioning properly? I haven’t tweaked it at all. Please help!

Hmm, do you happen to have a function called main in your main.py file? If so, try renaming it.

Yes, thank you, that was indeed the problem and I fixed it. Although I have one more question. My game stores data in a folder for reading and writing in. Whenever I get to a saving point in the game, however, it is unable to open the file for writing. Is there any way to incorporate writing data to file within a compiled p3d app? I ran multify on the p3d file to view the files and folders, and my save data folder was there, but the game can’t seem to open a new file in it.


In case that was confusingly worded, this is what happens in the game: Upon startup, it checks if there is a file named “data” in a folder called “savedata”. If there is no file, the game proceeds as a new game. After the player is finished choosing everything they want, the game tries to open a new file named “data” to store all of the data in. This works during regular python execution, but does not work in the p3d file. Any potential solution for this is appreciated.

No, sorry, the .p3d file is read-only. You’ll have to find another location on disk to write the modified files (eg. AppData directory)

I’m fairly sure I’m using the same way to save data, would py2exe or any other compilers work AND save data?

The thing is that you’re trying to open an existing file for writing, whereas that existing file is stored compressed in the .p3d file. You have to write a new file on disk rather than trying to modify an existing packed file.

py2exe will have the same problem if you try to write a file that’s packed into the .exe. This is not a limitation of the tool. py2exe is fundamentally very similar to the packp3d+pdeploy combination.

So could we do if not os.path exists or something like that to make the new file or no?

So could I do something like this?

import getpass

with open('C:/Users/' + getpass.getuser() + '/AppData/Local/savedata/data.json', 'w') as savegame: 
    savegame.write(jsonpickle.encode(game_state))

(Where game_state is the variable containing the data.)

No, you shouldn’t. There is no guarantee that C:/Users exists, that the user is running Windows, or that any of the other directories in the path you specified exists.

Instead, use something like this, which would be far more portable:

# Find the location of the platform-specific app data directory
appdata = Filename.getUserAppdataDirectory()
fn = Filename(appdata, "YourGame/data.json")

# Create the directories leading up to this file
fn.makeDir()

with open(fn.toOsSpecific(), "w") as savegame:
    ...