Z4Zy Posted June 30, 2018 Share Posted June 30, 2018 Hi Friends ! Again, I've fall into a big hole . So, I'm requesting you to help me to come outside this hole by answering this problem . 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
Dimos7 Posted June 30, 2018 Share Posted June 30, 2018 isElementWithinMarker Use this Link to comment
Z4Zy Posted June 30, 2018 Author Share Posted June 30, 2018 (edited) 3 hours ago, Dimos7 said: isElementWithinMarker Use this Bro, what is the relationship between 'isElementWithinMarker' and 'setElementData' ? 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 June 30, 2018 by DeadthStrock Link to comment
Dimos7 Posted June 30, 2018 Share Posted June 30, 2018 then use toJSON function and store them as table Link to comment
Moderators IIYAMA Posted July 1, 2018 Moderators Share Posted July 1, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now