Question about array?

Hi! 😀

Got a quick question about arrays in a definition for example:

def test_onevalue += 2value2 += 3@my_array_test = Array.new@my_array_test2 = Array.new@my_array_test.push(value)@my_array_test2.push(value2)msgbox(@my_array_test.size)msgbox(@my_array_test.size2)endDoes instance arrays gets cleared after the definition is called? I'm calling the same definition three times and it keeps coming back the same array size. Shouldn't the array supposed to get longer as I keep calling the definition?
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

No, because you are instantiating a new object each time you call it

@my_array_test = Array.new@my_array_test2 = Array.new
This is overwriting the old array with a new array each time.

Also what is value?  That is an instance variable, so will not keep increasing. I'm a bit surprised it doesn't throw an error, but += must revert to = if the object doesn't exist.
I find actually really weird to use Array.new....

why not just using 

"[ ]" this far more clear and more easier in my opinion :/
It doesn't throw you an error? value is a local and never defined beforehand so it should be sending some kinda error.

And yeah, it's resetting because you're making a new array every time that method is called.

If you want the array to keep increasing, you'd want to do something like

Code:
class Test    def initialize    @my_array_test = Array.new    @my_array_test2 = Array.new  end    def test_one    value = 2    value2 = 3    @my_array_test.push(value)    @my_array_test2.push(value2)    msgbox(@my_array_test.size)    msgbox(@my_array_test.size2)  endend
or if you want value to be kept and increase over calls of test_one

Code:
class Test    def initialize    @my_array_test = Array.new    @my_array_test2 = Array.new    @value = 0    @value2 = 0  end    def test_one    @value += 2    @value2 += 3    @my_array_test.push(@value)    @my_array_test2.push(@value2)    msgbox(@my_array_test.size)    msgbox(@my_array_test.size2)  endend
I'm so sorry guys! I didnt find this till now but thank yall for yalls inputs. XD

Solved and close down plz and ty all /bow XD

Original thread: https://forums.rpgmakerweb.com/threads/question-about-array.45119/