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