How can I save my game every time before running the game engine? (BGE 2.78)

I work on a lot of BGE stuff in general, and I often use code. the problem with using code in the BGE is that it is instinctive to use the python while loop, and as you all know, once you run a while loop in the game you’ve just screwed yourself because it will softlock. So I was wondering how I could save it every single time before running the game as a new individual file to avoid this very obnoxious problem. I have lost so much work in the past because of this, and I apologize if I should’ve put it in blender instead.

1: gitgud
2: autosave
3: run standalone player so the new blenderplayer.exe crashes and not blender.

when you’re quickly developing something you don’t want to have to rely on the standalone player.

if you cant adapt, then suffer the consequences or find a different engine. but make no mistake, each engine have its own issues you need to work out.

instead of while loops, use controlled for loops that have a start and end usually.

I do, it is instinctive for any programmer to use while loops and they will indefinitely make that mistake.
And I am adapting by changing my setup to solve this problem.

i dont understand this “instinct” you speak of. coding isnt like muscle memory hotkeys. its hard to imagine anyone who couldnt learn not to type “while” after discovering game code works a bit different then normal scripts.

1 Like

this from blender 2.79 manual but i think it will work on 2.78

Easy peasy.

import bpy

bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)

Take these two lines, and run them through a startup script.

laughs in hex

2 Likes

I’m pretty sure there is a setting somewhere which lets you set how many previous versions you want to keep when saving.

So, if you set it to 4, you’d see the following in your directory after a while:

  • game.blend
  • game.blend1
  • game.blend2
  • game.blend3

Then, just CRTL+S before you run the game without worrying about losing previous versions.

Use “for” loops instead when you can. They are a LOT harder to accidentally run infinitely and they’re usually easier to read.

:roll_eyes: what get from this is that not everybody learns from there mistakes, and thus keep repeating them.

1 Like

@Liebranca Damn, that’s a pretty cool way to use that feature. I have never considered using the bpy module like that before, wicked smart!

@edderkop Hmmm… That seems to be a sort of anti-pattern of humanity in general. How does one unlearn this unintelligent behaviour?