The infamous 'Left hand of an assignment must be a variable'

I'm making some kind of game where a map draws itself as a fixed number of tiles...

some tiles are destroyable, and when destroyed, they turn into another tile (basicly, the image and some parameters changes)

also, a tile can have another tile above or below

now what I'm trying to do is to destroy a tile depending on the layer we are on (above, floor or below)

so it goes like

publicvoid destroyTile(int x,int y){

tile[x][y].getTileOnLayer(currentLayer) = tile[x][y].getTileOnLayer(currentLayer).getDestroyedTile();

//getTileOnLayer returns a Tile object, depending on the layer we send it

}

and yes, the left-hand of an assignment must be a variable

I thought about making a setTile method in the Tile class...the result would only be this = something, which makes the same problem...

what could I do

[1095 byte] By [SlashOwNsUa] at [2007-10-1 0:49:38]
# 1
Would the following be acceptable?Tile tile = tile[x][y];Tile destroyed = tile.getTileOnLayer(currentLayer).getDestroyedTile();tile.setTileOnLayer(currentLayer, destroyed);I'm hazy about what you're asking, to be honest...
dcmintera at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...
# 2
Oops, in-attentive choice of variable names. Try this:Tile currentTile = tile[x][y];Tile destroyedTile = currentTile.getTileOnLayer(currentLayer).getDestroyedTile();currentTile.setTileOnLayer(currentLayer, destroyedTile);
dcmintera at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...
# 3

yes this is exactly what I want to do

but what bugs me is that

each tile has two Tile attributes

Tile above;

Tile below;

if I want to set the tile on the middle level, setTileOnLayer would do

if(layer == MIDDLELEVEL)

this = receivedObject;

and java doesn't like it

but I guess I'll just reorganize some code to make it work

I just wanted to avoid all the work

SlashOwNsUa at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...
# 4

Well, I don't think you can assign to "this".

If things seem too convoluted, then usually either you haven't decomposed the problem or the data enough, you haven't encapsulated enough, or your class design is screwy (which I guess is just a restatement of the first two scenarios).

Just think about what Tile needs to do, and clarify it as needed. You'll get it.

paulcwa at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...
# 5
> Well, I don't think you can assign to "this".Correct. It is a keyword not a variable.
jschella at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...
# 6
The left hand return an object. You cannot assign an object to another object.What you need is a setter method.tile[x][y].setTileOnLayer(currentLayer, tile[x][y].getTileOnLayer(currentLayer).getDestroyedTile());
Peter-Lawreya at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...
# 7
A more logical choise would be to have a destroy method which destroys the tile.tile[x][y].setDestroyedTile(currentLayer);
Peter-Lawreya at 2007-7-8 1:05:29 > top of Java-index,Security,Event Handling...