Hi there Team,
I'm working to port the Level and Skill System from Oxide 1 to Oxide 2, but I stuck on the Group management.
How its possible to remove a Table Entry (key) and all its values?
Ex.:
tableremoveentry(LESData, Testers)Code:LESData.json = "GroupData": { "Testers": { "Leader": [ "PlayerX" ], "Members": [ "PlayerX" ] }
Then, all the group Testers would be remove with its info.
Removing a table entry
Discussion in 'Rust Development' started by TheRotAG, Dec 23, 2014.
-
Just set it to nil and it will magically disappear
Code:LESData.json.GroupData.Testers = nil
-
Oooww, will test that!
I was so focused in doing it using a function that I created this:
Code:function PLUGIN:tableRemoveKey(table, key) local element = table[key] table[key] = nil return element end
-
-
Tried it and it gave me an error in the console, checked the file LESData.json and the info was deleted as expected.
It's safe to use that simple form even with this error?
Code:[Oxide] 6:04 AM [Error] RotAG-LES: invalid arguments to method call at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unkn own>: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
-
-
That's weird... it only shows up if I simplify the method using your option. If I stick to the function tableRemoveKey that I've created, no errors are generated.
-
Dont use the function at all.
When you use LOCAL, the variable gets saved inside the cache, adding more and more local to the cache that Will never be used later on.
just do table[value]=nil
In your code, donc make à remove function that doesnt do anything Else then that.
Also à little tip that i found out.
It is impossible to do direcly:
GroupData={}
You need to delete all the tables inside the tables first
GroupData.Testers.Leaders = nil
GroupData.Testers.Members = nil
Then
GroupData.Testers=nil
Then
GroupData={}
You can look inside my r-Zones how i did it ...
It Hurt my Brain for days before i found out that -
:
Code:myTable = { ["Test1"] = { ["Leader"] = { "123456","mughisi" }, ["Members"] = { "321654", "isihgum" } }, ["Test2"] = { ["Leader"] = { "123456","mughisi" }, ["Members"] = { "321654", "isihgum" } } } print( "Table without modifications:" ) tprint( myTable ) print( " " ) print( "Table after setting Test1 to nil" ) myTable["Test1"] = nil tprint( myTable ) print( " " ) print( "Table after setting table to nil" ) myTable = nil print( tostring( myTable ) )
Code:12:04 PM [Info] Table without modifications: 12:04 PM [Info] Test1: ( table ) 12:04 PM [Info] Leader: ( table ) 12:04 PM [Info] 1: 123456 (string) 12:04 PM [Info] 2: mughisi (string) 12:04 PM [Info] Members: ( table ) 12:04 PM [Info] 1: 321654 (string) 12:04 PM [Info] 2: isihgum (string) 12:04 PM [Info] Test2: ( table ) 12:04 PM [Info] Leader: ( table ) 12:04 PM [Info] 1: 123456 (string) 12:04 PM [Info] 2: mughisi (string) 12:04 PM [Info] Members: ( table ) 12:04 PM [Info] 1: 321654 (string) 12:04 PM [Info] 2: isihgum (string) 12:04 PM [Info] 12:04 PM [Info] Table after setting Test1 to nil 12:04 PM [Info] Test2: ( table ) 12:04 PM [Info] Leader: ( table ) 12:04 PM [Info] 1: 123456 (string) 12:04 PM [Info] 2: mughisi (string) 12:04 PM [Info] Members: ( table ) 12:04 PM [Info] 1: 321654 (string) 12:04 PM [Info] 2: isihgum (string) 12:04 PM [Info] 12:04 PM [Info] Table after setting table to nil 12:04 PM [Info] nil
-
not if you want to save it in a file.
try it out you will see ...
took me 1 week to fix just this in r-Zones.
deletion worked ONCE then all add/remove NEVER got saved in the file.
it's a very strange bug, but you should try to use my r-zones, remove the part where i reset everything 1 by 1.
and try adding 3 zones, then removing all of them 1 by 1, you will see in your data file that ONLY the FIRST one removed will be rmeoved from the datafile, and all the others will stay (until you reload the plugin and remove again, same thing will happen, first will get removed and the other ones wont) -
. Appears that it does in fact not save, but it should to be honest so guess we'll need a fix for that issue
-
yeah ... well now that we know it it's fine ...
but it's just another example of why oxide 2 is harder to code then oxide 1.
(and another example why it would be awesome to have a wiki for oxide 2 to help new coders) -