Hi. I've been working on my rp-script, and i've made a function so i can adjust the price for a door, and make it unownable. It works fine, but when i've added 1/4 of all the doors in Rp_downtown_v2(i use this map for testing) and load the map, Garrysmod comes up with this error:
[code]Timer Error: includes/modules/glon.lua:241: Infinite Loop Detected![/code].
The settings are stored in a glon-encoded table inside of a textfile. When the servers starts, i load that table.
Here's the function used for writing to the table:
[lua]
local function WriteDoorSettings(index, price, public) // Index = ent:EntIndex() . price is the price of the door. Public is wether people are able to buy the door(
local currentMap = game.GetMap()
if(file.Exists("bennoRP/mapSettings/" .. currentMap .. ".txt")) then
local DoorTable = glon.decode(file.Read("bennoRP/mapSettings/" .. currentMap .. ".txt")) //Choose the .txt for the current map
for k, v in pairs(DoorTable) do
if(v.index == index) then //Is the door we're adding already in the file?
v.price = price //Then just update the table
v.public = public
file.Write("bennoRP/mapSettings/" .. currentMap .. ".txt", glon.encode(DoorTable)) //Encode it with glon, and write it to the file again.
return
end
end
local temp = {} //The file exists, but this door hasn't added to it before.
temp[1] = {} //Let's create a table with all the data
temp[1].price = price
temp[1].public = public
temp[1].index = index
table.Add(DoorTable, temp) //Add the temp-table to the table we read from the file
file.Write("bennoRP/mapSettings/" .. currentMap .. ".txt", glon.encode(DoorTable)) //Encode it with glon, and write it to the file again.
else
local temp = {} //The hasn't been created yet. Let's create a table, and write it to the file
temp[1] = {}
temp[1].price = price
temp[1].public = public
temp[1].index = index
file.Write("bennoRP/mapSettings/" .. currentMap .. ".txt", glon.encode(temp)) //Encode it with glon, and write it to the file again.
end
end
[/lua]
... and here's the part where i read the table:
[lua]
//Load the settings-file for the map
local function UpdateDoors()
local currentMap = game.GetMap()
if(file.Exists("bennoRP/mapSettings/" .. currentMap .. ".txt")) then
local DoorTable = glon.decode(file.Read("bennoRP/mapSettings/" .. currentMap .. ".txt"))
for k, v in pairs(DoorTable) do
local Price = v.price
local Public = v.public
local Key = v.index
local ent = Entity(Key) //Find the entity, with the given keyindex
if(ent:IsValid() and ent:IsDoor()) then
if(Public) then
ent:MakePublicDoor()
end
ent:SetPriceDoor(Price)
end
end
end
log.Write("serverStarts", "Door settings loaded")
end
timer.Simple(1, UpdateDoors) //We need to wait abit or the doors, won't be valid.
[/lua]
What can i do to make Garrysmod finish the loop, and not display that error?
Read the page on glon:[url]http://wiki.garrysmod.com/?title=Glon[/url]
It tells you exactly how to fix this.
Thanks :-) . But i can't seems to figure out, how i use this with the glon.decode-function. How? :S
[editline]02:42AM[/editline] Oh thanks :D
I tried to include this in my code, but it doesn't work. This is what i did:
[lua]
local h_a, h_b, h_c = debug.gethook()
debug.sethook()
local DoorTable = glon.decode(file.Read("bennoRP/mapSettings/" .. currentMap .. ".txt"))
debug.sethook(h_a, h_b, h_c)
[/lua]
I get this error:
[code]
Timer Error: BennoRP/gamemode/init.lua:66: bad argument #1 to 'sethook' (function expected, got string)
[/code]
How do i use the debug.sethook() function?
bump. I still have this problem :S
Sorry, you need to Log In to post a reply to this thread.