Jump to content

crash on the server


Fabioxps

Recommended Posts

Posted

load XML files without causing a crash on the server, I am carrying a map. this is only possible with php?

            for i,par in ipairs(xmlNodeGetChildren(arquivoMap)) do 
                local objectType = xmlNodeGetName(par) 
                if objectType == "object" then 
                    _indexInto.obj = {insertType = objectType, 
                    model = tonumber(xmlNodeGetAttribute(p,"model")), 
                    pX = tonumber(xmlNodeGetAttribute(p,"posX")), 
                    pY = tonumber(xmlNodeGetAttribute(p,"posY")), 
                    pZ = tonumber(xmlNodeGetAttribute(p,"posZ")), 
                    rX = tonumber(xmlNodeGetAttribute(p,"rotX")), 
                    rY = tonumber(xmlNodeGetAttribute(p,"rotY")), 
                    rZ = tonumber(xmlNodeGetAttribute(p,"rotZ")) or tonumber(xmlNodeGetAttribute(p, "rotation"))} 
               end 
               end 
              _indexIntoTable[#_indexIntoTable+1] = _indexInto.obj 
  

  • Moderators
Posted

XML is slow, you should load it slowly.

"without"

without what to be exact?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

My version, not tested.

  
local slowLoopTable = {} 
local maxItemsPerLoop = 30  
  
local slowLoopFunction = function (theTable) 
    local tableData = slowLoopTable[theTable] 
    if tableData then 
        local startValue = tableData["startValue"] 
        local endValue = tableData["endValue"] 
        local processFunction = tableData["processFunction"] 
        for i=startValue, endValue do 
            tableData["processFunction"](i,theTable[i]) 
        end 
  
        local maxItemsPerLoop = (theTable["maxItemsPerLoop"] or maxItemsPerLoop) 
  
  
        local newStartValue = endValue+1 
        if newStartValue <= #theTable then 
            tableData["startValue"] = newStartValue 
            local newEndValue = newStartValue+maxItemsPerLoop 
            if newEndValue > #theTable then 
                tableData["endValue"] = #theTable 
        else 
        tableData["endValue"] = newEndValue 
            end 
            --tableData["timer"] = setTimer(slowLoopFunction,400,1,theTable) 
            resetTimer (tableData["timer"]) 
        else 
            slowLoopTable[theTable] = nil 
        end 
    end 
end 
  
  
function startSlowLoop (theTable,processFunction,itemsPerLoop) 
    local slowLoopTimer = setTimer(slowLoopFunction,400,1,theTable) 
    if slowLoopTimer then 
        local maxItemsPerLoop = tonumber(itemsPerLoop) or maxItemsPerLoop -- protect the variable against overwrite 
        if maxItemsPerLoop > #theTable then 
            maxItemsPerLoop = #theTable 
        end 
  
        slowLoopTable[theTable]= { 
            ["timer"]= slowLoopTimer, -- can be useful for a quick abort and reset. 
            ["startValue"]= 1, 
            ["endValue"]= maxItemsPerLoop, 
            ["maxItemsPerLoop"]= maxItemsPerLoop, 
            ["processFunction"]= processFunction 
        } 
    end 
end 
  
  
--[[ supports multiply tables 
----------------------------- ]] 
  
  
  
  
  

syntrax

startSlowLoop ( theTable, processFunction [, itemsPerLoop = 30] ) 

Send to process function.

( index, par ) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

look at the syntax. Function is second argument.

If you want to know when the process is completed, you can call your finished function between line: 30 and 31.

Example/test run:

local theTable = {3,5,36,547,36,3,8,9,3,6,7,8,5,4,7,8,4,8,5,2,2,1} 
  
function executeProcess (index, par) 
   outputChatBox(tostring(index) .. " " .. tostring(par))  
   -- do your stuff here -- 
end 
  
startSlowLoop ( theTable, executeProcess, 5)  

Afaik you need the code, then you test it.

Go ahead.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • 4 weeks later...
  • Moderators
Posted

Seriously, replying on this 1 month later.....

The slowLoopCode.

local slowLoopTable = {} 
local maxItemsPerLoop = 30 
  
local slowLoopFunction = function (theTable) 
    local tableData = slowLoopTable[theTable] 
    if tableData then 
        local startValue = tableData["startValue"] 
        local endValue = tableData["endValue"] 
        local processFunction = tableData["processFunction"] 
        for i=startValue, endValue do 
            tableData["processFunction"](i,theTable[i]) 
        end 
  
        local maxItemsPerLoop = (theTable["maxItemsPerLoop"] or maxItemsPerLoop) 
  
  
        local newStartValue = endValue+1 
        if newStartValue <= #theTable then 
            tableData["startValue"] = newStartValue 
            local newEndValue = newStartValue+maxItemsPerLoop 
            if newEndValue > #theTable then 
                tableData["endValue"] = #theTable 
        else 
        tableData["endValue"] = newEndValue 
            end 
            --tableData["timer"] = setTimer(slowLoopFunction,400,1,theTable) 
            resetTimer (tableData["timer"]) 
        else 
            slowLoopTable[theTable] = nil 
        end 
    end 
end 
  
  
function startSlowLoop (theTable,processFunction,itemsPerLoop) 
    local slowLoopTimer = setTimer(slowLoopFunction,400,1,theTable) 
    if slowLoopTimer then 
        local maxItemsPerLoop = tonumber(itemsPerLoop) or maxItemsPerLoop -- protect the variable against overwrite 
        if maxItemsPerLoop > #theTable then 
            maxItemsPerLoop = #theTable 
        end 
  
        slowLoopTable[theTable]= { 
            ["timer"]= slowLoopTimer, -- can be useful for a quick abort and reset. 
            ["startValue"]= 1, 
            ["endValue"]= maxItemsPerLoop, 
            ["maxItemsPerLoop"]= maxItemsPerLoop, 
            ["processFunction"]= processFunction 
        } 
    end 
end 
  
  
--[[ supports multiply tables 
----------------------------- ]] 
  

Example how to execute it.

  
    local theTable = {3,5,36,547,36,3,8,9,3,6,7,8,5,4,7,8,4,8,5,2,2,1} 
      
    function executeProcess (index, par) 
       outputChatBox(tostring(index) .. " " .. tostring(par)) 
       -- do your stuff here -- 
    end 
      
    startSlowLoop ( theTable, executeProcess, 5) 

Put them both in one of your scripts and execute it. Then you will know what it does.(if I didn't made a mistake)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...