• 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?
The code: [lua]PrintTable(util.JSONToTable( file.Read( "radbox/" .. string.lower( game.GetMap() ) .. ".txt", "DATA" ) ))[/lua] Windows: [code]] rcon lua_openscript printjsontable.lua autokick is disabled for Odic Force Running script printjsontable.lua... info_player_army: 1 = -2346.090820 5996.107910 -570.968811 2 = -2414.977051 5952.080078 -570.968811 3 = -2426.180176 6028.065430 -570.968811 4 = -2511.503418 6022.393066 -570.968811 5 = -2510.533447 5947.597168 -570.968811 6 = -2597.396240 5994.706543 -570.968811 7 = -2602.291016 5922.521973 -570.968811 8 = -2377.438965 5761.932129 -570.968811 9 = -2467.262207 5764.070313 -570.968811 10 = -2559.233887 5764.036133 -570.968811 11 = -2652.519043 5763.355469 -570.968811 12 = -2660.152344 5816.475586 -570.968811 13 = -2667.993652 5890.736328 -570.968811 14 = -2734.708496 5908.572266 -570.968811 15 = -2920.817627 5767.289551 -570.968811 16 = -2720.909180 5774.377930 -570.968811 17 = -2784.486328 5747.221680 -570.968811 18 = -2768.175537 5214.663086 -570.968811 19 = -3592.643311 5190.975098 -570.968811 20 = -3588.065186 5258.208984 -570.968811 21 = -3537.722412 5258.322266 -570.968811 22 = -3467.469482 5182.112305 -570.968811 23 = -3478.604736 5259.023438 -570.968811 24 = -3380.932861 5147.375488 -570.968811 25 = -3312.308594 5110.135742 -570.968811 26 = -3144.496338 5049.537598 -570.968811 27 = -3233.227783 5049.116211 -570.968811 28 = -3339.879150 4981.989258 -570.968811 29 = -3476.083008 5051.767578 -570.968811 npc_trader_exodus: 1 = 3390.968750 2666.215088 -1023.968811 npc_trader_bandoliers: 1 = 1826.695435 -9447.910156 8.031300 info_npcspawn: 1 = -7366.520508 5175.842285 5.031300 2 = -10249.911133 -11802.314453 121.312698 3 = -3735.468750 -3500.060059 5.031300 4 = -8292.827148 -2904.255371 5.000000 5 = -8921.628906 2191.490723 62.314602 6 = 5541.176270 -4742.493164 5.031300 7 = 4584.998047 -44.735802 5.031300 8 = 2312.566650 8849.462891 5.031300 9 = -1242.342163 3441.434082 5.031300 10 = -6849.534180 9488.494141 5.031300 11 = -4583.116699 4094.863525 146.378906 12 = -6705.760742 4381.557129 13.031100 13 = -433.428406 6926.002930 8.999900 14 = -1791.998657 7870.479004 5.031300 15 = -1062.157227 7358.977051 21.031300 16 = -1125.072754 7022.916504 21.031300 17 = 3541.492188 5171.639648 5.031300 18 = 5345.551758 8478.771484 5.031300 19 = 7986.548828 8896.277344 5.031300 20 = 8741.840820 12791.900391 47.116199 21 = 9343.156250 6930.866211 5.000000 22 = 7467.263184 6240.005859 5.031300 23 = 6971.967773 5603.380371 5.031200 24 = 7960.639648 5832.418945 5.031300 25 = 7862.895996 6221.572754 5.031300 26 = 6973.520020 6029.621094 5.031300 27 = 7504.435547 5815.782227 5.031300 28 = 7531.455566 6411.447754 5.031200 29 = 7186.255371 4153.501953 -70.607101 30 = 7517.751465 4558.982910 5.031300 31 = 7021.003418 4291.757324 -58.682400 32 = 7791.323242 4605.335938 5.031300 33 = 7897.167969 4132.845215 -214.856796 34 = 7875.697754 3862.125244 -250.968796 35 = 8121.974609 3684.493896 -250.968796 36 = 8048.260254 3067.224365 -250.968796 37 = 7768.438477 3087.364258 -250.968796 38 = 8111.356934 2707.696045 -250.968796 39 = 8070.586426 2918.863525 -570.968811 40 = 8010.207031 3547.962646 -570.968811 41 = 8052.789551 3252.851807 -565.335876 42 = 7481.860840 2987.227295 -570.968811 43 = 7200.130859 2635.476807 -570.968811 44 = 6932.920410 2709.904297 -570.968811 45 = 7083.880371 2991.302979 -570.968811 46 = 6965.798828 2885.630127 -570.968811 47 = 7668.849121 2805.150635 -892.289490 48 = 8116.928711 2702.202637 -890.968811 49 = 8010.908691 3024.278320 -890.968811 50 = 7782.024414 3111.515869 -890.968811 51 = 7995.440430 3460.491699 -890.968811 52 = 7824.818359 3457.900146 -890.968811 53 = 8089.925781 3696.344727 -890.968811 54 = 8021.962402 3898.166504 -890.968811 55 = 8011.116211 4073.940674 -890.968811 56 = 7829.364746 3907.898438 -890.968811 57 = 7625.172852 4083.447998 -890.968811 58 = 7846.170410 4042.800049 -1530.968750 59 = 7950.216797 3452.073486 -1530.968750 60 = 7685.547852 2347.978027 -1535.092163 61 = 8168.999023 2378.311035 -1556.847534 62 = 7878.093262 2911.388428 -1535.972656 63 = 8015.013184 2731.202148 -1534.013428 64 = 7920.848145 2569.737305 -1536.574341 65 = 7825.970703 2372.188477 -1531.000000 66 = 7999.285645 2567.177979 -1531.000000 prop_physics: 1: 1 = -736.664124 6525.484375 61.050400 2 = models/props_vehicles/truck001a.mdl 3 = 0.324 0.956 1.502 4 = true 2: 1 = -719.590515 6524.925781 60.822498 2 = models/props_junk/wood_crate001a.mdl 3 = -1.912 5.416 1.365 4 = true 3: 1 = -764.261414 6521.459473 59.333302 2 = models/props_junk/wood_crate001a.mdl 3 = -2.172 18.882 0.845 4 = true 4: 1 = -1156.551636 6769.187988 16.387899 2 = models/props_c17/oildrum001.mdl 3 = -0.045 -28.559 -0.043 4 = true info_player_loner: 1 = -10047.029297 -11353.643555 4.999800 2 = -10053.834961 10846.862305 37.637901 3 = -2454.230957 -3800.446777 5.031100 4 = 9827.832031 -11062.173828 67.277603 5 = 8396.015625 -84.124001 5.000000 6 = 5865.257324 4725.606445 878.268372 7 = 6719.958984 12106.860352 93.034103 info_lootspawn: 1 = 6814.894043 2446.103027 -570.968811 2 = 7229.213867 2486.135742 -570.968811 3 = 6961.425293 2923.350830 -570.968811 4 = 7787.802734 2292.318359 -1531.000000 5 = 8165.143555 2322.434326 -1531.148438 6 = 7948.784180 2486.601074 -1531.000000 7 = 7658.122070 2711.744629 -1510.464233 8 = 8213.349609 2821.068848 -1531.627930 9 = 5330.599121 6625.642578 79.572601 10 = 2291.953125 2276.400391 -345.325012 11 = 1893.764160 2137.087158 -378.968811 12 = 2308.247559 2875.494873 -698.968811 13 = 3650.893799 2904.162109 -698.968811 14 = 2314.318115 2925.549561 -1018.968811 15 = 2044.910767 2515.907715 -1018.968811 16 = 1928.411621 2902.334717 -1018.968811 17 = 3018.252197 2991.184082 -698.968811 18 = 4677.757813 -9072.526367 5.031300 19 = 4226.038086 -9273.041016 13.031300 20 = 4361.286621 -9555.446289 -138.968796 21 = 3468.481934 -9690.385742 5.031300 22 = 2481.245117 -8131.961426 13.031300 23 = 2818.706055 -8104.140625 13.031300 24 = 2711.379150 -8763.157227 13.031300 25 = 2576.603271 -9336.538086 13.031300 26 = 1513.046143 -8061.601563 21.031300 27 = 1881.390503 -9274.231445 -266.968811 28 = -4139.407227 11486.592773 5.000000 29 = -3444.115479 45.708000 5.031300 30 = 4294.557617 -2292.750977 5.031300 31 = 2865.142090 3979.334473 3077.031250 32 = 4800.167969 -1350.935791 -9.538000 33 = 5691.129395 -1229.235229 -28.486601 34 = 5369.922363 -714.455017 -31.637400 35 = 5411.665527 -1548.090454 -46.828999 36 = 5018.316406 -1343.638550 -87.457603 37 = 5549.927246 -912.717712 -54.382099 38 = 11069.764648 2933.361816 11.971400 39 = 10347.100586 -4698.466309 49.044399 40 = 2147.841797 -4058.118652 5.031300 41 = 6918.700684 -8991.714844 5.031400 42 = -4307.183594 -11485.826172 21.514099 43 = -9323.015625 -7154.991699 5.000000 44 = -8790.910156 720.600830 19.497299 45 = -3155.569336 1300.433838 5.031300 46 = -332.468506 -5979.528320 5.031100 47 = -3266.985352 -10598.244141 26.990801 48 = -247.523697 -8425.531250 6.130000 49 = -3114.799072 -5401.086914 5.031300 info_player_bandoliers: 1 = 1886.456421 -9527.131836 13.031300 2 = 1881.738281 -9475.210938 13.031300 3 = 1825.396362 -9532.821289 13.031300 4 = 1755.133789 -9530.329102 13.031300 5 = 1696.869995 -9524.588867 13.031300 6 = 1672.231079 -9218.349609 -138.968796 7 = 1661.324951 -9299.718750 -138.968796 8 = 1664.401489 -9386.854492 -138.968796 9 = 1814.874756 -9475.224609 -138.968796 10 = 1812.290161 -9386.782227 -138.968796 11 = 1799.862793 -9321.347656 -138.968796 12 = 1735.841187 -9310.624023 -138.968796 13 = 1733.277222 -9383.421875 -138.968796 14 = 1725.706177 -94
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.