Jump to content

dxDrawRectangle failing


.:HyPeX:.

Recommended Posts

how can this return "Error, expected number at argument 2, returned none"

  
dxDrawRectangle(v) 
  

But outputChatbox(v) returns:

0.14191175997257 * x, 0.15364582836628 * y,( 0.37794119119644 * x ) - ( 0.14191175997257 * x ), ( 0.62109375 * y - 0.15364582836628 * y ), -1275068416 

Link to comment
How can outputChatBox return that? and if it does, then 'v' is a string.

This is basically the add, how could it NOT be a string?

  
table.insert(DrawStringTable,CursorTable.X1.." * x, "..CursorTable.Y1.." * y,( "..EndX.." * x ) - ( "..CursorTable.X1.." * x ), ( "..EndY.." * y - "..CursorTable.Y1.." * y ), "..color) 

Link to comment

Just like SN said, this is how it looks like:

dxDrawRectangle (" 1.0.14191175997257 * x, 0.15364582836628 * y,( 0.37794119119644 * x ) - ( 0.14191175997257 * x ), ( 0.62109375 * y - 0.15364582836628 * y ), -1275068416" )  
  

Do you really think this will work with quotation marks ? :)

Link to comment

use string.split to get arguments from a string.

function string.split(s,d) 
   local t = {} 
   local i = 0 
   local f 
   local match = '(.-)' .. d .. '()' 
   if string.find(s, d) == nil then 
      return {s} 
   end 
   for sub, j in string.gfind(s, match) do 
         i = i + 1 
         t[i] = sub 
         f = j 
   end 
   if i~= 0 then 
      t[i+1]=string.sub(s,f) 
   end 
   return t 
end 

An example:

local str = "a,b,c" 
local vals = string.split(str,",") 
for i,v in ipairs(vals) do 
  outputChatBox(v) 
end 

You also need to tonumber the arguments to get your desired values. But this method... Oh gosh, someone, throw his keyboard out :D

Link to comment

Try removing quotation marks with this:

function escapeCSV (s) 
      if string.find(s, '[,"]') then 
        s =  string.gsub(s, '"', '""') 
      end 
      return s 
    end 
  

I still doubt this will work but anyway if this doesn't work then you can use galladros code.

Link to comment
use string.split to get arguments from a string.
function string.split(s,d) 
   local t = {} 
   local i = 0 
   local f 
   local match = '(.-)' .. d .. '()' 
   if string.find(s, d) == nil then 
      return {s} 
   end 
   for sub, j in string.gfind(s, match) do 
         i = i + 1 
         t[i] = sub 
         f = j 
   end 
   if i~= 0 then 
      t[i+1]=string.sub(s,f) 
   end 
   return t 
end 

An example:

local str = "a,b,c" 
local vals = string.split(str,",") 
for i,v in ipairs(vals) do 
  outputChatBox(v) 
end 

You also need to tonumber the arguments to get your desired values. But this method... Oh gosh, someone, throw his keyboard out :D

i dont understand what str = "a,b,c" does.

Link to comment
use string.split to get arguments from a string.
function string.split(s,d) 
   local t = {} 
   local i = 0 
   local f 
   local match = '(.-)' .. d .. '()' 
   if string.find(s, d) == nil then 
      return {s} 
   end 
   for sub, j in string.gfind(s, match) do 
         i = i + 1 
         t[i] = sub 
         f = j 
   end 
   if i~= 0 then 
      t[i+1]=string.sub(s,f) 
   end 
   return t 
end 

An example:

local str = "a,b,c" 
local vals = string.split(str,",") 
for i,v in ipairs(vals) do 
  outputChatBox(v) 
end 

You also need to tonumber the arguments to get your desired values. But this method... Oh gosh, someone, throw his keyboard out

i dont understand what str = "a,b,c" does.

Its just an example. Suppose ab is a string and has commas so we need to split the values from the string so we'll use split function.

local ab = "x * 0.3, y +1,x*y + 5, z - 12"  
local vals = string.split(str,",") 
for i,v in ipairs(vals) do 
  outputChatBox(v) 
end 

Test it and you'll see.

Link to comment
unpack 

Tried this, but nothing is drawn.

function DrawTableString() 
local x,y = guiGetScreenSize() 
for i,v in ipairs(DrawStringTable) do 
local str = v 
local vals = string.split(str,",") 
local a,b,c,d,e = unpack(vals) 
dxDrawRectangle(a,b,c,d,e) 
outputChatBox(a..","..b..","..c..","..d..","..e) 
end 
end 
addEventHandler("onClientRender", getRootElement(), DrawTableString) 

Output:

  
0.19117647409439 * x, 0.15885417163372 * y,( 0.64191174507141 * x ) - ( 0.19117647409439 * x ), ( 0.421875 * y - 0.15885417163372 * y ), -1275068416 

PD: no errors in debug

Link to comment
function DrawTableString ( ) 
    local x,y = guiGetScreenSize ( ) 
    for _, v in ipairs ( DrawStringTable ) do 
        local vals = { } 
        for _, value in ipairs ( string.split ( v, "," ) ) do 
            table.insert ( vals, tonumber ( value ) ) 
        end 
        dxDrawRectangle ( unpack ( vals ) ) 
    end 
end 
addEventHandler ( "onClientRender", getRootElement(), DrawTableString ) 

P.S: Why are you using a custom function to split it? MTA has "split" function which does the same.

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