#✅ SOLVED *Buffer Async - What am I misunderstanding?*

1 messages · Page 1 of 1 (latest)

main dew
#

I am trying to get some basic code working to utilize the buffer_async* functions but I'm having no luck. My debug window never ends up showing any text. Is there something I'm missing / not understanding?

Create

saveBuffer = buffer_create(1, buffer_grow, 1);
loadBuffer = buffer_create(1, buffer_grow, 1);

buffer_write(saveBuffer, buffer_string, "Hello world");
size = buffer_get_size(saveBuffer);
asyncSave = buffer_save_async(saveBuffer, "test.dat", 1, size);
asyncLoad = undefined;

Async Save/Load

switch(async_load[? "id"]){
case asyncSave :
    buffer_delete(saveBuffer);
    show_debug_message("Buffer Saved");
    asyncLoad = buffer_load_async(loadBuffer, "default/test.dat", 1, size);
break;
case asyncLoad :
    var text = buffer_read(loadBuffer, buffer_string);
    show_debug_message("Loaded: "+string(text));
    buffer_delete(loadBuffer);
    file_delete("default/test.dat");
    game_end();
break;
}
main dew
#

So for some reason the saveBuffer size for "Hello world" returns 16, but the loadBuffer size when it comes back in is 12.

Not sure how this helps as it doesn't seem to make much of a difference but still

#

Ooh. Using buffer_seek_start gives me "ello world". So I need to offset by 4 bytes I guess?

wind ivy
#

size = buffer_tell(saveBuffer);

#

and save from 0

#

and load from 0

#

offsets

main dew
#

Hmm, that didnt work. I was able to get it working by just adding an empty space before my string data

buffer_write(saveBuffer, buffer_string, " " + "Hello World")
And just setting the size to 10000000.

This even works with JSON stringify/parse

wind ivy
#
loadBuffer = buffer_create(1, buffer_grow, 1);

buffer_write(saveBuffer, buffer_string, "Hello world");
size = buffer_tell(saveBuffer);
asyncSave = buffer_save_async(saveBuffer, "test.dat", 0, size);
asyncLoad = undefined;
case asyncSave :
    buffer_delete(saveBuffer);
    show_debug_message("Buffer Saved");
    asyncLoad = buffer_load_async(loadBuffer, "test.dat", 0, size);
break;
case asyncLoad :
    var text = buffer_read(loadBuffer, buffer_string);
    show_debug_message("Loaded: "+string(text));
    buffer_delete(loadBuffer);
    file_delete("test.dat");
    game_end();
break;
}```
#
LOAD: numFiles 1, numBundleFiles 0
Loaded: Hello world
###game_end###0```
main dew
#

Weird, I got an error. I will try again, very possible I mistyped something. Haha

#

Thanks!!

main dew
wind ivy
#

I generally buffer_seek_start when rewriting the buffer and then use buffer_tell to use it

#

though it's mostly for sending packets in my case