tommymaster Posted January 28, 2018 Share Posted January 28, 2018 (edited) 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 January 28, 2018 by tommymaster Link to comment
kieran Posted January 28, 2018 Share Posted January 28, 2018 (edited) 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. Edited January 28, 2018 by kieran Apparently I can't type getElementData these days... Link to comment
Bonsai Posted January 28, 2018 Share Posted January 28, 2018 This should work too: a = b < 0 and 'negative' or 'positive' Link to comment
NeXuS™ Posted January 28, 2018 Share Posted January 28, 2018 You could just simply. outputChatBox("Player's data: " .. (getElementData(localPlayer, "elementData") or "not found") .. ".") 1 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