In my code below, I can't get performActivity method to increase character happiness. Because 'need' comes as a string with the value "happiness" whereas I need to make changes on "happiness" which is a class instance. I'd appreciate any help!
// Character Needs Class
class CharNeeds {
var currentNeedValue : Int = 0
func changeNeedValue (changeBy : Int){
currentNeedValue += changeBy
}
}
// Activities Class
class Activities{
let activityName : String
var effects = [String: Int]()
//Initializers
init(activityName: String, effects: [String: Int]){
self.activityName = "Unnamed Activity"
self.effects = effects
}
//Methods
static func performActivity(activityName : Activities){
for (need, effect) in activityName.effects {
need.changeNeedValue(changeBy: effect)
}
}
}
//Testing
var happiness = CharNeeds()
var cycling = Activities(activityName: "cycling", effects: ["happiness":10])
Activities.performActivity(activityName: cycling)