Jump to content

Problem with the unpack() function


Recommended Posts

Hello, I've a little problem with the lua unpack function.

This is my code :

-- CLIENT

local loginPanelPos = {
	["globalPanel"] = {0,0,557,400}
}
function showLoginPanel(  )
	a = guiCreateStaticImage( unpack(loginPanelPos["globalPanel"]), "LOGIN.png", false )
end

This is what I'm getting in /debugscript 3

Bad argument @guiCreateStaticImage [Expected number at argument 3, got boolean]

Edited by Gordon_G
Link to comment

For some reason it counts the "unpack(loginPanelPos["globalPanel"]" as one argument (doesn't unpack it) and that's why it gives the boolean error at arg3 (I think). Try this:

-- CLIENT

local loginPanelPos = {
	["globalPanel"] = {0,0,557,400}
}
function showLoginPanel(  )
	a = guiCreateStaticImage(loginPanelPos["globalPanel"][1], loginPanelPos["globalPanel"][2], loginPanelPos["globalPanel"][3], loginPanelPos["globalPanel"][4], "LOGIN.png", false)
end

 

Link to comment

You can't use unpack like that if you have other arguments coming after it.

local pos = {100, 200, 300}
setElementPosition(localPlayer, unpack(pos)) -- works
setElementPosition(localPlayer, unpack(pos), false) -- won't work

Nothing can come behind unpack()

So try one of these methods instead:

local x, y, w, h = unpack(loginPanelPos["globalPanel"])
guiCreateStaticImage(x, y, w, h, "LOGIN.png", false)
-- or
local pos = loginPanelPos["globalPanel"]
guiCreateStaticImage(pos[1], pos[2], pos[3], pos[4], "LOGIN.png", false)

I recommend the last one if you're doing it in a render because it is faster, performance wise.

Edited by Tails
  • Like 1
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...