Data Persistence
The scripting system has a simple way to persist data between different scripts. The functionality is in the Proxy.Settings class.
You create a custom class with simple properties and pass it to the Proxy.Settings.SetSavedData method. This will serialise your object to a Json string and save it to the database.
You can then retrieve it with the Proxy.Settings.GetSavedData method which will retrieve the Json data and deserialise it back to your object type.
Example:
<RagebotScriptEntry>
Public Sub Run()
Dim ID As String = "MySettings"
' Check if the object already exists
Dim obj = Proxy.Settings.GetSavedData(Of MyData)(id)
If obj Is Nothing Then
Output("Creating Data")
' If data does not exist, create it and set the default values
obj = New MyData() With {.Name = "YourName", .DateOfBirth = #5/22/2000# }
Else
Output("Settings were previously saved")
End If
' Save the object to the database
Proxy.Settings.SetSavedData(Of MyData)(ID, obj)
' Now retrieve the data and display it
Dim RetrievedData = Proxy.Settings.GetSavedData(Of MyData)(ID)
Output($"{RetrievedData.Name} - {RetrievedData.DateOfBirth}")
' Now delete the settings
Proxy.Settings.DeleteSavedData(Of MyData)(ID)
End Sub
Private Class MyData
Public Property Name As String
Public Property DateOfBirth As Date
End Class