Jump to content

Solved


1LoL1

Recommended Posts

Posted (edited)

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
  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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 ); 

Posted
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) 

Posted

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) 

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

Posted
Use
toJSON  
fromJSON 

He don't need to

set/get-Elementdata does store tables unlike set/get-accountData

ViRuZGamiing example is what he should do, btw there's a missing ")" on line 8

Posted
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} 

Posted
did you Add the missing ')' on line 8? that was my bad

Yes it is added.

Where's your full code? we cant help you without your code

Don't needed full code.. i want only example how i can 3x getElementData in 1x getElementData.

Posted
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) 
  

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

Posted
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) 

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