Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing the increment/decrement functions

The increment/decrement functions didn't work if the value didn't
exist, it will now initiate to 0 if that is the case.
  • Loading branch information...
commit 00c5d6ef3f25fb10b34bb45da078d8d48976912f 1 parent 5cb75ab
@GrahamRanson GrahamRanson authored
View
BIN  .DS_Store
Binary file not shown
View
10 corona/GGData.lua
@@ -284,9 +284,12 @@ function GGData:setIfLower( name, value )
end
--- Increments a value in this GGData object.
--- @param name The name of the value to increment. Must be a number.
+-- @param name The name of the value to increment. Must be a number. If it doesn't exist it will be set to 0 and then incremented.
-- @param amount The amount to increment. Optional, defaults to 1.
function GGData:increment( name, amount )
+ if not self[ name ] then
+ self:set( name, 0 )
+ end
if self[ name ] and type( self[ name ] ) == "number" then
self[ name ] = self[ name ] + ( amount or 1 )
self:storeIntegrityHash( name, value )
@@ -294,9 +297,12 @@ function GGData:increment( name, amount )
end
--- Decrements a value in this GGData object.
--- @param name The name of the value to decrement. Must be a number.
+-- @param name The name of the value to decrement. Must be a number. If it doesn't exist it will be set to 0 and then decremented.
-- @param amount The amount to decrement. Optional, defaults to 1.
function GGData:decrement( name, amount )
+ if not self[ name ] then
+ self:set( name, 0 )
+ end
if self[ name ] and type( self[ name ] ) == "number" then
self[ name ] = self[ name ] - ( amount or 1 )
self:storeIntegrityHash( name, value )
View
10 love/GGData.lua
@@ -213,18 +213,24 @@ function GGData:setIfLower( name, value )
end
--- Increments a value in this GGData object.
--- @param name The name of the value to increment. Must be a number.
+-- @param name The name of the value to increment. Must be a number. If it doesn't exist it will be set to 0 and then incremented.
-- @param amount The amount to increment. Optional, defaults to 1.
function GGData:increment( name, amount )
+ if not self[ name ] then
+ self:set( name, 0 )
+ end
if self[ name ] and type( self[ name ] ) == "number" then
self[ name ] = self[ name ] + ( amount or 1 )
end
end
--- Decrements a value in this GGData object.
--- @param name The name of the value to decrement. Must be a number.
+-- @param name The name of the value to decrement. Must be a number. If it doesn't exist it will be set to 0 and then decremented.
-- @param amount The amount to decrement. Optional, defaults to 1.
function GGData:decrement( name, amount )
+ if not self[ name ] then
+ self:set( name, 0 )
+ end
if self[ name ] and type( self[ name ] ) == "number" then
self[ name ] = self[ name ] - ( amount or 1 )
end
Please sign in to comment.
Something went wrong with that request. Please try again.