• Surface library draws matrix as string in one line
    4 replies, posted
Hi, I wanted to display a 4x4 matrix using the surface library but printed it out on one line. I am using the flowing code: local m = Matrix() surfaceDrawText(tostring(m)) -- Prints on the screen: [0,0,0,0][0,0,0,0][0,0,0,0][0,0,0,0] print(tostring(m)) -- Prints this in the console: -- [0,0,0,0] -- [0,0,0,0] -- [0,0,0,0] -- [0,0,0,0] It seems that the surface library skips the new lines. How can draw the matrix with new line on the screen ?
surface.DrawText doesn't like newlines. You'd have to split the string into a table and draw each line seperately.
Exactly what I thought ... kinda unexpected because other APIs like "\n". Thanks !
There's draw.DrawText that will look for new lines tho
    ["MTX"] = function(scr, key, typ, inf, def, spn)       local fmt = asmlib.GetOpVar("FORM_DRAWDBG")       local tab = spn[key]:ToTable()       local fky = tostring(def.Draw[1] or "%s")       for iR = 1, 4 do         local out = "{"..tostring(iR).."}["..tableConcat(tab[iR], ",").."]"         scr:DrawText(fmt:format(fky:format(key), typ, out, inf))       end     end Mehh, ho lazy just convert tha matrix to a table and format every row . It will be more robust instead of braking it on "\n".
Sorry, you need to Log In to post a reply to this thread.