Jump to content

getElementData or "something"


tommymaster

Recommended Posts

Hi! For example if in my script i use getElementData or just simply call something that's value is either nil or false, how can i use the or? I mean outputChatBox ("player's element data" or "no data") And the "no data" would only get put in the chatbox if the element's  specified data is nil or false? I have seen this in scripts, but i never knew it's usage. 

Edited by tommymaster
Link to comment

I guess something like this would work....

function someFuntion()
    local theData = getElementData(source, "data_name") --First we get the data
    if theData ~= false then --If the data is not equal (~=) to false
        outputChatBox("data = "..theData, source) --We output a message to the source, adding the data value to the string
    else
        outputChatBox("Data was not found.", source) --Otherwise we tell the player data was not found.
    end
end

addEventHandler("onPlayerLogin", getRootElement(), someFunction) --When player logs in, function is triggered

You get the data first, then you check it in the if, if it's there, output it to the chat, if not, say it's not there, keep in mind, you might need to use tostring when adding the data to chat message, so it might look like...  outputChatBox("data = "..tostring(theData), source) where the data is in the brackets...

Hope this helped you. :D

Edited by kieran
Apparently I can't type getElementData these days...
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...