Suggestion to refactor this
Posted: Mon Sep 18, 2017 2:59 pm
Is there a better way to refactor this. Ive got the following line:
In modules/player.lua. I’ve got:
Basically health, mana, health_pool, and mana_pool are attributes dependent on the class type (ie. wizard or warrior)
Code: Select all
player = require('modules/player')('wizard')
Code: Select all
function health(class)
if class == 'wizard' then
return 80
elseif class == 'warrior' then
return 100
end
end
function mana(class)
if class == 'wizard' then
return 100
elseif class == 'warrior' then
return 80
end
end
function healthPool(class)
if class == 'wizard' then
return 80
elseif class == 'warrior' then
return 100
end
end
function manaPool(class)
if class == 'wizard' then
return 100
elseif class == 'warrior' then
return 80
end
end
return function(class)
speed = 100,
x = 50,
y = 50,
health = health(class),
mana = mana(class),
health_pool = healthPool(class),
mana_pool = manaPool(class)
}
end