Hai, I’m Kai! Totally new to Elixir here, and gave up coding in other languages for so long now I’m practically new to programming as a whole again. I’ve been using Joy of Elixir as an introduction, and I don’t feel like I’m banging my head against a brick wall so far, so that’s a plus!
However, I did this silly thing here to test my understanding of cond statements, and I’m stumped as to why it doesn’t work.
ffan = %{
name: "Kff'annin",
current_hp: 240,
max_hp: 4080,
current_energy: 500,
max_energy: 720,
current_will: 720,
max_will: 720,
is_mob: false,
fav_ice_cream_flavor: "Cotton Candy Bubble Gum",
}
alter_hp = fn(name,current_hp,max_hp,ficf,hp_effect) ->
cond do
hp_effect > 0 ->
if current_hp < max_hp do
current_hp = current_hp + hp_effect
IO.puts "#{name} was healed for #{hp_effect} HP. #{name}'s HP is now #{current_hp}."
else
IO.puts "#{name}'s HP is already at its maximum, #{max_hp}."
end
hp_effect < 0 ->
if current_hp > 0 do
current_hp = current_hp + hp_effect
IO.puts "#{name} was hurt for #{hp_effect} HP. #{name}'s HP is now #{current_hp}."
else
IO.puts "#{name} is already defeated! Could you spare some #{ficf} ice cream for their recovery?"
end
hp_effect == 0 ->
IO.puts "No effect on #{name}'s HP. It is currently #{current_hp}."
end
end
alter_hp(ffan.name,ffan.current_hp,ffan.max_hp,ffan.fav_ice_cream_flavor,82)
When attempting to run it, I get an error telling me that function alter_hp is undefined…but it clearly, obviously is defined right above the call! I combed through said function about five times too, looking for stuff like syntax goofs or missing end-statement closures, but it all looks fine to me. What am I missing here?
Also, is there a better place to be an annoying beginner programmer than this?