Wumbaloo Posted August 25, 2015 Share Posted August 25, 2015 Hey, i have this code, of the example in the dxDrawCircle wiki page: local screenWidth, screenHeight = guiGetScreenSize( ) local stopAngle = 0 addEventHandler( "onClientRender", root, function( ) if ( stopAngle < 360 ) then stopAngle = stopAngle + 5 else stopAngle = 0 end dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, stopAngle ) end ) And it return me "attempt to call global 'dxDrawCircle' (a nil value)" i don't understand why Link to comment
t3wz Posted August 25, 2015 Share Posted August 25, 2015 dxDrawCircle is an useful function so you need to define it in the script. function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end Link to comment
MAB Posted August 25, 2015 Share Posted August 25, 2015 all useful functions needs its codes because useful functions aren't MTA functions they are scripted by normal scripters Link to comment
Wumbaloo Posted August 26, 2015 Author Share Posted August 26, 2015 But don't work when i do this: local x, y = guiGetScreenSize() red = tocolor(255, 0, 0) dxDrawCircle(x/2, y/2, 50, 5, 1, 0, 360, red, true) Link to comment
Moderators Citizen Posted August 26, 2015 Moderators Share Posted August 26, 2015 But don't work when i do this: local x, y = guiGetScreenSize() red = tocolor(255, 0, 0) dxDrawCircle(x/2, y/2, 50, 5, 1, 0, 360, red, true) Any error on the client-side ? In general if you have this error: attempt to call global 'functionNameHere' (a nil value) Then it means that the function doesn't exist or is not defined yet. Make sure you have copied and pasted the dxDrawCircle function at the right place. Link to comment
Wumbaloo Posted August 26, 2015 Author Share Posted August 26, 2015 No errors local x, y = guiGetScreenSize() red = tocolor(255, 0, 0) [function] if rand == 0 then text = "lui prend la jambe et la mord" addEventHandler("onClientRender", root, function () dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) end) end function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end Link to comment
MAB Posted August 26, 2015 Share Posted August 26, 2015 No errors local x, y = guiGetScreenSize() red = tocolor(255, 0, 0) [function] if rand == 0 then text = "lui prend la jambe et la mord" addEventHandler("onClientRender", root, function () dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) end) end function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end -___- function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end -- now put your things here ._. Link to comment
TAPL Posted August 26, 2015 Share Posted August 26, 2015 No errors local x, y = guiGetScreenSize() red = tocolor(255, 0, 0) [function] if rand == 0 then text = "lui prend la jambe et la mord" addEventHandler("onClientRender", root, function () dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) end) end function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end How about not lying? Link to comment
Wumbaloo Posted August 26, 2015 Author Share Posted August 26, 2015 of course michaelmir i did that, no error in game but not working Link to comment
KariiiM Posted August 26, 2015 Share Posted August 26, 2015 No errors [function] ---- end This have no sense and will cause errors Link to comment
Wumbaloo Posted August 26, 2015 Author Share Posted August 26, 2015 You don't understand me, look at my code: local x, y = guiGetScreenSize() red = tocolor(255, 0, 0) function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end function abc(source) local rand = math.random(0, 6) if rand == 0 then addEventHandler("onClientRender", root, function () dxDrawCircle( x/2, y/2) end) else addEventHandler("onClientRender", root, function () dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) end) end end Link to comment
Moderators Citizen Posted August 27, 2015 Moderators Share Posted August 27, 2015 That code works just fine: and Please make sure you did everything correctly before saying it doesn't work. Most of the scripters here do not test the scripts, they are guessing the problem and the solutions using what the original poster says and their knowledges. As I can see you are french, if you prefer, you can ask for help in french in the French subforum. I saw you were kinda angry because you didn't get a reply in time because I'm kinda alone in that section and I was away from home. I always watch that French section and I get an email notification for each thread created in that section. I hope to see you again there: viewforum.php?f=128 Best regards, Citizen Link to comment
Wumbaloo Posted August 27, 2015 Author Share Posted August 27, 2015 wtf it don't work for me, i test all my code.. Link to comment
Wumbaloo Posted August 27, 2015 Author Share Posted August 27, 2015 it work, finally, thanks. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now