Jump to content

Table issues


.:HyPeX:.

Recommended Posts

Well, this is quite weird, it should never get past 17, but it reaches 18 and stays there....

  
             
            if fileDownload > 16 then 
            removeEventHandler('onClientRender',root, drawLoad) 
            local sfile = fileCreate("wheelDownload.txt") 
            fileWrite(sfile, "true") 
            fileClose(sfile) 
            return 
            end 
        a = nil 
        outputConsole("downloading.. ["..fileDownload + 1 .."] ".."wheels/"..wheels[fileDownload+1].name..".dff") 
        downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 
        outputConsole(fileDownload + 1) 
        fileName = wheels[fileDownload + 1].name 
        fileDownload = fileDownload + 1 
  

Console:

  
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
18 
  

Link to comment

Bump, i'm totally ragging all over this script, somehow, half the times i start it it fails loading...

When it fails it spams debugscript a lot of times, and then it stops giving errors... (Until it stops giving errors it lags a lot, but its just 1-2 sec)

Console:

n..117 

Error debugscript 3:

.lua:line 194: attemt to index field '?' (a nil value) 

  
local wheels = {} 
wheels[1] = {name="wheel_or1",id=1025,size=370} 
wheels[2] = {name="wheel_sr6",id=1073,size=412} 
wheels[3] = {name="wheel_sr3",id=1074,size=340} 
wheels[4] = {name="wheel_sr2",id=1075,size=364} 
wheels[5] = {name="wheel_lr4",id=1076,size=368} 
wheels[6] = {name="wheel_lr1",id=1077,size=356} 
wheels[7] = {name="wheel_lr3",id=1078,size=384} 
wheels[8] = {name="wheel_sr1",id=1079,size=366} 
wheels[9] = {name="wheel_sr5",id=1080,size=372} 
wheels[10] = {name="wheel_sr4",id=1081,size=358} 
wheels[11] = {name="wheel_gn1",id=1082,size=386} 
wheels[12] = {name="wheel_lr2",id=1083,size=370} 
wheels[13] = {name="wheel_lr5",id=1084,size=370} 
wheels[14] = {name="wheel_gn2",id=1085,size=370} 
wheels[15] = {name="wheel_gn3",id=1096,size=364} 
wheels[16] = {name="wheel_gn4",id=1097,size=368} 
wheels[17] = {name="wheel_gn5",id=1098,size=360} 
  
local fileDownload = 0 
local endingFile = 17 
local fileName = "" 
addEventHandler('onClientResourceStart',resourceRoot, function() 
if fileExists("wheelDownload.txt") then 
    local file = fileOpen("wheelDownload.txt") 
    local size = fileGetSize(file) 
    local txt = fileRead(file,size) 
    fileClose(file) 
    if txt == "true" then 
    downloadTxd() 
    else 
    for i,v in ipairs(wheels) do 
    local result = fileExists("wheels/"..v.name..".txt") 
        if result then 
        fileDownload = fileDownload + 1 
            if fileDownload > 16 then 
            local sfile = fileCreate("wheelDownload.txt") 
            fileWrite(sfile, "true") 
            fileClose(sfile) 
            downloadTxd() 
            return 
            end 
        end 
    end 
    if fileDownload >= 1 then 
    downloadFile("wheels/"..wheels[fileDownload].name..".dff") 
    fileName = wheels[fileDownload].name 
    addEventHandler('onClientRender',root,drawLoad) 
    outputConsole("Y..1"..fileDownload) 
    else 
    fileDownload = 1 
    downloadFile("wheels/"..wheels[fileDownload].name..".dff") 
    fileName = wheels[fileDownload].name 
    addEventHandler('onClientRender',root,drawLoad) 
    outputConsole("Y..2"..fileDownload) 
    end 
    end 
else 
    for i,v in ipairs(wheels) do 
    local result = fileExists("wheels/"..v.name..".txt") 
        if result then 
        fileDownload = fileDownload + 1 
            if fileDownload > 16 then 
            local sfile = fileCreate("wheelDownload.txt") 
            fileWrite(sfile, "true") 
            fileClose(sfile) 
            downloadTxd() 
            return 
            end 
        end 
    end 
    if fileDownload >= 1 then 
    downloadFile("wheels/"..wheels[fileDownload].name..".dff") 
    fileName = wheels[fileDownload].name 
    addEventHandler('onClientRender',root,drawLoad) 
    outputConsole("n..1"..fileDownload) 
    else 
    outputConsole("n..2"..fileDownload) 
    fileDownload = 1 
    downloadFile("wheels/"..wheels[fileDownload].name..".dff") 
    fileName = wheels[fileDownload].name 
    addEventHandler('onClientRender',root,drawLoad) 
    end 
end 
end) 
  
  
local x,y = guiGetScreenSize() 
  
-- [[ MATHS SHIT ]] -- 
local barx = 305 
local ox = 1920 
local xsize = (barx / 1920) * x 
local bary = 27 
local oy = 1080 
local ysize = (bary / 1080) * y 
  
local mx = (808/1920)*x 
local my = (944/1080)*y 
local my2 = (4/1080)*y 
  
local boxx = 44 
local xbox = (boxx / 1920) * x 
local boxy = 33 
local ybox = (boxy / 1080) * y 
  
local tenx =  (10/1920) * x 
  
local font0 = dxCreateFont("fontdefault.ttf", 10) 
local font1 = dxCreateFont("fontbold.ttf", 10) 
local font2 = dxCreateFont("fontdefault.ttf", 11) 
  
function drawLoad() 
local total = 0 
local current = 0 
for i=1, 17 do 
total = total + wheels[i].size 
if i < fileDownload then 
    current = current + wheels[i].size 
end 
end 
  
if fileExists("wheels/"..fileName..".dff") then 
local file = fileOpen("wheels/"..fileName..".dff",true) 
local size =fileGetSize(file) 
fileClose(file) 
local size = math.floor(size/1000) 
local progress = ((size + current)/ total) 
local oR,oG,oB = 68,160,197 
local nR,nG,nB = 136,206,170 
local slice = (xsize - (tenx*2)) / 100 
for i=1, 100 do 
if i  >= math.floor(progress*100) then 
else 
local r,g,b = interpolateBetween(oR,oG,oB,nR,nG,nB,i/100,"Linear") 
dxDrawImage(mx + tenx + (slice * (i-1)),my + ysize/2-my2/4,slice,my2,"loading/progress.png",0,0,0, tocolor(r,g,b,255)) 
end 
end 
dxDrawImage( mx +tenx + (slice * (progress*100)) - (xbox / 2), (924/1080)*y, xbox, ybox, "loading/box.png", 0,0,0,tocolor(255,255,255,255)) 
dxDrawText( math.floor((progress*100)).."%",mx +tenx + (slice * (progress*100))-xbox, (924/1080)*y, mx +tenx + (slice * (progress*100)) + xbox, (924/1080)*y + ybox,tocolor(255,255,255,255),  1.00, font1, "center", "center") 
dxDrawImage( mx,my,xsize,ysize,"loading/bar.png",0,0,0,tocolor(255,255,255,255))dxDrawImage( mx,my,xsize,ysize,"loading/bar.png",0,0,0,tocolor(255,255,255,255)) 
local width = dxGetTextWidth("current file: ", 1, font0) 
dxDrawText("current file: ", (888/1920)*x,(971/1080)*y,x*1,y*1,tocolor(255,255,255,255), 1, font0) 
dxDrawText(fileName..".dff", (888/1920)*x+width,(971/1080)*y,x*1,y*1,tocolor(255,255,255,255), 1, font1) 
end 
if wheelstxd then 
if fileExists("wheels/wheels.txd") then 
local file = fileOpen("wheels/wheels.txd",true) 
local size =fileGetSize(file) 
fileClose(file) 
local size = math.floor(size/1000) 
local progress = (size/ 6767) 
dxDrawText("Downloading File: "..fileName..".txd", x*0.05,y*0.5,x*0.5,y*0.6,tocolor(255,255,255,255), 1.5, "default") 
  
end 
end 
end 
  
c = nil 
addEventHandler('onClientFileDownloadComplete',root,function(file,success) 
if file == "wheels/wheels.txd" then 
    if success then 
        loadWheels() 
        sfile = fileCreate("wheels/wheels.txd") 
        fileWrite(sfile,"true") 
        fileClose(sfile) 
    else 
        downloadFile("wheels/wheels.txd") 
    end 
end 
    if ( success == true ) then 
    c = nil 
for i,v in ipairs(wheels) do 
    if (file) == ("wheels/"..v.name..".dff") then 
    c=true 
    end 
end 
if not c then return end 
            local sfile = string.gsub(file, ".dff", "") 
            local sfile = fileCreate(sfile..".txt") 
            fileWrite(sfile, "true") 
            fileClose(sfile) 
             
            if fileDownload > 16 then 
            removeEventHandler('onClientRender',root, drawLoad) 
            local sfile = fileCreate("wheelDownload.txt") 
            fileWrite(sfile, "true") 
            fileClose(sfile) 
            downloadTxd() 
            return 
            end 
        a = nil 
        downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 
        fileName = wheels[fileDownload + 1].name 
        fileDownload = fileDownload + 1 
    end 
end) 
  
function downloadTxd() 
if not fileExists("wheels/wheels.txt") then 
    downloadFile("wheels/wheels.txd") 
    else 
    loadWheels() 
    end 
end 
  
function loadWheels() 
        txd = engineLoadTXD("wheels/wheels.txd") 
    for i,v in ipairs(wheels) do 
        engineImportTXD(txd, v.id) 
        dff = engineLoadDFF("wheels/"..v.name..".dff") 
        engineReplaceModel(dff,v.id) 
    end 
end 
  

Link to comment
downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 

Will find this kind of table:

wheels = { 
    name = { 
        --stuff 
    } 
} 

Try this:

downloadFile("wheels/"..wheels[fileDownload+1][1]..".dff") 

This will get the first thing in the table, which is the name.

Link to comment
downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 

Will find this kind of table:

wheels = { 
    name = { 
        --stuff 
    } 
} 

Try this:

downloadFile("wheels/"..wheels[fileDownload+1][1]..".dff") 

This will get the first thing in the table, which is the name.

Well I think you misunderstood this. I'm sure thid error starts after 17 because there is no 18 index in table.

Link to comment
That code gives me headache when trying to read it, anyway, simply check if the index is on your table.
  
        if wheels[fileDownload+1] then 
        downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 
        fileName = wheels[fileDownload + 1].name 
        fileDownload = fileDownload + 1 
        else 
        return end 

Its weird, it still gives me errors.

But whats most strange, is that the error only happens exactly the half of the times. I.e if i turn it off and start it again it will work...

Link to comment

It is, in fact right....

  
        if wheels[fileDownload+1] then 
        outputConsole( type( wheels[fileDownload+1] ) ) 
        outputConsole(wheels[fileDownload+1]) 
        downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 
        fileName = wheels[fileDownload + 1].name 
        fileDownload = fileDownload + 1 
        else 
        return end 
  

  
stop: Resource stopping 
Server FPS limit: 0 (Using 65) 
* [server] FPS Limit Script by HyPeX was started. 
* [server] Usage: /sfps [fps] 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
table 
n..117 
* [Client] FPS Settings were loaded. 
* [Client] Your FPS Limit is: 65 
* [Client] Usage: */sfps [fps] 
start: Resource '5team' started 
  

Second test:

  
        if wheels[fileDownload+1] then 
        outputConsole( type( wheels[fileDownload+1] ).name ) 
        outputConsole(wheels[fileDownload+1].name) 
        downloadFile("wheels/"..wheels[fileDownload+1].name..".dff") 
        fileName = wheels[fileDownload + 1].name 
        fileDownload = fileDownload + 1 
        else 
        return end 

  
stop: Resource stopping 
Server FPS limit: 0 (Using 65) 
* [server] FPS Limit Script by HyPeX was started. 
* [server] Usage: /sfps [fps] 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
wheel_lr3 
n..117 
* [Client] FPS Settings were loaded. 
* [Client] Your FPS Limit is: 65 
* [Client] Usage: */sfps [fps] 
start: Resource '5team' started 
  

Link to comment

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...