NoviceWithManyProblems Posted January 25, 2020 Share Posted January 25, 2020 table = --[[...]]("SELECT * FROM table") for i, v in pairs(table) do marker = createMarker(...) setElementData(marker, "unique_id", v.id) end Element data to all marker it's always last I want his id to be displayed after entering the marker, but always the highest record is displayed, e.g. 5 yes, id from database is correct Link to comment
Moderators Patrick Posted January 25, 2020 Moderators Share Posted January 25, 2020 This part of the code isn't wrong, more info is needed about the script. Link to comment
NoviceWithManyProblems Posted January 25, 2020 Author Share Posted January 25, 2020 6 minutes ago, stPatrick said: This part of the code isn't wrong, more info is needed about the script. function func1() outputChatBox(tostring(getElementData(picint, "unique_id"))) end addEventHandler("onMarkerHit", marker, func1, false) in the database, each new marker has an id greater by 1 it displays the largest record in the database instead of displaying the correct id connected to the marker Link to comment
Moderators Patrick Posted January 25, 2020 Moderators Share Posted January 25, 2020 1 minute ago, NoviceWithManyProblems said: function func1() outputChatBox(tostring(getElementData(picint, "unique_id"))) end addEventHandler("onMarkerHit", marker, func1, false) in the database, each new marker has an id greater by 1 it displays the largest record in the database instead of displaying the correct id connected to the marker I think the problem is similar to a previous one Link to comment
NoviceWithManyProblems Posted January 25, 2020 Author Share Posted January 25, 2020 that's look how I want to it to work Link to comment
Moderators Patrick Posted January 25, 2020 Moderators Share Posted January 25, 2020 (edited) Okay, i see In the for loop you define a global marker variable what you overwrite every time until the for loop is running. So, when the loop ends, the marker variable is still alive, whats the last marker's element. In the onMarkerHit event you print the unique_id of this element. You need to replace it to source. function func1() outputChatBox(tostring(getElementData(source, "unique_id"))) end addEventHandler("onMarkerHit", marker, func1, false) btw, nice drawing xd Edited January 25, 2020 by stPatrick Link to comment
NoviceWithManyProblems Posted January 25, 2020 Author Share Posted January 25, 2020 2 minutes ago, stPatrick said: Okay, i see In the for loop you define a global marker variable what you overwrite every time until the for loop is running. So, when the loop ends, the marker variable is still alive, whats the last marker's element. In the onMarkerHit event you print the unique_id of this element. You need to replace it to source. function func1() outputChatBox(tostring(getElementData(source, "unique_id"))) end addEventHandler("onMarkerHit", marker, func1, false) btw, nice drawing xd Thanks. It's possible to do this with pickup? Link to comment
Moderators Patrick Posted January 25, 2020 Moderators Share Posted January 25, 2020 1 minute ago, NoviceWithManyProblems said: Thanks. It's possible to do this with pickup? Maybe, but you need to cancel the event. -- SERVER local pickup = createPickup(...) setElementData(pickup, "unique_id", 1) addEventHandler("onPlayerPickupHit", pickup, function() cancelEvent() -- cancel the event ==> the player can't pickup this "pickup" :D outputChatBox(getElementData(source, "unique_id")) end) 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