+ 1
Why is the value same ?should have been diffrent for each of the item .
8 Antworten
+ 1
See, when you pass an array as an Argument as a function like this, you actually don't pass the array itself but a copy of it. That copy is being modified,not the original. What you can do is to define a global array at the top of the class, so it can accessed from within the function:
static item[] items = new item[20];
static void generate(){
//here use items just like it is a real argument
}
+ 1
I guess that a new "item" array is being created in the parameters of genarate(), a copy of your original array. You only modify this copy, not the original itself. I'd recommend to look into the concept of so called Pointers.
+ 1
thanks I think I can figure now to do what I wanted ..for each item have a diffrent ammout because now once the ammout is created all the rest with the same name will share the same amount
+ 1
I've try to use static item but still sane result so I was think in the loop just set item[i].ammout = random.next properly better this way
+ 1
and delete the one in constructor
0
Did it
0
Nice! Well done