Add check for nil XP value

This commit is contained in:
Austin Shenk 2013-07-01 22:04:06 -04:00
parent 1b97fec405
commit 545bed2e09
1 changed files with 5 additions and 3 deletions

8
xp.lua
View File

@ -29,17 +29,19 @@ end
--Table Modification --Table Modification
specialties.changeXP = function(name, specialty, amount) specialties.changeXP = function(name, specialty, amount)
local newAmount = specialties.players[name].skills[specialty]+amount local current = specialties.players[name].skills[specialty]
if current == nil then current = 0 end
local newAmount = current+amount
if newAmount >= 0 then if newAmount >= 0 then
specialties.players[name].skills[specialty] = newAmount specialties.players[name].skills[specialty] = newAmount
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
local id = specialties.players[name].menu[specialty] local id = specialties.players[name].hud[specialty]
local hudItem = player:hud_get(id) local hudItem = player:hud_get(id)
hudItem.text = tostring(newAmount) hudItem.text = tostring(newAmount)
hudItem.offset = {x=100, y=0} hudItem.offset = {x=100, y=0}
hudItem.alignment = {x=1, y=0} hudItem.alignment = {x=1, y=0}
player:hud_remove(id) player:hud_remove(id)
specialties.players[name].menu[specialty] = player:hud_add(hudItem) specialties.players[name].hud[specialty] = player:hud_add(hudItem)
return true return true
else else
return false return false