Jump to content

Incrementing in setElementData with no additional variable ?


crismar

Recommended Posts

I've seen in some scripts some sort of:

setElementData(thePlayer, "Thingy", +1) 

Tried that but didn't get it to work, is it possible or I just have a bad memory ? At the moment I'm using an additional variable to store the oldValue with getElementData then do setElementData(thePlayer, "Thingy", oldValue + 1)

Ideas ? :shock:

Link to comment
  
local oldValue = tonumber (getElementData(thePlayer, "Thingy") ) 
if type (oldValue) == "number" then 
setElementData(thePlayer, "Thingy", oldValue + 1 ) 
end 
  

I don't see the point for if oldValue == "number" as you just made it a number on line before, also this works just fine aswell:

local oldValue = getElementData(thePlayer, "Thingy")  or 0 
setElementData(thePlayer, "Thingy", tonumber(oldValue) + 1 ) 
  

Link to comment
  
local oldValue = tonumber (getElementData(thePlayer, "Thingy") ) 
if type (oldValue) == "number" then 
setElementData(thePlayer, "Thingy", oldValue + 1 ) 
end 
  

I don't see the point for if oldValue == "number" as you just made it a number on line before, also this works just fine aswell:

local oldValue = getElementData(thePlayer, "Thingy")  or 0 
setElementData(thePlayer, "Thingy", tonumber(oldValue) + 1 ) 
  

Actually it is to check if the data was a number or not.

Link to comment
  
local oldValue = tonumber (getElementData(thePlayer, "Thingy") ) 
if type (oldValue) == "number" then 
setElementData(thePlayer, "Thingy", oldValue + 1 ) 
end 
  

I don't see the point for if oldValue == "number" as you just made it a number on line before, also this works just fine aswell:

local oldValue = getElementData(thePlayer, "Thingy")  or 0 
setElementData(thePlayer, "Thingy", tonumber(oldValue) + 1 ) 
  

Actually it is to check if the data was a number or not.

Yes, I realized, but what I was saying was:

local oldValue = tonumber (getElementData(thePlayer, "Thingy") ) <-- You make it a number here with tonumber()

if type (oldValue) == "number" then <-- yet you check if it's a number if you just made it a number

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