From: "Sebastjan H." Date: 2012-10-02T05:46:07+09:00 Subject: Re: still learning by doing - connecting rooms in a game Jan E. wrote in post #1078238: > Hi, > > the item does get pushed into the array, but when you call > Player#satchel again, the variable @satchel is reset to ['test']. So the > previous array with the new item will be overwritten. > > Check it: > > player = Player.new 'testname' > player.satchel << 'testitem' > p player.instance_variable_get :@satchel > player.satchel # this resets @satchel to ['test'] > p player.instance_variable_get :@satchel > > So you have to change those methods. This isn't good style, anyway, > because a getter method is supposed to do nothing but get or calculate a > certain value. It shouldn't change the object (except maybe caching of a > calculated value). When you want to set default values, do it in the > initialize method. >> I didn't want to set a default value, the "test" in the satchel was >> just my primitive way of testing whether the room and the player >> communicate. And yes, I see now that it gets reset. >> How should I change these methods? I am not looking for the easy way >> out by you just telling me;) but I am puzzled and stuck yet again. Why >> does it get reset by just calling it? >> I was dealing with instance variable modification in my last game where >> the player hp got modified constantly. I can't see the difference. I >> guess it is back to books... seba -- Posted via http://www.ruby-forum.com/.