Jump to content

setElementData


Z4Zy

Recommended Posts

Hi Friends !^_^

Again, I've fall into a big hole :S. So, I'm requesting you to help me to come outside this hole by answering this problem :signhelp:.

The problem is mentioned below,

            We use 'setElementData' to store some data in a element like below,

local marker = createMarker(0,0,5,"cylinder",1.5,255,255,0,255)

addEventHandler("onMarkerHit", marker,
  function (hitter)
    setElementData(hitter,"isInsideMarker","yes")
  end
)

addEventHandler("onMarkerLeave", marker,
  function (leaver)
    setElementData(leaver,"isInsideMarker","no")
  end
)

as you can see, when element hit the marker, we set it's data called "isInsideMarker", the value "yes". when leave, element's data "isInsideMarker" set to the value "no". Simple idea ! So, in this occasion, "isInsideMarker" data gets only the value "yes" and "no". It successfully store only one value at one time. So, my problem is, how to store multiple values set in one element's data ? [ it may be using a table or ..ect ] can you describe me how to store multiple values in one element data ?

Link to comment
3 hours ago, Dimos7 said:

Bro, what is the relationship between 'isElementWithinMarker' and 'setElementData' ?:violent1:  I want to insert multiple values to one key of an element's data. Marker code is only an example use to describe problem.

Think we create a script like this, 

There are some markers that we have created. When an element / player hit a marker, his key called "hitMarkers" will be added new value.

local a = createMarker(bla,bla,bla)
local b = createMarker(bla,bla,bla)
local c = createMarker(bla,bla,bla)

addEventHandler("onMarkerHit", root,
function (player)
   if (source == a) then
      setElementData(player,"hitMarkers","a") -- on hit marker a set Value to "a"
   elseif (source == b) then
      setElementData(player,"hitMarkers",????) -- if I write this line as setElementData(player,"hitMarkers","b"), it will remove the current value and replace new value. How to add "b" without remove previous value ?
   end
)

 

Edited by DeadthStrock
Link to comment
  • Moderators

Using JSON as Dimos7 said.

 

Or just use directly a table:

do -- set
	local theTable = {a = 100}
	setElementData(player, "hitMarkers", theTable)
end


do -- update
	local theTable = getElementData(player, "hitMarkers")
	theTable.b = 200
	setElementData(player, "hitMarkers", theTable)
end


do -- debug
	local theTable = getElementData(player, "hitMarkers")
	iprint(theTable)
end

 

Information about what is allowed inside of this table.

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