gms_bdb_open

Usage: gms_bdb_open ( bdb_id, exclusive_lock, callback )

Description

Opens the binary data block with ID bdb_id. When exclusive_lock is enabled, other clients are prevented from reading and writing while this client has the block opened.

Callback is the script that will be called when the binary data block has been opened. The first argument of the script will be the handle to the opened block.

Replies (9)

Last message on 30 Nov 2019

AutoPlanetServer2019 on 27 Nov 2019, 13:45:21
When i run a callback script, it runs correctly. Now after a while i wanna open another bdb, it calls the wrong callback script? I did make sure to close the bdbs after reading.
Size43 (Administrator) on 30 Nov 2019, 17:24:45
Are you changing callback scripts at all? You should set one script at the beginning and then handle different cases in the script itself.
Aaron13ps on 21 Jun 2016, 16:12:00
This stuff is vary confusing. Any chance you can explain further?

My goal is to transfer a lot of variables (4 decimals) and strings (OR, alternatively, an ini / txt file).

The binary data blocks seem unlike ini's.

If you can solve this question, it will help me vary much: If I have 2 variables i want to send, a string ("Hello") and a variable (1234.1234), to another player for them to pull data from, how would I go about doing that with this system?
Size43 (Administrator) on 22 Jun 2016, 14:46:49
Binary data blocks are quite different from INIs indeed. Whereas INIs use a section-key-value map to store data, binary data blocks just store, well, literally binary blocks of data. BDBs just store bytes, and don't provide a nice abstraction like a key-value map, which means you can virtually do anything you want with them. They work similarly to buffers in GM:Studio.

To write data to a BDB, you'd open the block, seek to a position in the block, write the data you'd want to write, and then close the block again. Since BDBs operate on byte-level, you can use integers of specific sizes (1, 2 or 4 bytes), doubles (the default type in GM, 4 or 8 bytes) or strings (variable number of bytes).

Alternatively, you could just directly copy any file into the BDB. (using the file_bin_ functions).
Aaron13ps on 25 Jun 2016, 18:13:55
Ok, so I am trying to copy a INI file into the BDB. I believe I have to create a bin file before transfering it. Once i have the bin file, how do I transfer it as a BDB?

if it simply: gms_bdb_write(argument0,bdb_string,file_bin_open("TempBin\MAP_BLOCKSAVETEST.bin",0)
and this to open: gms_bdb_read(argument0,bdb_string)
??
Size43 (Administrator) on 25 Jun 2016, 22:02:56
You don't have to write it to a binary file. You can read it in as a string, and then use gms_bdb_write(argument0, bdb_string, string_to_store) to store it. After that, you can use gms_bdb_read(argument0, bdb_string) to read it back in.
Aaron13ps on 25 Jun 2016, 22:58:42
One last question: How do I transfer the entire INI to a string?
Aaron13ps on 28 Jun 2016, 01:53:10
I think I have got it.
Just open the file and copy each line into a longer string, separating lines with some kind of indicator.
Size43 (Administrator) on 3 Jul 2016, 22:12:44
Yep, that would be the way to do it.