Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (763)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Editing a tile map while running  (Read 1626 times)
0 Members and 1 Guest are viewing this topic.
Offline CroCop

Junior Newbie





« Posted 2007-01-12 03:56:20 »

My problem is this, i have a platformer game that uses a String for the tile map, such as this
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
 String map[] = {
      "11111111111111111111111111111111111111111111111111111111111111111111111",
      "10000000000000000000000220000000000000000000000000000000000000000000001",
      "10000000000000000000220000000000000000000000000000000000000000000000001",
      "10000000000000002200000000000000000000000000001110000000000000000000001",
      "1000000000E022000000000000000000000000000001111110000000022222200000001",
      "10000000022000000000000000000000000000011111111111000000000000000000001",
      "10000000000000000000000000000000000011111111111111111111111000011111111",
      "11111111111111111111111111111111111111111111111111111111111111111111111"
     
   };

Now the problem is that sometimes i need to edit the map while the game is playing, such as changing an E to a 0 or something to the affect, but everytime i want to go and change an individual character in the map i get an "unexpected type" error.  This is how i try to do it
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
for (int i = 0; i<map.length; i++) {
         for (int j = 0; j < map[0].length(); j++) {
            char c = map[i].charAt(j);
            if (c == 'E') {
               enemy[enemyIndex] = new Enemy(elite,eliteAttack,i*tileW,j*tileH,this, 3);
               enemyIndex++;
               map[i].charAt(j) = "0";
            }
         }
}

Right on the line where i try to change the value of the character in the map, i get an "unexpected type" error pointing to the oppening round bracket.  I know im probably overthinking this and its easier than i think, but i really need help on how to do this.  Thanks
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2007-01-12 07:28:15 »

1. Strings are immutable.
2. "0" is a String and not a char.
3. String.charAt is a method, which returns the character at that position.
4. You cannot assign some value to some method.

Simple solution: use a 2d array (byte, short, char or int) instead.

弾幕 ☆ @mahonnaiseblog
Offline SluX

Junior Devvie





« Reply #2 - Posted 2007-01-12 08:01:32 »

Or use StringBuffer-its basicaly mutable String-u can change individual chars...

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #3 - Posted 2007-01-12 20:01:08 »

Sure. But that's awfully long winded and a waste of processing power, therefore I didn't mention it.

弾幕 ☆ @mahonnaiseblog
Offline JAW

Senior Devvie


Medals: 2



« Reply #4 - Posted 2007-01-15 21:33:42 »

map.charAt(j) = "0";

That wont work. Try map[j] = "0" but I am not sure and cant test it right now.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (490 views)
2018-06-10 19:43:48

EgonOlsen (577 views)
2018-06-10 19:43:44

EgonOlsen (406 views)
2018-06-10 19:43:20

DesertCoockie (726 views)
2018-05-13 18:23:11

nelsongames (1015 views)
2018-04-24 18:15:36

nelsongames (981 views)
2018-04-24 18:14:32

ivj94 (1505 views)
2018-03-24 14:47:39

ivj94 (557 views)
2018-03-24 14:46:31

ivj94 (1261 views)
2018-03-24 14:43:53

Solater (560 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!