Jump to content

How can I add unique element data for object from table?


Recommended Posts

Posted
    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

Posted
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

  • Moderators
Posted
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

 

  • Moderators
Posted (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 by stPatrick
Posted
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?

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

 

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