Your going to need to refactor you code a bit.

If you want saved state, you should store that in a file that isn't part of
the source code. And it should get saved outside of the application.

You can save the data in pretty much any format -- even python code, but
I'd recommend a "standard" text format, like JSON.

So your app would:

on start up, look for the "state" file.
if it it exists, it would load the state from there.
if it doesn't exist, it will create one from defaults you have in the code.
- when the state changes, or on app exit, or ??? the state file is updated.

This is how state (and preferences, etc) are usually handled.

There are standard places on each OS to put things like this -- the
platformdirs module provides a pretty good set.

HTH,

-CHB



On Fri, Nov 21, 2025 at 9:49 AM David Chavez <[email protected]>
wrote:

> Sorry, here is a portion of the script which loads a saved state when game
> over is triggered. The code in the first post is for when the exe saves but
> that portion works fine as intended. This part is where the trouble starts.
>
> # Check whether the game is over or not.
> if lives_count <= 0:
> lives_count = 0
> enemy_count = 0
> game_over = True
> level = 66
> if time_count != str("OUT"):
> gameMusic()
> bg_img = black_bg
> draw_text('GAME OVER', font_s_game_over, white, (screen_width // 2) - 200,
> (screen_height // 2) -100)
> player.rect.x = (screen_width // 2) - 25
> player.rect.y = (screen_height // 2) + 125
> player.image = dead_ball_img
> exit_level_group.empty()
> bricks_group.empty()
> brickschange_group.empty()
> breakbricks_group.empty()
> barbwire_group.empty()
> cash_group.empty()
> info_ball_group.empty()
> spike_goon_group.empty()
> spike_boss_group.empty()
> soccer_goon_group.empty()
> soccer_boss_group.empty()
> tnt_group.empty()
> boobytrap_group.empty()
> hooks_goon_group.empty()
> hooks_boss_group.empty()
> shadow_goon_group.empty()
> shadow_boss_group.empty()
> foot_goon_group.empty()
> foot_boss_group.empty()
> if rock_inuse:
> level = 64
> time_count = int(555)
> if card_inuse:
> level = 65
> time_count = int(777)
> if cigs_inuse:
> level = 67
> time_count = int(666)
> draw_text('Need a clue? Click the pack...', font_s, blue, 360, 670)
> if gear_inuse:
> level = 68
> time_count = int(888)
> if continue_button.draw():
> game_over = False
> if check_point == -1:
> level = 0
> lives_count = 2
> cash_count = 0
> score_count = 0
> elif not check_point == -1:
> importlib.reload(savestate)
> level = savestate.check_point + 1
> score_count = savestate.score_count
> gameMusic()
>
> It seems to import the save state (savestate) from the frozen exe instead
> of the update as I have stated previously.
>
> On Friday, November 21, 2025 at 9:26:05 AM UTC-8 David Chavez wrote:
>
>> Hello,
>>
>> I am having an issue with pyinstaller where it would create the
>> executable file just fine, however it would not load saved states. For
>> example, after a checkpoint is made, it saves to a file which file is then
>> used to load variables if/when the player gets game over or closes the
>> game. Normally, when testing in development mode opening the program via
>> terminal, this functionality works fine. However, when creating the
>> executable file, since it keeps things in a frozen state, it does not reach
>> the updated save file(s).
>>
>> Here's a piece of my code which is used to load saved states which works
>> fine when open via command line/terminal:
>>
>> if pygame.sprite.spritecollide(player, exit_level_group, False):
>> if not level == 99:
>> score_count += 100
>> if level == 99:
>> with open('savestate.py', 'w') as file:
>> file.write('check_point = ' + str(check_point) + '\
>> \nlives_count = ' + str(lives_count) + '\
>> \ncash_count = ' + str(cash_count) + '\
>> \nscore_count = ' + str(score_count) + '\
>> \nrock_sold = ' + str(rock_sold) + '\
>> \ncard_sold = ' + str(card_sold) + '\
>> \ncigs_sold = ' + str(cigs_sold) + '\
>> \ngear_sold = ' + str(gear_sold) + '\
>> \ngame1_won = ' + str(game1_won) + '\
>> \ngame2_won = ' + str(game2_won) + '\
>> \ngame3_won = ' + str(game3_won) + '\
>> \ngame4_won = ' + str(game4_won) + '\
>> \ndoorlevel_46 = ' + str(doorlevel_46) + '\
>> \ndoorlevel_47 = ' + str(doorlevel_47) + '\
>> \ndoorlevel_48 = ' + str(doorlevel_48) + '\
>> \ndoorlevel_49 = ' + str(doorlevel_49) + '\
>> \ndoorlevel_52 = ' + str(doorlevel_52) + '\
>> \ndoorlevel_53 = ' + str(doorlevel_53) + '\
>> \ndoorlevel_54 = ' + str(doorlevel_54) + '\
>> \ndoorlevel_55 = ' + str(doorlevel_55))
>>
>> Please let me know how I may resolve this issue. I couldn't find anything
>> in documentation which would have addressed my issue and worked.
>>
>> Best regards,
>>
>> David Chavez.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "PyInstaller" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/pyinstaller/c304f068-6dec-4b35-8830-bc887cd059bfn%40googlegroups.com
> <https://groups.google.com/d/msgid/pyinstaller/c304f068-6dec-4b35-8830-bc887cd059bfn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/pyinstaller/CALGmxEJs3QNimcGUSe%3D6_x54Y0RTeGw5msH_hvvcQ0VMtserQg%40mail.gmail.com.

Reply via email to