Space Engineers

Space Engineers

Not enough ratings
Data Map from Block Name (Library)
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
362.096 KB
2 Jan, 2015 @ 12:53pm
1 Change Note ( view )

Subscribe to download
Data Map from Block Name (Library)

Description

Basic Data Map Via Name
Author: Extramrdo
Version: 1.0
Several functions to store data in the name field of a button.
What is a data map? Short of it, it's a list of pairs. Each pair is a key and a value, both Strings.
You search the map using the key, and get the value back, much like regular variables.
Why use this? Big reason: "User defined variables are not saved." You save the map, load it, and script breaks.
However, block names ARE saved, so why not save variables in there?
Additionally, you can use this Data Map as shared storage between 2+ Programming Blocks.
Beginner Outside Setup: Make a block whose name is "DATAMAP#;", no quotes.
It is recommended that this NOT be an antenna or beacon; I didn't test how broadcasting 600 characters to the entire world really affects anyone. It's not helpful at any rate. Author prefers button panels but any named block will do.

Usage: Call FindKeyBlock() first.
To add a key pair, UpdateKey( YourKey, YourValue );
DO NOT use AddKey() unless you know what you're doing. See AddKey()'s header for further discussion.
To get the value, just GetKey( YourKey );
Removal of a key, RemoveKey( YourKey );
... This is all in the function headers anyhow, and see Main() for an example usage.

=Implementing in your own script!=
Copy this header (Which is included in the script itself), and everything beneath it, into your own script and paste my stuff at the end.
Please include the header in your script if you choose to publish it to the Steam Workshop.
If you're worried about file length, go ahead and remove the function headers but please keep the first two lines of this header (BDMVN, Author), to properly attribute my tiny part in your grand device.
This was a fun "first project after graduating with a BS in Comp Sci."

For quick reference, the functions are
FindKeyBlock()
FindKeyBlock(String prefix)
RemoveKey(key)
AddKey(Key,Value) //Don't use, use UpdateKey
UpdateKey(Key,Value)
GetKey(Key)
ResetKeyBlock()
HasKey(Key)