From: Day Date: 2008-02-05T12:29:11+09:00 Subject: Re: Having problems with my instance variable ------=_Part_10289_8010182.1202182145376 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 4, 2008 8:14 PM, macaco wrote: > def some > call_other(@xpos,@ypos) > end > > def more > call_other(@other,@another) > end > > def call_other(var1, var2) > max = 9 > var1= rand(max) > var2=rand(max) > end > end > It's not clear to me what you're trying to do here. You want a method that will set arbitrary variables to random numbers? That's a wild guess. What you're actually doing when you call call_other is passing it the values in @xpos and @ypos (which is 0 and 0 initially). Then, in call_other, you're taking those 0s in with var1 and var2. Then you're over-writing var1 and var2 with random numbers (0s are lost, as far as this method is concerned) and then... you exit. You're leaving your @vars untouched because you're passing the values, not the variables themselves. If "max" is always going to be the same, I'd make it a constant at the class level and then just have some look like this: def some @xpos = rand MAX @ypos = rand MAX end If max won't be the same all the time, make a method that figures it out and returns a random number based on it... An example will make more sense, maybe. def some @xpos = generate_random @ypos = generate_random end def generate_random max = 9 # or whatever determines your max value rand(max) end I hope that's clear. Scope can be confusing sometimes. If I am too rambly (I hear that a lot), maybe someone with more experience will be more clear, too. Ben ------=_Part_10289_8010182.1202182145376--