Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 24 Sep 2012 08:04 PM |
| Does :SaveInstance() work for saving tables? For instance, I'm creating an OOP powered RPG and I would like players to be able to save their "instance," which is a table with various numbers, functions, and metatables stored in it (how you OOP in RBX.Lua). How do I attach this to a player with DP? |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 24 Sep 2012 08:06 PM |
| Please explain what you are trying to do. It is not possible to serialize a function in RBX.Lua. What I would do is serialize the table as a string "{ someIndex = \"someValue\" }"and use Player:SaveString and Player:LoadString |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 24 Sep 2012 08:20 PM |
Have you ever made a custom object in RBX.Lua?
self = {}
self.name = "Derp"
self.printName = function()
print(self.name)
end
self.epicnessLevel = 1337
I want to be able to save "self." |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 24 Sep 2012 08:25 PM |
| Then write a function that serializes a table. But you will have to ignore functions, as they cannot be serialized. |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 24 Sep 2012 08:34 PM |
| Is there a way I can transform the table into a userdata and use SaveInstance()? |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2012 08:46 PM |
i have no idea what im talking about, but i know that newproxy creates a userdata and you can give it a metatable
cooleo = newproxy(true) setmetatable(newproxy, {"cool", "data"})
??? |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 24 Sep 2012 09:16 PM |
"Is there a way I can transform the table into a userdata and use SaveInstance()?"
I don't understand why you would want to do that.
When you call SaveInstance it's just really saving a string. It just uses the same serialization code that it does to read / write .rbx files. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 24 Sep 2012 09:41 PM |
| Player:SaveInstance only works on instances (i.e. Parts, IntValues, etc) |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2012 10:10 PM |
| Use JSON. RbxUtility library. |
|
|
| Report Abuse |
|
|
coolbob44
|
  |
| Joined: 26 Nov 2009 |
| Total Posts: 1649 |
|
| |
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Sep 2012 11:55 PM |
| JSON hardly saves anything... |
|
|
| Report Abuse |
|
|
|
| 25 Sep 2012 01:57 AM |
1. Serialise table into a string, or multiple strings 2. Use SaveString to save the table 3. Deserialise the table on LoadString 4. ??? 5. Profit |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 25 Sep 2012 02:38 PM |
Table = {1,2,3,4} String = "{"..table.concat(Table,",").."}"
Pyr:SaveString("key",String)
--
String = Pyr:LoadString("key")
Table = loadstring("return "..String)()
TADA!
but i would really want to save tables *properly*. It'd be very useful and save time. It's annoying loading every single thing seperately on like 50 lines
|
|
|
| Report Abuse |
|
|
|
| 25 Sep 2012 04:52 PM |
| Keep the data separate from the methods that handle it. |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
| |
|
Parthax
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 6941 |
|
|
| 25 Sep 2012 09:26 PM |
Save all of it as a string then use loadstring after on it? I'm pretty sure you can still use loadstring but not bytecode with it. Just a guess :/
or
You could convert all the characters into a number then for each number save it as a unique number, then just decode it afterwards... I really don't know. |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 26 Sep 2012 07:07 AM |
| player.saveinstance.new(table) = {lol hi] |
|
|
| Report Abuse |
|
|