Jump to content

[QUESTION] What wrong in this script?


Recommended Posts

Posted

i got this warning, and error:

"rC.lua:40: bad argument @ 'dxDrawImageSection' [Expected material at argument 9, got nil]" - This is the warning msg.. 
"sC.lua:6: attempt to index global 'WorldRadar' (a nil value)" - This is the error msg....

And code(s):

rC.lua:40: - 

	dxDrawImageSection(WorldRadar["monX"], WorldRadar["monY"], WorldRadar["width"], WorldRadar["height"], mapX + 50, mapY + 60, WorldRadar["width"]/zoom, WorldRadar["height"]/zoom, WorldRadar["Map"], 0, 0, 0, tocolor(255, 255, 255, 255))

---

and the sC:lua:6: -

Map = {}
Map["F11"] = false

function Map.start()
	MiniMap.start()
	WorldRadar.start()
end
Map.start()

function Map.draw()
	if Map["F11"] then return end
	MiniMap.draw()
end
addEventHandler("onClientRender", root, Map.draw)

function Map.stop()

end

What wrong? How to fix this problems? Thanks the help!

  • Moderators
Posted (edited)
WorldRadar

Doesn't contain a value. (which should contain a table)

 

You can check if WorldRadar does have a positive value, by writing it like this:

if WorldRadar then
  -- code that uses WorldRadar
end

This will stop the errors/warnings, but doesn't guarantee that the script will operate as pleased.

 

So make sure that:

WorldRadar

does contain a valid value.

Edited by IIYAMA

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
6 minutes ago, IIYAMA said:

WorldRadar

Doesn't contain a value. (which should contain a table)

 

You can check if WorldRadar does have a positive value, by writing it like this:


if WorldRadar then
  -- code that uses WorldRadar
end

This will stop the errors/warnings, but doesn't guarantee that the script will operate as pleased.

 

So make sure that:


WorldRadar

does exist.

the WorldRadar exist in a another file

WorldRadar = {}
WorldRadar["width"] = sX - 20
WorldRadar["height"] = sY - 20

WorldRadar["monX"] = math.floor(sX/2 - WorldRadar["width"]/2)
WorldRadar["monY"] = math.floor(sY/2 - WorldRadar["height"]/2)
WorldRadar.show = false

then why not working?

  • Moderators
Posted (edited)

Most likely it is because this file loads later than the file that is already using WorldRadar.

In short: You can't use something which hasn't been loaded yet.

 

To solve that problem, you can execute code after ALL the code has been loaded using the event: 'onClientResourceStart'. It is clientside right? (for serverside use onResourceStart)

function Map.start()
	MiniMap.start()
	WorldRadar.start()
end

addEventHandler("onClientResourceStart", resourceRoot,
function ()
	Map.start()
end)

 

Edited by IIYAMA
  • Like 1

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
4 minutes ago, IIYAMA said:

Most likely it is because this file loads later than the file that is already using WorldRadar.

In short: You can't use something which hasn't been loaded yet.

 

To solve that problem, you can execute code after ALL the code has been loaded using the event: 'onClientResourceStart'. It is clientside right? (for serverside use onResourceStart)


function Map.start()
	MiniMap.start()
	WorldRadar.start()
end

addEventHandler("onClientResourceStart", resourceRoot,
function ()
	Map.start()
end)

 

now i got this error: 

"attempt to index global 'Map' (a nil value)"

	dxDrawImageSection(WorldRadar["monX"], WorldRadar["monY"], WorldRadar["width"], WorldRadar["height"], mapX + 50, mapY + 60, WorldRadar["width"]/zoom, WorldRadar["height"]/zoom, WorldRadar["Map"], 0, 0, 0, tocolor(255, 255, 255, 255))



function WorldRadar.start()
	WorldRadar["Map"] = dxCreateTexture( "map.png")
	dxSetTextureEdge(WorldRadar["Map"], "border", tocolor(75,144,223))
end

what wrong in this?

  • Moderators
Posted

I do not see the variable >Map< in this code. You sure this is the right code that contains this error?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted (edited)
11 minutes ago, IIYAMA said:

I do not see the variable >Map< in this code. You sure this is the right code that contains this error?

Lol, now working :D thank you!:D

Edited by Wrench 2000
solved

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