Data store query

Discussion in 'Rust Development' started by Taffy, Oct 17, 2014.

  1. Making a bit of progress creating a tphome mod for oxide 2. Now I want to output the list of home locations to a file which will be written to and read.

    So I was wondering, whats the best practice for this to ensure smooth operation and follows some sort of standard?

    Should I write to the self.Config file each users home location(s) - not worked out how I will do this bit yet - or have a separate file containing the homes coordinates. If the separate file is the way to go, how do I go about creating it and reading/writing to it?

    Cheers
    Dave
     
  2. ah, that be why I am seeing datafilesystem errors then :) Thought it was just me.

    Shall plod on with the code with a view to adding that later then if and when I work out the correct syntax :p

    Thanks for the info
    Cheers
     
  3. The data file system should at least be functional, what kind of errors are you getting?

    Here is my test code for it:

    Code:
    function PLUGIN:cmdDatafileTest( arg )
        local datatable = datafile.GetDataTable( "test" )
        datatable.entries = datatable.entries or {}
        datatable.entries[1] = 123
        datatable.entries[2] = "hello"
        datatable.entries[3] = { 10, 20 }
        datafile.SaveDataTable( "test" )
    end
     
  4. Shit, mine didnt look anything like your example :p

    ok so I now have the following in the init function

    Code:
    --load or create home locations save file
        local datatable = datafile.GetDataTable ("homesave")
        datatable.entries = datatable.entries or {}
        datafile.SaveDataTable("homesave")
    Appears to have created the data\homesave file in json format but generates the following error;

    Code:
    [Oxide] 8:15 PM [Error] Failed to initialise plugin tphome (A .NET exception occ
    ured in user-code)
    [Oxide] 8:15 PM [Debug]   at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x
    00000] in <filename unknown>:0
      at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System
    .Type[] returnTypes) [0x00000] in <filename unknown>:0
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (ob
    ject,object[],System.Exception&)
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invoke
    Attr, System.Reflection.Binder binder, System.Object[] parameters, System.Global
    ization.CultureInfo culture) [0x00000] in <filename unknown>:0
    If I remark out the datafile.SaveDataTable line the error goes away
     
  5. Just don't save at that point. Create a different method to save when you modify the data, saving when loading the datafile is a bit obsolete when you're not modifying it and the error is caused when you save the datatable without any values.
     
  6. Thanks mate, makes perfect sense. Think I have been looking at too much code today. Perhaps have too many mods on the go at the same time lol