1

I want to open a file which is packed into the Blend-file with the open() function while the game is running.

Is it possible? And can I write files into it? Like open("Test.blend/Text.txt", "w") or something?.

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Frostie
  • 31
  • 3

2 Answers2

1

If you run the game by pressing P in Blender, you can simply use the bpy module and access Blender's data while the game is running.

If you don't want to depend on Blender, you're limited to the LibLoad function. However, this doesn't support text datablocks. Writing to blend files is also not possible in that case. IMO it'll be much easier to read and write directly to files on the filesystem, rather than packing them inside blend files.

dr. Sybren
  • 7,139
  • 1
  • 23
  • 52
  • Sure but it also has to work with the standalone player. And generally its a bad idea to use bpy within the game engine – Frostie Feb 16 '18 at 20:51
  • That's rather situation dependent. I chose the BGE for my project because it allows me to use the bpy module. If this was a requirement, you could have mentioned it in the question. – dr. Sybren Feb 16 '18 at 22:18
  • But its generally no good idea – Frostie Feb 16 '18 at 22:44
  • 1
    If with "generally" you mean "if you want your game to run in the standalone player" you're correct, but I would hardly call that "generally". The BGE is also used for simulations, where recording the result of the physics engine and/or simulation data to Blender's FCurves is very powerful. Also I'm a former BGE developer, I kind of know what I'm talking about ;-) – dr. Sybren Feb 17 '18 at 13:34
  • Yes you're right. :) But in most cases bpy isn't used – Frostie Feb 17 '18 at 13:35
  • 1
    Please mark this answer as 'Accepted', or let me know in which way it's not good enough. – dr. Sybren Mar 04 '18 at 21:38
  • I'm still not able to open internal files in Blender Game Engine – Frostie Mar 05 '18 at 16:42
  • 1
    What you want is not possible, as I point out in my answer. – dr. Sybren Mar 05 '18 at 16:47
1

Bpy module and functions do not work in standalone player mode. suggest using write()or open() methods.

user98383
  • 11
  • 1