Swimer Posted February 18, 2022 Posted February 18, 2022 In the method below I don't use my functions but still "Stack overflow" Error on 3 line function updateValue(player, key, value) if not (player == nil) then local p = getPlayerSerial(player) if players[p] == nil then players[p] = {} end players[p][key] = value end end
Cronoss Posted February 18, 2022 Posted February 18, 2022 I also had this problem but it was because of the name of my function... but not always it's because of that, in this "error", the function it's calling itself without finishing the initial execution, so the problem could be in another part of the code. You should post the rest of it, so people of the community can help you easily, sometimes the console sends me the line where "the error is" and I find the problem 2 lines above, so...
_SAXI_ Posted February 18, 2022 Posted February 18, 2022 (edited) The problem may be that you are using the player serial as the table index. Try this: local serials = {} function getSerialIndex(str) local index; if(str)then for i,serial in pairs(serials)do if(str == serial)then index = i; end end if not(index)then table.insert(serials,str); end return #serials; end return index; end function updateValue(player, key, value) if not (player == nil) then local p = getSerialIndex(getPlayerSerial(player)) if players[p] == nil then players[p] = {} end players[p][key] = value end end This would work as long as the script is not stopped... If you use this option, I recommend you complement it with a database Edited February 18, 2022 by _SAXI_ 1
Swimer Posted February 18, 2022 Author Posted February 18, 2022 1 hour ago, Cronoss said: I also had this problem but it was because of the name of my function... but not always it's because of that, in this "error", the function it's calling itself without finishing the initial execution, so the problem could be in another part of the code. You should post the rest of it, so people of the community can help you easily, sometimes the console sends me the line where "the error is" and I find the problem 2 lines above, so... Sure players = { } function getPlayerData(player) if players[getPlayerSerial(player)] then return players[getPlayerSerial(player)] end return nil end function getPlayerDataById(id) local p = exports.ids:getPlayerByID(id) return getPlayerData(p) end function savePlayerToData(player) if players[player] == nil then updateValue(player, "name", "") updateValue(player, "surname", "") updateValue(player, "sex", "0") -- Биологический пол (не ламинат) 1- мужской, 2 - женский updateValue(player, "lastposition", {2005,1543,13.5}) updateValue(player, "skin", 29) end return players[getPlayerSerial(player)] end function onLogin(username,password,checkboxState, plr) if not (username == "") then if not (password == "") then local account = getAccount ( username, password ) if ( account ~= false ) then logIn(source, account, password) triggerClientEvent (source,"hideLoginPanel",getRootElement()) triggerClientEvent (source,"saveXML",getRootElement(),username,password,tostring(checkboxState)) triggerEvent("spawnPlayerLL", source, plr) else triggerClientEvent(source,"changeMessage",getRootElement(),"1","Добро пожаловать, пожалуйста войдите.", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"1","Пожалуйста, введите Ваш пароль.", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"1","Пожалуйста, введите Ваш логин.", "red") end end addEvent("onLogin",true) addEventHandler("onLogin",getRootElement(),onLogin) function onRegister(username,password) if not (username == "") then if not (password == "") then local account = getAccount (username) if (account == false) then addAccount(tostring(username),tostring(password)) triggerClientEvent(source,"changeMessage",getRootElement(),"2","Вы успешно зарегистрировались.", "green") triggerClientEvent(source,"changeMessage",getRootElement(),"1","Вы успешно зарегистрировались, войдите.", "green") triggerClientEvent(source,"pressBack", getRootElement()) else triggerClientEvent(source,"changeMessage",getRootElement(),"2","Этот логин не доступен.", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"2","Пожалуйста, введите пароль..", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"2","Пожалуйста, введите логин..", "red") end end addEvent("onRegister",true) addEventHandler("onRegister",getRootElement(),onRegister) function updateValue(player, key, value) if not (player == nil) then local p = getPlayerSerial(player) if players[p] == nil then players[p] = {} end players[p][key] = value end end function spawnPlayer(player) if not (player == nil) then local pdata = savePlayerToData(player) local x,y,z = unpack(pdata["lastposition"]) spawnPlayer(player,x,y,z,0,pdata["skin"],0,0) fadeCamera(player, true) setCameraTarget(player, player) end end function on_quit() local x,y,z = getElementPosition(source) updateValue(source, "lastposition", {x,y,z}) end addEventHandler('onPlayerQuit', root, on_quit) local function initScript() resetMapInfo() end addEventHandler("onResourceStart",resourceRoot,initScript) function informPlayerOnModelChange(oldModel, newModel) if ( getElementType(source) == "player" ) then -- Make sure the element is a player updateValue(source, "skin", newModel) end end addEventHandler("onElementModelChange", root, informPlayerOnModelChange) function onLogin(username,password,checkboxState, plr) if not (username == "") then if not (password == "") then local account = getAccount ( username, password ) if ( account ~= false ) then logIn(source, account, password) triggerClientEvent (source,"hideLoginPanel",getRootElement()) triggerClientEvent (source,"saveXML",getRootElement(),username,password,tostring(checkboxState)) spawnPlayer(plr) else triggerClientEvent(source,"changeMessage",getRootElement(),"1","Добро пожаловать, пожалуйста войдите.", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"1","Пожалуйста, введите Ваш пароль.", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"1","Пожалуйста, введите Ваш логин.", "red") end end addEvent("onLogin",true) addEventHandler("onLogin",getRootElement(),onLogin) function onRegister(username,password) if not (username == "") then if not (password == "") then local account = getAccount (username) if (account == false) then addAccount(tostring(username),tostring(password)) triggerClientEvent(source,"changeMessage",getRootElement(),"2","Вы успешно зарегистрировались.", "green") triggerClientEvent(source,"changeMessage",getRootElement(),"1","Вы успешно зарегистрировались, войдите.", "green") triggerClientEvent(source,"pressBack", getRootElement()) else triggerClientEvent(source,"changeMessage",getRootElement(),"2","Этот логин не доступен.", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"2","Пожалуйста, введите пароль..", "red") end else triggerClientEvent(source,"changeMessage",getRootElement(),"2","Пожалуйста, введите логин..", "red") end end addEvent("onRegister",true) addEventHandler("onRegister",getRootElement(),onRegister) 33 minutes ago, _SAXI_ said: The problem may be that you are using the player serial as the table index. Try this: local serials = {} function getSerialIndex(str) local index; if(str)then for i,serial in pairs(serials)do if(str == serial)then index = i; end end if not(index)then table.insert(serials,str); end return #serials; end return index; end function updateValue(player, key, value) if not (player == nil) then local p = getSerialIndex(getPlayerSerial(player)) if players[p] == nil then players[p] = {} end players[p][key] = value end end This would work as long as the script is not stopped... If you use this option, I recommend you complement it with a database error: "[22:15:04] ERROR: [gameplay]/lunarp/basic/server.lua:81: stack overflow" *code*
Moderators IIYAMA Posted February 18, 2022 Moderators Posted February 18, 2022 2 hours ago, Swimer said: Error on 3 line Are you sure you do not have defined a function called 'getPlayerSerial' somewhere else in the code? (other file for example)
Swimer Posted February 19, 2022 Author Posted February 19, 2022 11 hours ago, IIYAMA said: Are you sure you do not have defined a function called 'getPlayerSerial' somewhere else in the code? (other file for example) I'm sure not. 11 hours ago, IIYAMA said: Are you sure you do not have defined a function called 'getPlayerSerial' somewhere else in the code? (other file for example) And yes, this error is exactly when I function from an event handler that is called from the client. And the function works fine when I call it with onPlayerJoin
βurak Posted February 19, 2022 Posted February 19, 2022 (edited) not sure but here mta function name is used try changing it function spawnPlayer(player) -- <-- mta spawn function if not (player == nil) then local pdata = savePlayerToData(player) local x,y,z = unpack(pdata["lastposition"]) spawnPlayer(player,x,y,z,0,pdata["skin"],0,0) fadeCamera(player, true) setCameraTarget(player, player) end end Edited February 19, 2022 by Burak5312
Swimer Posted February 19, 2022 Author Posted February 19, 2022 1 hour ago, Burak5312 said: not sure but here mta function name is used try changing it function spawnPlayer(player) -- <-- mta spawn function if not (player == nil) then local pdata = savePlayerToData(player) local x,y,z = unpack(pdata["lastposition"]) spawnPlayer(player,x,y,z,0,pdata["skin"],0,0) fadeCamera(player, true) setCameraTarget(player, player) end end The standard function has 4 necessary arguments, but I have 1, so it's unlikely. But Lua is too specific, so I'll try it now 1 hour ago, Burak5312 said: not sure but here mta function name is used try changing it function spawnPlayer(player) -- <-- mta spawn function if not (player == nil) then local pdata = savePlayerToData(player) local x,y,z = unpack(pdata["lastposition"]) spawnPlayer(player,x,y,z,0,pdata["skin"],0,0) fadeCamera(player, true) setCameraTarget(player, player) end end It works! Topic closed
Recommended Posts