vON doesn't serialize a table of weapon objects, throws error
3 replies, posted
I am trying to get player's weapons, put them in a table, serialize the table with vON and then save it to a text file.
I managed to save everything:HP, armor, angles and pos, a table of ammo, but a table of weapons fails to serialize.
Here is the weapon related code:
[code]function SavePlayerStatus( ply )
ply.status.weaponry = {}
for k, v in pairs(ply:GetWeapons()) do
if v then
table.insert(ply.status.weaponry, v)
end
end
for k, v in pairs(ply.status.weaponry) do
print(v)
end
local debugstuff = von.serialize(ply.status.weaponry)
...
end[/code]
The error is
[quote]
[ERROR] addons/persistentdata/lua/von.lua:149: attempt to call a nil value
1. s_anyVariable - addons/persistentdata/lua/von.lua:149
2. serialize - addons/.../von.lua:426
3. SavePlayerStatus - addons/.../sv_save.lua:26
[/quote]
The 26 line is [code]local debugstuff = von.serialize(ply.status.weaponry)[/code]
Please help smart guys, I just don't know.
Link to vON: [url]http://www.facepunch.com/showthread.php?t=1194008[/url]
I think you may be using an outdated copy of von. This one should work.
[url]http://puu.sh/3XFvk.lua[/url]
[QUOTE=Jarva;41772245]I think you may be using an outdated copy of von. This one should work.
[url]http://puu.sh/3XFvk.lua[/url][/QUOTE]
I just tried it.
That code
[code]
ply.status.weaponry = {}
for k, v in pairs(ply:GetWeapons()) do
if v then
table.insert(ply.status.weaponry, v)
end
end
for k, v in pairs(ply.status.weaponry) do
print(v)
end
local debugstuff = von.serialize(ply.status.weaponry)
[/code]
Gave that error:
[code]
Saving Euphe - university's player data
Weapon [41][weapon_crowbar]
Weapon [42][weapon_pistol]
Weapon [82][weapon_smg1]
Weapon [104][weapon_frag]
Weapon [105][weapon_physcannon]
Weapon [108][weapon_crossbow]
Weapon [109][weapon_shotgun]
Weapon [110][weapon_357]
Weapon [111][weapon_rpg]
Weapon [112][weapon_ar2]
Weapon [113][gmod_tool]
Weapon [114][gmod_camera]
Weapon [115][weapon_physgun]
[ERROR] addons/persistentdata/lua/von.lua:149: attempt to call a nil value
1. s_anyVariable - addons/persistentdata/lua/von.lua:149
2. serialize - addons/persistentdata/lua/von.lua:426
3. SavePlayerStatus - addons/persistentdata/lua/sv_save.lua:26
4. unknown - addons/persistentdata/lua/sv_save.lua:71
5. unknown - lua/includes/modules/concommand.lua:69
[/code]
Nothing changed
I'm not sure you would really want to save a weapon entity to the file, unless you have a specific idea in mind, I suggest you convert them to their class and save it as a table of strings.
Sorry, you need to Log In to post a reply to this thread.