Gladox114 1 Posted March 15, 2019 Share Posted March 15, 2019 When i am in the Lua section and want to use the string.format("%g",num) it works like it should but in my code drawtext not... I want to use gpu.set(x,y,string) but my problem is that i want sometime numbers as strings but i don't know how to convert them properly info who is wondering whats drawText() drawText(print, gpu proxy) is my function that prints something on my second screen with a second graphics card to multi-task Quote Link to post Share on other sites
0 Molinko 43 Posted March 15, 2019 Share Posted March 15, 2019 I would expect that you're somehow overwriting the string lib in your context.. I would recommend using a different variable name for your string value other than `string` as this will probably cause your error later when calling string.format on it.. The result of type(string) by default would normally result in "table" because `string` is a global Lua library. Quote Link to post Share on other sites
0 CptMercury 6 Posted March 15, 2019 Share Posted March 15, 2019 It would be helpful to see the entire code of drawText, not only lines 39 - 50, but I may have found your problem. It seem like you named your variable 'string', is that right? If so, you are either overriding the global string variable, if you declared 'string' as a public variable, or if you used local, your code is not actually looking for the global 'string' variable, but for your local one. So basically, either way you don't have access to the string functions. In oder to solve this, you should not name your variables after globally ones unless you don't need to have access to them. Ok, for your code, you want a program that does a gpu set using a string or a number as input? And if it is a string, you want to replace all \n with ""? Then this might help: local function set(str, gpuProxy) checkArg(1, str, "number", "string") checkArg(2, gpuProxy, "table") -- checkArg to ensure you don't have any false input -- but you don't really need it if type(str) == "number" then str = tostring(str) elseif type(str) == "string" then str = str:gsub("\n", "") end gpuProxy.set(x, y, str) end Quote Link to post Share on other sites
0 Gladox114 1 Posted March 15, 2019 Author Share Posted March 15, 2019 Quote Ok, for your code, you want a program that does a gpu set using a string or a number as input? And if it is a string, you want to replace all \n with ""? Yeah for now i just wanted to go a line down if the string contains "\n" in it. its cheap ik 27 minutes ago, CptMercury said: if type(str) == "number" then str = tonumber(str) I am not allowed to use numbers in gpu.set() but i want so i need to convert however the number to a string.tonumber() converts a string with a number like "10" in to a number like 10. The opposite what i need and i thought that string.format() does the opposite. Quote Link to post Share on other sites
0 CptMercury 6 Posted March 15, 2019 Share Posted March 15, 2019 Oh sorry, my bad, it's supposed to be tostring(str) Quote Link to post Share on other sites
0 Gladox114 1 Posted March 15, 2019 Author Share Posted March 15, 2019 Oh thx ^^ Quote Link to post Share on other sites
When i am in the Lua section and want to use the string.format("%g",num) it works like it should but in my code drawtext not...
I want to use gpu.set(x,y,string) but my problem is that i want sometime numbers as strings but i don't know how to convert them properly
info who is wondering whats drawText()
drawText(print, gpu proxy) is my function that prints something on my second screen with a second graphics card to multi-task
Link to post
Share on other sites