• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Need more efficiency in a script, challenge for knowledgeable, test your skills.

Peonso

Godly Member
Joined
Jan 14, 2008
Messages
1,752
Solutions
30
Reaction score
1,542
I changed this function (https://otland.net/threads/savemap-function-saves-it-to-a-new-otbm.193781/ // https://otland.net/threads/saving-map-in-game-creates-a-new-otbm.141986/) that saves current map, to actually convert the map and save it. My intent is to convert maps to 7.6 format. The problem is, it take ages. Small 200x200 6 floors map can take more then half an hour to convert, I need to speed up the process but my lua knowledge is limited. Here is the code: https://gist.github.com/peonso/835501dd76bf856aaf434200dfe9736b (I'm updating it constantly with more items). Sorry for the click bait title.

Code:
--    add this to data\globalevents\scripts\startup.lua
--    -- convert map and save
--    saveMap("converted_map.otbm", {x=100,y=1000,z=4}, {x=1200,y=1200,z=10}) -- from lowest x,y,z to highest ones

conversion = { -- to 7.6
   [392] = {id = 383},
    [489] = {id = 482},
    [490] = {id = 4608},
    [491] = {id = 4609},
    [492] = {id = 4610},
    [618] = {id = 4611},
    [619] = {id = 4612},
    [620] = {id = 4613},
    [621] = {id = 4614},
    [622] = {id = 4615},
    [623] = {id = 4616},
    [624] = {id = 4608},
    [625] = {id = 4609},
    [626] = {id = 4610},
    [627] = {id = 4611},
    [628] = {id = 4612},
    [629] = {id = 4613},
    [695] = {id = 406},
    [696] = {id = 407},
    [1492] = {id = 1487},
    [1493] = {id = 1488},
    [1494] = {id = 1489},
    [1495] = {id = 1491},
    [1496] = {id = 1490},
    [1500] = {id = 1487},
    [1501] = {id = 1488},
    [1502] = {id = 1489},
    [1503] = {id = 1490},
    [1504] = {id = 1491},
    -- 3134 ends 7.4
    [4617] = {id = 4608},
    [4618] = {id = 4609},
    [4619] = {id = 4610},
    [4620] = {id = 4611},
    [4621] = {id = 4612},
    [4622] = {id = 4613},
    [4623] = {id = 4614},
    [4624] = {id = 4615},
    [4625] = {id = 4616},
    [4664] = {id = 4614},
    [4665] = {id = 4615},
    [4666] = {id = 4616},
    [4820] = {id = 4608},
    [4821] = {id = 4609},
    [4822] = {id = 4610},
    [4823] = {id = 4611},
    [4824] = {id = 4612},
    [4825] = {id = 4613},
    [5023] = {id = 1387},
    [5024] = {id = 1387},
    -- 5089 ends 7.6
    [5098] = {id = 1212},
    [5099] = {id = 1213},
    [5100] = {id = 1214},
    [5101] = {id = 1221},
    [5102] = {id = 1222},
    [5103] = {id = 1229},
    [5104] = {id = 1230},
    [5105] = {id = 1225},
    [5106] = {id = 1226},
    [5107] = {id = 1209},
    [5108] = {id = 1210},
    [5109] = {id = 1211},
    [5110] = {id = 1219},
    [5111] = {id = 1220},
    [5112] = {id = 1227},
    [5113] = {id = 1228},
    [5114] = {id = 1223},
    [5115] = {id = 1224},
    [5146] = {id = 1037},
    [5147] = {id = 1037},
    [5148] = {id = 1037},
    [5149] = {id = 1036},
    [5150] = {id = 1036},
    [5151] = {id = 1036},
    [5152] = {id = 1037},
    [5153] = {id = 1037},
    [5154] = {id = 1036},
    [5155] = {id = 1036},
    [5258] = {id = 3688},
    [5259] = {id = 1385},
    [5260] = {id = 3688},
    [5324] = {id = 1038},
    [5543] = {id = 1386},
    [5631] = {id = 358, border = true},
    [5632] = {id = 356, border = true},
    [5633] = {id = 366, border = true},
    [5634] = {id = 367, border = true},
    [5635] = {id = 364, border = true},
    [5636] = {id = 365, border = true},
    [5637] = {id = 359, border = true},
    [5638] = {id = 357, border = true},
    [5639] = {id = 373, border = true},
    [5640] = {id = 371, border = true},
    [5641] = {id = 374, border = true},
    [5642] = {id = 372, border = true},
    [5643] = {id = 381, border = true},
    [5644] = {id = 382, border = true},
    [5645] = {id = 379, border = true},
    [5646] = {id = 380, border = true},
    [5647] = {id = 360, border = true},
    [5648] = {id = 375, border = true},
    [5649] = {id = 362, border = true},
    [5650] = {id = 363, border = true},
    [5651] = {id = 361, border = true},
    [5652] = {id = 376, border = true},
    [5653] = {id = 377, border = true},
    [5654] = {id = 378, border = true},
    [5683] = {id = 356, border = true},
    [5684] = {id = 356, border = true},
    [5685] = {id = 358, border = true},
    [5686] = {id = 358, border = true},
    [5711] = {id = 101},
    [5712] = {id = 101},
    [5713] = {id = 101},
    [5714] = {id = 101},
    [5715] = {id = 101},
    [5716] = {id = 101},
    [5717] = {id = 101},
    [5718] = {id = 101},
    [5719] = {id = 101},
    [5720] = {id = 101},
    [5721] = {id = 101},
    [5722] = {id = 101},
    [5723] = {id = 101},
    [5724] = {id = 101},
    [5725] = {id = 101},
    [5726] = {id = 101},
    [5731] = {id = 482},
    [5768] = {id = 1284},
    [5769] = {id = 1284},
    [5770] = {id = 1284},
    [6127] = {id = 459},
    [6128] = {id = 459},
    [6129] = {id = 485},
    [6130] = {id = 485},
    [6173] = {id = 924},
    [6174] = {id = 924},
    [6281] = {id = 1026},
    [6282] = {id = 1025},
    [6283] = {id = 1026},
    [6284] = {id = 1025},
    [6436] = {id = 1263},
    [6437] = {id = 1264},
    [6438] = {id = 1263},
    [6439] = {id = 1264},
    [6440] = {id = 1265},
    [6441] = {id = 1266},
    [6442] = {id = 1265},
    [6443] = {id = 1266},
    [6444] = {id = 1267},
    [6445] = {id = 1268},
    [6446] = {id = 1267},
    [6447] = {id = 1268},
    [6580] = {id = 670},
    [6581] = {id = 670},
    [6582] = {id = 670},
    [6583] = {id = 670},
    [6584] = {id = 670},
    [6585] = {id = 670},
    [6586] = {id = 670},
    [6587] = {id = 670},
    [6588] = {id = 670},
    [6589] = {id = 670},
    [6590] = {id = 670},
    [6591] = {id = 670},
    [6592] = {id = 670},
    [6593] = {id = 670},
    [6594] = {id = 670},
    [6595] = {id = 670},
    [6596] = {id = 670},
    [6597] = {id = 670},
    [6598] = {id = 670},
    [6599] = {id = 670},
    [6600] = {id = 670},
    [6601] = {id = 670},
    [6602] = {id = 670},
    [6603] = {id = 670},
    [6604] = {id = 670},
    [6605] = {id = 670},
    [6606] = {id = 670},
    [6607] = {id = 670},
    [6608] = {id = 670},
    [6683] = {id = 671},
    [6684] = {id = 671},
    [6685] = {id = 671},
    [6686] = {id = 671},
    [6838] = {id = 670},
    [6967] = {id = 671},
    [6909] = {id = 1388},
    [6910] = {id = 1389},
    [6911] = {id = 1390},
    [6912] = {id = 1391},
    [6913] = {id = 1392},
    [6914] = {id = 1393},
    [6915] = {id = 1394},
    [6916] = {id = 1395},
    [6917] = {id = 479},
    [6918] = {id = 480},
    [6919] = {id = 484},
    [6920] = {id = 484},
    [6921] = {id = 476},
    [6922] = {id = 475},
    [6923] = {id = 459},
    [6924] = {id = 459},
    [7062] = {id = 791},
    [7063] = {id = 791},
    [7064] = {id = 791},
    [7065] = {id = 791},
    [7066] = {id = 791},
    [7348] = {id = 431},
    [7350] = {id = 491},
    [7351] = {id = 407},
    [7352] = {id = 103},
    [7353] = {id = 413},
    [7354] = {id = 355},
    [7355] = {id = 3152},
    [7356] = {id = 4405},
    [7357] = {id = 3139},
    [7358] = {id = 420},
    [7924] = {id = 1392},
    [7925] = {id = 1388},
    [7975] = {id = 101},
    [7976] = {id = 101},
    [8276] = {id = 369},
    [8277] = {id = 369},
    [8279] = {id = 369},
    [8280] = {id = 409},
    [8281] = {id = 410},
    [8282] = {id = 411},
    [8283] = {id = 423},
    [8284] = {id = 427},
    [8285] = {id = 428},
    [8286] = {id = 429},
    [8315] = {id = 231},
    [8316] = {id = 231},
    [8317] = {id = 231},
    [8318] = {id = 231},
    [8319] = {id = 231},
    [8320] = {id = 231},
    [8321] = {id = 231},
    [8322] = {id = 231},
    [8326] = {id = 106},
    [8327] = {id = 106},
    [8328] = {id = 106},
    [8329] = {id = 106},
    [8330] = {id = 106},
    [8331] = {id = 106},
    [8332] = {id = 106},
    [8333] = {id = 106},
    [8334] = {id = 106},
    [8347] = {id = 106},
    [8348] = {id = 106},
    [8372] = {id = 1388},
    [8373] = {id = 1389},
    [8374] = {id = 1390},
    [8375] = {id = 1391},
    [8376] = {id = 1392},
    [8377] = {id = 1393},
    [8378] = {id = 1394},
    [8379] = {id = 1395},
    [8559] = {id = 479},
    [8560] = {id = 480},
    [8561] = {id = 470},
    [8562] = {id = 470},
    [8563] = {id = 476},
    [8564] = {id = 475},
    [8565] = {id = 459},
    [8566] = {id = 459},
    [8599] = {id = 1386},
    [8671] = {id = 2555},
    [9021] = {id = 351},
    [9022] = {id = 352},
    [9023] = {id = 353},
    [9024] = {id = 354},
    [9025] = {id = 355},
    [9026] = {id = 101},
    [9027] = {id = 101},
    [9028] = {id = 101},
    [9029] = {id = 101},
    [9030] = {id = 101},
    [9031] = {id = 101},
    [9032] = {id = 101},
    [9033] = {id = 101},
    [9034] = {id = 101},
    [9035] = {id = 101},
    [9036] = {id = 101},
    [9037] = {id = 101},
    [9038] = {id = 101},
    [9039] = {id = 101},
    [9040] = {id = 101},
    [9041] = {id = 101},
    [9042] = {id = 101},
    [9043] = {id = 4526},
    [9044] = {id = 4527},
    [9045] = {id = 4528},
    [9046] = {id = 4529},
    [9047] = {id = 4530},
    [9048] = {id = 4531},
    [9049] = {id = 4532},
    [9050] = {id = 4533},
    [9051] = {id = 4534},
    [9052] = {id = 4535},
    [9053] = {id = 4536},
    [9054] = {id = 4537},
    [9055] = {id = 4538},
    [9056] = {id = 4539},
    [9057] = {id = 4540},
    [9058] = {id = 4541},
    [9059] = {id = 231},
    [9067] = {id = 405},
    [9144] = {id = 406},
    [9145] = {id = 406},
    [9146] = {id = 406},
    [9224] = {id = 3139},
    [9225] = {id = 3139},
    [9226] = {id = 3139},
    [9227] = {id = 3139},
    [9228] = {id = 3139},
    [9229] = {id = 3139},
    [9230] = {id = 3139},
    [9231] = {id = 3139},
    [9232] = {id = 3139},
    [9573] = {id = 1385},
    [9574] = {id = 432},
    [9606] = {id = 433},
    [9682] = {id = 1284},
    [9683] = {id = 1284},
    [9684] = {id = 1284},
    [9685] = {id = 1284},
    [9846] = {id = 433},
    [10177] = {id = 1049},
    [10178] = {id = 1050},
    [10179] = {id = 1051},
    [10180] = {id = 1050},
    [10181] = {id = 1053},
    [10182] = {id = 1049},
    [10183] = {id = 1049},
    [10184] = {id = 1049},
    [10185] = {id = 1053},
    [10186] = {id = 1050},
    [10187] = {id = 1053},
    [10192] = {id = 1049},
    [10193] = {id = 1049},
    [10195] = {id = 1050},
    [10196] = {id = 1050},
    [10398] = {id = 413},
    [10399] = {id = 413},
    [10400] = {id = 413},
    [10401] = {id = 413},
    [10402] = {id = 413},
    [10403] = {id = 413},
    [10404] = {id = 413},
    [10488] = {id = 1267},
    [10489] = {id = 1268},
    [10490] = {id = 1267},
    [10491] = {id = 1268},
    [10492] = {id = 791},
    [10493] = {id = 791},
    [10494] = {id = 791},
    [10495] = {id = 791},
    [10496] = {id = 791},
    [10497] = {id = 791},
    [10498] = {id = 791},
    [11062] = {id = 426},
    [11063] = {id = 426},
    -- 11703 ends 8.6
    [17665] = {id = 106},
    [17666] = {id = 106},
    [17667] = {id = 106},
    [17668] = {id = 106},
    [17669] = {id = 106},
    [17670] = {id = 106},
    [17671] = {id = 106},
    [17672] = {id = 106},
    [17673] = {id = 4786},
    [17674] = {id = 4784},
    [17675] = {id = 4785},
    [17676] = {id = 4787},
    [17677] = {id = 4795},
    [17678] = {id = 4794},
    [17679] = {id = 4792},
    [17680] = {id = 4793},
    [17681] = {id = 4791},
    [17682] = {id = 4790},
    [17683] = {id = 4788},
    [17684] = {id = 4789},
    [18162] = {id = 4411},
    [18163] = {id = 4413},
    [18164] = {id = 4415},
    [18165] = {id = 4417},
    [18166] = {id = 4419},
    [18167] = {id = 4412},
    [18168] = {id = 4414},
    [18169] = {id = 4416},
    [18170] = {id = 4418},
    [18171] = {id = 4420},
    [18172] = {id = 4514},
    [18173] = {id = 4516},
    [18174] = {id = 4515},
    [18175] = {id = 4517},
    [18176] = {id = 4521},
    [18177] = {id = 4520},
    [18178] = {id = 4518},
    [18179] = {id = 4519},
    [18180] = {id = 4525},
    [18181] = {id = 4524},
    [18182] = {id = 4522},
    [18183] = {id = 4523},
    [18184] = {id = 4514},
    [18185] = {id = 4516},
    [18186] = {id = 4515},
    [18187] = {id = 4517},
    [18188] = {id = 4521},
    [18189] = {id = 4520},
    [18190] = {id = 4518},
    [18191] = {id = 4519},
    [18192] = {id = 4525},
    [18193] = {id = 4524},
    [18194] = {id = 4522},
    [18195] = {id = 4523},
    [18764] = {id = 405},
    [18765] = {id = 405},
    [18766] = {id = 405},
    [18767] = {id = 405},
    [18768] = {id = 405},
    [18769] = {id = 405},
    [19785] = {id = 431},
    [19786] = {id = 431},
    [19787] = {id = 431},
    [19788] = {id = 431},
    [19789] = {id = 431},
    [19790] = {id = 431},
    [19824] = {id = 413},
    [19825] = {id = 413},
    [19826] = {id = 413},
    [19827] = {id = 413},
    -- 21217 ends 10.41
    -- 24332 ends 10.77
}

bit32 = bit

--SPECIAL CHARACTERS
NODE_START = 0xfe
NODE_END = 0xff
ESCAPE_CHAR = 0xfd

--OTBM NODE TYPES
OTBM_ROOTV1 = 1
OTBM_MAP_DATA = 2
OTBM_ITEM_DEF = 3
OTBM_TILE_AREA = 4
OTBM_TILE = 5
OTBM_ITEM = 6
OTBM_TILE_SQUARE = 7
OTBM_TILE_REF = 8
OTBM_SPAWNS = 9
OTBM_SPAWN_AREA = 10
OTBM_MONSTER = 11
OTBM_TOWNS = 12
OTBM_TOWN = 13
OTBM_HOUSETILE = 14

--OTBM ATTR TYPES
OTBM_ATTR_DESCRIPTION = 1
OTBM_ATTR_EXT_FILE = 2
OTBM_ATTR_TILE_FLAGS = 3
OTBM_ATTR_ACTION_ID = 4
OTBM_ATTR_UNIQUE_ID = 5
OTBM_ATTR_TEXT = 6
OTBM_ATTR_DESC = 7
OTBM_ATTR_TELE_DEST = 8
OTBM_ATTR_ITEM = 9
OTBM_ATTR_DEPOT_ID = 10
OTBM_ATTR_EXT_SPAWN_FILE = 11
OTBM_ATTR_RUNE_CHARGES = 12
OTBM_ATTR_EXT_HOUSE_FILE = 13
OTBM_ATTR_HOUSEDOORID = 14
OTBM_ATTR_COUNT = 15
OTBM_ATTR_DURATION = 16
OTBM_ATTR_DECAYING_STATE = 17
OTBM_ATTR_WRITTENDATE = 18
OTBM_ATTR_WRITTENBY = 19
OTBM_ATTR_SLEEPERGUID = 20
OTBM_ATTR_SLEEPSTART = 21
OTBM_ATTR_CHARGES = 22

function lchar(i) s="" while i>0 do s=s..string.char(i%256) i=math.floor(i/256) end return s end

function format(s,size)
    local len = #s
 
    for x=1,size/8-len do
        s=s.."\0"
    end
 
    return s
end

function writeData(f,data,size,unescape)
    local thestr
 
    if type(data) == "string" then
        thestr = format(data,size)
    elseif type(data) == "number" then
        thestr = format(lchar(data),size)
    elseif type(data) == "table" then
        for k,v in pairs(data) do
            print(k,v)
        end
        return
    else
        print(data)
        return
    end
 
    for x=1,size/8 do
        local c = thestr:sub(x,x)
        --print(#thestr,size,string.byte(c))
        --if c == string.char(0x0D) then error("daonde") end
        if unescape and (c==string.char(NODE_START) or c==string.char(NODE_END) or c==string.char(ESCAPE_CHAR)) then
            f:write(string.char(ESCAPE_CHAR))
        end
        f:write(c)
    end
end

function addU8(f,data)
    writeData(f,data,8,true)
end
function addByte(f,data)
    writeData(f,data,8,false)
end
function addU16(f,data)
    writeData(f,data,16,true)
end
function addU32(f,data)
    writeData(f,data,32,false)
end
function addString(f,data)
    if #data > 0xffff then
        return false
    end
    addU16(f,#data)
    writeData(f,data,#data*8,false)
end

function startNode(f,c) --c is a char
    writeData(f,NODE_START,8,false)
    writeData(f,c,8,true)
end

function endNode(f)
    writeData(f,NODE_END,8,false)
end

WIDTH = 2048 --put here the dimensions of your map
HEIGHT = 2048 --
ITEMDWMAJORVERSION = 3    -- https://github.com/hjnilsson/rme/blob/master/data/clients.xml#L73 7.6 = 2
ITEMDWMINORVERSION = 55    -- https://github.com/hjnilsson/rme/blob/master/data/clients.xml#L73 7.6 = 3

function saveMap(name, frompos, topos) --e.g. "map.otbm"
    print("saveMap start")
    startconversion = ">> - Conversion started: " ..os.date("%d %b %Y %X", (os.time()))
    f = io.open(name,"wb")
    addU32(f,0); --version
    startNode(f,0)
    addU32(f,0); --version again :O
    addU16(f,WIDTH)
    addU16(f,HEIGHT)
    addU32(f,ITEMDWMAJORVERSION)
    addU32(f,ITEMDWMINORVERSION)

    startNode(f,OTBM_MAP_DATA)
    --addByte(f,OTBM_ATTR_DESCRIPTION)
    --addString(f,"Created with saveMap script, a translation of Remere's")
    local first = true
    local l_x=-1
    local l_y=-1
    local l_Z=-1
    for z=frompos.z,topos.z do
        local progprint = 0
        for x=frompos.x,topos.x do
            local prog = (x - frompos.x) * 100 / (topos.x - frompos.x)
            if math.floor(prog) > progprint then
                print("Saving " .. name .. ", level " .. z + 1 - frompos.z .. "/" .. topos.z - frompos.z + 1 .. "(" .. math.floor(prog) .. "%) ... total [" .. math.floor((prog + 100 * (z - frompos.z)) / (topos.z - frompos.z + 1)) .. "%]" ..os.date("%d %b %Y %X", (os.time())))
                progprint = math.floor(prog)
            end
            for y=frompos.y,topos.y do
                if x<l_x or x>=l_x+256 or y<l_y or y>=l_y+256 or z~=l_z then
                    if not first then
                        endNode(f)
                    end
                    first = false
                    --start new node
                    startNode(f,OTBM_TILE_AREA)
                    l_x=bit32.band(x,0xff00)
                    l_y=bit32.band(y,0xff00)
                    l_z=z
                    addU16(f,l_x)
                    addU16(f,l_y)
                    addU8(f,l_z)
                end
                startNode(f,OTBM_TILE)
                addU8(f,bit32.band(x,0xff))
                addU8(f,bit32.band(y,0xff))
            
                for stackpos=0,10 do
                    local pos = {x=x,y=y,z=z,stackpos=stackpos}
                    local thing = getTileThingByPos(pos)
                
                    if (thing.itemid==0 and stackpos==0) then --no tile, so we can skip it
                        break
                    end
                
                    local newItem = conversion[thing.itemid]

                    if newItem then
                        local tilePos = {x=x,y=y,z=z,stackpos=0}
                        local tile = getTileThingByPos(tilePos)
                        if newItem.tile then
                            if newItem.tile == tile.itemid then
                                doRemoveItem(thing.uid,1)
                                doTransformItem(tile.uid,newItem.id)
                                thing = getTileThingByPos(tilePos)
                            else
                                doTransformItem(thing.uid,newItem.id)
                                thing = getTileThingByPos(pos)
                            end
                        elseif newItem.border == true then
                            doRemoveItem(thing.uid,1)
                            doTransformItem(tile.uid,newItem.id)
                            thing = getTileThingByPos(tilePos)
                        else
                            doTransformItem(thing.uid,newItem.id)
                            thing = getTileThingByPos(pos)
                        end
                    end
                
                    newItem = nil

                    if thing.itemid > 99 and thing.itemid < 5090 and stackpos ~= 253 then --TODO: save item counts, save containers
                        addByte(f,OTBM_ATTR_ITEM)
                        addU16(f,thing.itemid)
                    end
                end
                endNode(f)

            end
        end
    end
    if not first then
        endNode(f)
    end
    endNode(f)
    endNode(f)
    f:close()
    print(startconversion)
    print(">> - Conversion ended: " ..os.date("%d %b %Y %X", (os.time())))
end
 
Last edited:
Mkalo: "@Peonso Don't use ".." to concatenate stuff
Code:
function lchar(i) s="" while i>0 do s=s..string.char(i%256) i=math.floor(i/256) end return s end

function format(s,size)
    local len = #s
 
    for x=1,size/8-len do
        s=s.."\0"
    end
 
    return s
end

here
i bet this is making your script 50% or more
slower

use a buffer
local buffer = {}
insert everything there
and at the end
table.concat(buffer)
and don't use table.insert
to insert
use a var
local size = #buffer
buffer[size+1] = "something"
size = size + 1

Code:
Stream = {}
setmetatable(Stream, {__call =
    function(_, ...)
        local args = {...}
        local strtab = {}
        local size = 1
        for i = 1, #args do
            if type(args[i]) == "string" then
                strtab[size + 1] = args[i]
                size = size + 1
            elseif type(args[i]) == "table" and args[i].strtab then
                for s = 1, #args[i].strtab do
                    strtab[size + 1] = args[i].strtab[s]
                    size = size + 1
                end
            end
        end

        return setmetatable({strtab = strtab}, {__index = Stream, __concat =
            function(self, str)
                local size = #self.strtab
                if type(str) == "string" or type(str) == "number" then
                    self.strtab[size + 1] = str
                    size = size + 1
                elseif type(str) == "table" and str.strtab then
                    for s = 1, #str.strtab do
                        self.strtab[size + 1] = str.strtab[s]
                        size = size + 1
                    end
                end
                return self
            end
        })
    end
})

function Stream:str()
    return table.concat(self.strtab)
end

local buffer = Stream()
local n = 1000000
for i = 1, n do
    buffer = buffer .. tostring(i)
end

local a = buffer:str()
print(os.clock())

use this

or nah
you want efficiency
probably better just doing the table thing
this is going to call too many functions

but the concept is easy
you will have a table for everything
and in the end you concat it all
using table.concat"


Ninja: " Also don't do the following thing inside long iterations as it's extremely slow:
Code:
local pos = {x = x, y = y, z = z, stackpos = stackpos}
I suggest you do something like this instead
Code:
local pos = {x = 0, y = 0, z = 0, stackpos = 0} -- Declare outside the for loops

-- Inside the loop
pos.x, pos.y, pos.z, pos.stackpos = someX, someY, someZ, someStackpos
"


Mkalo: "also you should be able to reduce the number of io.write calls
idk if this matters or not
tho
it probably has some kind of buffer implemented
probably not relevant"


@Shyzoul
 
Back
Top