JSONToTable Not working 100%, Am I doing it wrong?
13 replies, posted
[B][U][I]Issue was sorta resolved. The reason it wasnt working right is because its a linux server. When its on a windows server it all runs fine.[/I][/U][/B]
Well I was updating RadBox for fun, And I changed places where GLON was, With JSON. So it all works great on a listen server. But once its on a dedicated server, When it loads. It creates all the ones that start with "point_" the rest end up in a null entity, Even though they exist. The dedicated server either cant find them, Or JSON isnt happy. Ending up as a error. Is this a problem with JSON or a problem with how its set up?
No other errors pop up besides this one.
EDIT: Forgot to add the error.
[code][ERROR] gamemodes/ras/gamemode/init.lua:215: Tried to use a NULL entity!
1. SetPos - [C]:-1
2. unknown - gamemodes/ras/gamemode/init.lua:215[/code]
Line 215 is marked with **
[lua]function GM:LoadAllEnts()
MsgN( "Loading radbox entity data..." )
local jsondry = util.JSONToTable( file.Read( "radbox/" .. string.lower( game.GetMap() ) .. ".txt", "DATA" ) )
if not jsondry then return end
for k,v in pairs( jsondry ) do
if v[1] then
if k == "prop_physics" then
for c,d in pairs( v ) do
local function spawnent()
local ent = ents.Create( k )
ent:SetPos( d[1] )
ent:SetModel( d[2] )
ent:SetAngles( d[3] )
ent:SetSkin( math.random( 0, 6 ) )
ent:Spawn()
ent.AdminPlaced = true
local phys = ent:GetPhysicsObject()
if IsValid( phys ) and not d[4] then
phys:EnableMotion( false )
end
end
timer.Simple( c * 0.1, spawnent )
end
else
for c,d in pairs( ents.FindByClass( k ) ) do
d:Remove()
end
for c,d in pairs( v ) do
if k != "point_radiation" && k != "info_lootspawn" then
local function spawnent()
local ent = ents.Create( k )
ent:SetPos( d )
ent:Spawn()
end
timer.Simple( c * 0.1, spawnent )
elseif k == "info_lootspawn" then
local function spawnent()
local ent = ents.Create( "info_lootspawn" )
** ent:SetPos( d ) **
ent:Spawn()
end
timer.Simple( c * 0.1, spawnent )
else
local ent = ents.Create( k )
ent:SetPos( d )
ent:Spawn()
end
end
end
end
end
end[/lua]
--Whoops, seems it was fixed an hour ago--
If it's not working right on a linux, it's because linux servers don't do the virtual folders thing right, from what I understand. Try installing all the files directly into the gmod/gmod folders and such (such as putting the gamemode folder into your gamemodes folder blahblahblah). From what I understand, the addons folder just doesn't work in the linux environment.
Well not exactly fixed. But I found out whats causing it, Linux doesn't appear to be very friendly to gmod.
You didn't even check if the entity exists, this is not related to JSONToTable.
It is infact json, I cut json out and just created a table in lua and it loads just fine.
No, the line you marked:
[lua]
local ent = ents.Create( "info_lootspawn" )
** ent:SetPos( d ) **
ent:Spawn()
[/lua]
Meaning ent is NULL, means you didn't check if the entity does exist, this is NOT a json issue, it is you not checking if the entity actually exists!
But if you were to read the code, JSON is loading and creating a table with those entity names in it. For some reason these json is not reading this entity names on linux, As it does on windows. With a table and json cut out, It works just fine.
[code]
local ent = ents.Create( k )
ent:SetPos( d )
ent:Spawn()
[/code]
same code at openaura kills the server (because executed in global init hook) when too many static props added (don't know what about clockwork)
Again, this has NOTHING to do with the actual json, there is no json involved in this error.
Gmod is unable to create the entity and thus returns NULL, the entity type is hardcoded and thus JSON [B]can't be the issue[/B].
I know what the error means, JSON IS creating this problem. Its not the entitys. They exist. JSON just is not loading the table correctly.
How about you print both tables and compare both windows and linux?
That's weird, the error states that your entity is null :/
Well, Look at the difference between both printed tables. For some reason its not reading it. I had a friend try it on his linux server. And it works correctly, I can only assume its the linux server that im using.
Sorry, you need to Log In to post a reply to this thread.