From: "Sebastjan H." Date: 2012-08-03T07:38:38+09:00 Subject: Re: learning by doing part 2 - tc game I am back with another question. I am re-factoring the game and still trying to keep it simple, so bear with me. I've added effects to cards which are activated when played. In the main file I have this for each turn: ## The cards effects are activated (opponent sequence is random) players = [@hm_player, @ai_player] @opponent = players.sample if @opponent == @ai_player @own = @hm_player hm_card.effect @opponent = @hm_player @own = @ai_player ai_card.effect elsif @opponent == @hm_player @own = @ai_player ai_card.effect @opponent == @ai_player @own = @hm_player hm_card.effect else end ------------------------ Now, I wanted to keep it simple, so I have the dragon's effect defined as follows: def effect() @opponent.hp -= card.attack # I've just spotted this error, where I refer to card and in the above code there is still hm_card end When I run the game everything goes smoothly until the effect should be activated. I get this error: dragon.rb:31:in `effect': undefined method `hp' for nil:NilClass (NoMethodError) from game_02.rb:126:in `
' If I puts the opponent.hp it works though. regards, seba -- Posted via http://www.ruby-forum.com/.