This site requires JavaScript, please enable it in your browser!
Greenfoot back
Xolkiyr
Xolkiyr wrote ...

2018/2/16

Inserting an array into an array?

1
2
Vercility Vercility

2018/2/17

#
danpost wrote...
If you only have two types of ore, then you can distinguish between them within the array by using negative quantities for one of them.
Uh, thats actually genius. Where the hell did you learn that stuff haha
Xolkiyr Xolkiyr

2018/2/18

#
That is genius. Unfortunately there is going to be a grand total of 8 different types of ore when its all said and done. My last question is if I pass an object to the array, that already exists, does it retain all private variables it possesses?
Vercility Vercility

2018/2/18

#
Xolkiyr wrote...
That is genius. Unfortunately there is going to be a grand total of 8 different types of ore when its all said and done. My last question is if I pass an object to the array, that already exists, does it retain all private variables it possesses?
It seems you've misunderstood how Arrays work. You arent actually "putting" the object itself into the array. If you pass an object to an array it will only hold a reference to the object, thats why if you manipulate the object itself with a direct reference it will still be visible when acessing it through the array.
danpost danpost

2018/2/18

#
You could just add another int to the array, making it 12x4, and have the new int represent which type ore it is. So you would have (x, y, type, amount) for each vein.
Xolkiyr Xolkiyr

2018/2/21

#
danpost wrote...
You could just add another int to the array, making it 12x4, and have the new int represent which type ore it is. So you would have (x, y, type, amount) for each vein.
Yeah, I realized that. I was just wondering if it would be easier to just make reference to the ore object itself. But looking at the wording, if it's just a reference to it then the moment I remove the object being referenced it'd fail to continue doing what I wanted it to. New question along the same vein(pun intended), if I made each "world" array a 12x4(like naming them world00, world01, world02, etc etc) and making each one a 12x4, would that produce the results I asked for initially?
Super_Hippo Super_Hippo

2018/2/21

#
If you remove an object from the world, it isn't "gone". If you still have the reference in the array, you can still access it (if you need to).
danpost danpost

2018/2/21

#
Why would you need to remove the vein at all? An empty vein can still be an object in your world and should not present any issues. As far as producing the results asked for ... as long as the same player object goes from world to world (that is, you do not create a new player object for each world), it should work.
Xolkiyr Xolkiyr

2018/2/21

#
danpost wrote...
Why would you need to remove the vein at all? An empty vein can still be an object in your world and should not present any issues. As far as producing the results asked for ... as long as the same player object goes from world to world (that is, you do not create a new player object for each world), it should work.
I only remove them ore veins when the player moves to the next world in the sequence(aka moving left from world01 to world02) because there is only one world object called Moon. Again, I can throw up the actual project file if you want to see what I mean.
danpost danpost

2018/2/21

#
I do not think throwing up the project is needed at this time, When you say world01 or world02, are you talking about having different World subclasses for each one or is everything to be contained in one subclass of World? I must presume the latter from the content already given. In this case, maybe it might be best to have each vein hold its location coordinates when in the world in fields. Then you can have one single array of 400, 12 veins each for 25 worlds (currently; 1452 later, which seems like a lot, but if you nullify them when no ore remains in them, you should not have to many at one time) Vein objects, which avoids a big mess. There will be one more field needed for the index of the current world (as if put in an array).
Xolkiyr Xolkiyr

2018/2/22

#
I figured out a way to do the world without having to set another part of the array. When the character initializes I setup a seperate 5x5x2 array that holds the limits of each "world" in the worldChunkOre variable so that when I need to call a particular worldChunk I don't have to cycle through the entire worldChunkOre array. This is more or less how both arrays look.
worldChunk[5][5][2]
[world00[ThreshMin][ThreshMax]][world01[ThreshMin][ThreshMax]][world02[ThreshMin][ThreshMax]][world03[ThreshMin][ThreshMax]][world04[ThreshMin][ThreshMax]]
[world10[ThreshMin][ThreshMax]][world11[ThreshMin][ThreshMax]][world12[ThreshMin][ThreshMax]][world13[ThreshMin][ThreshMax]][world14[ThreshMin][ThreshMax]]
[world20[ThreshMin][ThreshMax]][world21[ThreshMin][ThreshMax]][world22[ThreshMin][ThreshMax]][world23[ThreshMin][ThreshMax]][world24[ThreshMin][ThreshMax]]
[world30[ThreshMin][ThreshMax]][world31[ThreshMin][ThreshMax]][world32[ThreshMin][ThreshMax]][world33[ThreshMin][ThreshMax]][world34[ThreshMin][ThreshMax]]
[world40[ThreshMin][ThreshMax]][world41[ThreshMin][ThreshMax]][world42[ThreshMin][ThreshMax]][world43[ThreshMin][ThreshMax]][world44[ThreshMin][ThreshMax]]
worldChunkOre[300][4] - Where each row would be:
[x][y][amount][type]
So instead of having to run through all 300 rows of the ore all I'd have to do is, for example I'm in world It would just pull like this:
for(row = worldChunk[x][y][0]; row < worldChunk[x][y][1]; row++){
    getWorld().addObject(new Ore(oreTypeList[worldChunkOre[row][3]], worldChunkOre[row][2]), worldChunkOre[row],[0]worldChunkOre[row][1])
}
Does that all sound about right?
danpost danpost

2018/2/23

#
Xolkiyr wrote...
I figured out a way to do the world without having to set another part of the array. When the character initializes I setup a seperate 5x5x2 array that holds the limits of each "world" in the worldChunkOre variable so that when I need to call a particular worldChunk I don't have to cycle through the entire worldChunkOre array. This is more or less how both arrays look. << Code Omitted >> Does that all sound about right?
Still seems a bit over-complicated. I was thinking that if the ore actors saved their location in the world, then all you would have to do is list the ore objects in a one-dimensional array. Because each world originally has up to 12 ore objects, the first 12 would be for world00, the next 12 for world01, etc. If you have worlds that are 5x5 then the sixth group of 12 would be for world10, and so on. To help save on memory usage, you can set the image of empty veins to 'null'.
You need to login to post a reply.
1
2