I'm making a simple RPG as a learning project, and am having an issue with part of the character creator.
This code should determine what skill string is assigned to player[:caste][:skill]
and player[:sub][:skill]
, then increase each respective skill's value in player[:skills]
by 2. This code should work regardless of what string is assigned to player[:caste][:skill]
and player[:sub][:skill]
, as long as it is equal to player[:skills].to_s
.
Currently, it is only applying the change to player[:skills][:endurance]
but not player[:skills][:athletics]
.
player = {
caste: {skill: "athletics"},
sub: {skill: "endurance"},
skills: {acrobatics: 0, athletics: 0, engineering: 0, endurance: 0, heal: 0, history: 0, influence: 0, insight: 0, magicka: 0, perception: 0, riding: 0, stealth: 0, streetwise: 0, thievery: 0},
}
player[:skills] = player[:skills].map do |skill, mod|
[skill, (mod += 2 if skill.to_s == player[:caste][:skill])]
[skill, (mod += 2 if skill.to_s == player[:sub][:skill])]
end.to_h
In other words, my code is returning the following player[:skills]
hash:
skills: {acrobatics: 0, athletics: 0, engineering: 0, endurance: 2, heal: 0, history: 0, influence: 0, insight: 0, magicka: 0, perception: 0, riding: 0, stealth: 0, streetwise: 0, thievery: 0}
but I want it to return:
skills: {acrobatics: 0, athletics: 2, engineering: 0, endurance: 2, heal: 0, history: 0, influence: 0, insight: 0, magicka: 0, perception: 0, riding: 0, stealth: 0, streetwise: 0, thievery: 0}
Please let me know if there is a simpler way to do this. I've also tried the following:
player[:skills] = player[:skills].map do |skill, mod|
[skill, (mod += 2 if skill.to_s == (player[:caste][:skill] || player[:sub][:skill]))]
end.to_h
which only affects the skill found in player[:caste][:skill]
.