Dexter Posted February 7 Share Posted February 7 Hi, I'm trying to get lua examples for Map's Save and Reload functions working. If you try the example from https://www.ultraengine.com/learn/Map_Save?lang=lua , sol complains about args (with a StreamBuffer at least). It's not clear to me what to feed it for in-memory stuff. I assume it's outdated because it's trying to call this scene:Save(stream, "game.sav") But save and reload do not take a string whatsoever as a second arg in lua docs. I assume changing the examples to do something like this is the way? local buffer = CreateBuffer(1024) local stream = CreateBufferStream(buffer) -- Create a scene local scene = CreateMap() -- .... -- Save the starting scene to an in memory buffer scene:Save(stream) This appears to work, but it's unclear to me how to do the next two things: 1. seek to beginning of stream: I tried this `stream = CreateStreamBuffer(stream)`. an API to seek to beginning of oft-reused buffers for cute tricks would be nice though 2. Actually reload a map from memory? `Map:Reload(Stream)` complains about args as well when trying a stream arg, it appears only the unary string function exists. I understand I can work around it with disk like so, maybe the old API was shorthand for this. But I'd like to avoid all disk I/O for reasons scene:Save('foo.sav') -- Main loop while not window:Closed() and not window:KeyDown(KEY_ESCAPE) do -- Reload the starting scene when space key is pressed if window:KeyHit(KEY_SPACE) then scene:Reload('foo.sav') end world:Update() world:Render(framebuffer) end If something like "`scene:Reload(stream, LOAD_DEFAULT)`" worked again that would be the money. Appreciate any input Quote Link to comment Share on other sites More sharing options...
Josh Posted February 8 Share Posted February 8 I do not know why the example in the documentation is wrong. I fixed it, thank you for pointing that out: https://github.com/UltraEngine/Documentation/blob/master/Lua/Map_Save.md It will take a few hours to re-cache in the docs system, but the link there will take you straight to the source content. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Dexter Posted February 12 Author Share Posted February 12 Is there currently a way to do it in memory only? Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted February 12 Solution Share Posted February 12 Yeah, it should work if you use CreateBufferStream to create a stream. This command does not require a buffer as an argument, and it is better not to provide one. Then, before saving or loading call stream:Seek(0) to make sure the file position is at the beginning of the file. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.