Jump to content

Solved


1LoL1

Recommended Posts

Hello, is possible 3x getElementData in 1x getElementData? i mean this:

local r = getElementData(source, "r") 
local g = getElementData(source, "g") 
local b = getElementData(source, "b") 
local all = getElementData(source, "all", r, g, b)  

When i go this i have this Error: Bad argument @ 'getElementData' [Expected bool at argument 3, got number '0'].

Edited by Guest
Link to comment
  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Yes, you just have to save the table in there like so;
setElementData ( source, "all", { r, g, b } ); 

later on you can use;

local all = getElementData ( source, "all" ); 
local r, g, b = unpack ( all ); 

When i want use getElementData i have this warning:

Bad argument @ 'getElementData' [Expected bool at argument 3, got number '0']

local all = getElementData(source, "all") 
local r, g, b = unpack(all) 
local wtf = r, g, b 
local ttt = getElementData(source, "all", wtf) 

Link to comment

ok i have now this:

setElementData(player, "all", ""..r..", "..g..", "..b.."") -- Work 

and this too:

local all = getElementData(source, "all") -- Work 

and here too:

local all = getElementData(player, "all")  
local r, g, b = unpack(tostring(all)) 
setVehicleHeadLightColor(source, r, g, b) 

Link to comment
local all = getElementData(source, "all") 
local r, g, b = unpack(all) 
local wtf = r, g, b 
local ttt = getElementData(source, "all", wtf) 

That error you got: Bad argument @ 'getElementData' [Expected bool at argument 3, got number '0']

That was because of your last line 'getElementData', getElementData only needs the element and the data. (source and "all")

Where you do have to use 3 parameters are with SET (setElementData(source, "all", colors)

For example;

addEventHandler("onMarkerHit", markerName, function() 
     local r, g, b = getVehicleColor(vehicle, true) 
     setElementData(vehicle, "color", {r, g, b}) 
end) 
  
-- and later on 
addEventHandler("onMarkerHit", marker2Name, function() 
     local x, y, z = unpack(getElementData(vehicle, "color") 
     setVehicleColor(vehicle, x, y, z) 
end) 

If i'm right at least, btw it's just a random example.

Link to comment
local all = getElementData(source, "all") 
local r, g, b = unpack(all) 
local wtf = r, g, b 
local ttt = getElementData(source, "all", wtf) 

That error you got: Bad argument @ 'getElementData' [Expected bool at argument 3, got number '0']

That was because of your last line 'getElementData', getElementData only needs the element and the data. (source and "all")

Where you do have to use 3 parameters are with SET (setElementData(source, "all", colors)

For example;

addEventHandler("onMarkerHit", markerName, function() 
     local r, g, b = getVehicleColor(vehicle, true) 
     setElementData(vehicle, "color", {r, g, b}) 
end) 
  
-- and later on 
addEventHandler("onMarkerHit", marker2Name, function() 
     local x, y, z = unpack(getElementData(vehicle, "color") 
     setVehicleColor(vehicle, x, y, z) 
end) 

If i'm right at least, btw it's just a random example.

Not work :/

Bad argument #1 to 'unpack' (table expected, got string)

i think i need this

local r, g, b = {r, g, b} 

Link to comment
Show us your code that's the way we can help. I think the problem will be somewhere around your r,g,b declaration/setElementData.

Don't needed full code can be this:

  
setElementData(sorce, "all", r,g,b) 
  
addEventHandler("onVehicleEnter", getRootElement(), 
function (player) 
    local r, g, b = getElementData(player, "all") 
    local r, g, b = unpack(r, g, b) 
    setVehicleHeadLightColor(source, r, g, b) 
    end 
end) 
  

Link to comment
setElementData(sorce, "all", r,g,b) -- this has to be source instead of sorce probably 
  
addEventHandler("onVehicleEnter", getRootElement(), 
function (player) 
    local colors = getElementData(player, "all") -- by calling it r, g, b you use 3 variables but the table only needs 1 
    local r, g, b = unpack(colors) -- here you go from 1 table to 3 variables 
    setVehicleHeadLightColor(source, r, g, b) 
end) 

If this doesn't work, let me see the setElementData function because I don't know what the source is right now.

Link to comment
Who's "source" or "sorce"

and setElementData(sorce, "all", r,g,b)

should be setElementData(sorce, "all", {r,g,b})

Yeah I looked over the table in setElementData

setElementData(source, "all", {r,g,b}) -- this has to be source instead of sorce probably 
  
addEventHandler("onVehicleEnter", getRootElement(), 
function (player) 
    local colors = getElementData(player, "all") -- by calling it r, g, b you use 3 variables but the table only needs 1 
    local r, g, b = unpack(colors) -- here you go from 1 table to 3 variables 
    setVehicleHeadLightColor(source, r, g, b) 
end) 

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