Wrench 2000

[QUESTION] What wrong in this script?

Recommended Posts

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!

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post

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

Share this post


Link to post
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?

Share this post


Link to post

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

Share this post


Link to post
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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.