i am in the middle of writing a program in my free time (its a tile map thing). Having setup the creation of a "map" using arrays and nested loops, i wish to add a character to the map. I use jBuilder, and made a jButton that will perform an action when it is clicked. However, there is a problem!
When clicked, the button can only change properties of objects that are created initially (ie user defined). The button does not recognise any object that is created once the program is run. For example, a nested loop creats a grid of tiles(with attributes) and names them "tN" + r + c (where r + c represents row and column number = ie row 1 col 1 = tN00). If i want to change an attribute of tN00 using the button, i cant, as tN00 is not recognised. Anything from the grid is not recognised (i cant use grid[r][c] or grid). What should i read up on to allow tN00 to be changed, or what should i do? This is quite important, as the whole grid[r][c] will be important to the whole program.
Thankyou for reading,
**edit** would 1 solution be to create an arraylist of numbers, which represents each tiles different attributes, and then link these to the grid? [ August 09, 2005: Message edited by: Seamus GalIagher ]
post some code maybe we would be able to come up with a solution!
Joined: Aug 08, 2005
i will post my code. Things to note - I use jBuilder. Also, this code is basically my old code "cleaned up" by another forum member, in a previous post. However, it doesnt work as it should. (my previous post is called My Tiled Game Map System, and the problem is detailed in the last post). The problem is, nothing is displayed - only references are made. Reading that post will help you to understand.
jbuilder has organised my code into these seperate files 1)Frame1 2)Tile 3)Grass 4)Block.
the package is named saloon :-) apoligies for bad code layout - ive coded and recoded about 50 times and havent cleaned up 100%
I can use the button to manipulate things like jLables created at the start of the prgam but not things created during loop. Some code is pointless, like the last loop - but it shows that the references are correct (although no image shows). [ August 09, 2005: Message edited by: Seamus GalIagher ]
Joined: Jul 29, 2005
Hi, You could simply put the declaration of gridref after the labels like this Tile  gridref; It would then be a member of your class. By doing so you would make it available in every function of Frame1.
Remark: the line where you define gridref right now should change and only be an initialization. [ August 09, 2005: Message edited by: Jean-Sebastien Abella ]
Joined: Aug 08, 2005
Hello, and thankyou for taking a look at my first attempt at game programming. (ive a LONNGGG way to go lol).
firstly, i did as you suggested and made the gridref defination an init. it ends up the problem was that gridref and grid were not defined as inits. so now it works.