Need help cleaning up code and or making it faster.

Thread Solved

Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster

Need help cleaning up code and or making it faster.

 
0
  #1
Nov 26th, 2008
string MAP[11][11];
MAP[0][0]= "|I|";
MAP[0][1]= "|I|";
MAP[0][2]= "|I|";
MAP[0][3]= "|I|";
MAP[0][4]= "|I|";
MAP[0][5]= "|I|";
MAP[0][6]= "|I|";
MAP[0][7]= "|I|";
MAP[0][8]= "|I|";
MAP[0][9]= "|I|";
MAP[0][10]= "|I|";
//1
MAP[1][0]= "|I|";
MAP[1][1]= "|R|";//thing
MAP[1][2]= "|T|";//thing
MAP[1][3]= "|F|";
MAP[1][4]= "|F|";
MAP[1][5]= "|F|";
MAP[1][6]= "|F|";
MAP[1][7]= "|R|";
MAP[1][8]= "|R|";
MAP[1][9]= "|G|";
MAP[1][10]= "|I|";

This is an example of an array that I built for my rpg program.

Could someone tell me how to clean this up, and or make it faster for me to type out so i can fit more things into my busy day without getting bored?

Such as:
MAP[1][]={"g","g","\0"};
I tried this out, but it doesn't seem to work.
Are there any other ways to shorten down the lines of code that I have to write.

I am currently trying to make a [32][32] Map, and I really don't want to have to write down 1000+ lines of code for a single array.

If anyone has any knowlege of somthing that I can do, please post it. Even if it has nothing to do with my topic, Knowledge is power!

Thanks anyway,
Shinedevil
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Need help cleaning up code and or making it faster.

 
0
  #2
Nov 26th, 2008
The nicest solution (in terms of future flexibility), is to encode your data in either a bitmap image or a text file.

Alternatively, if you just want to initialize an array of arrays:
// made smaller (4x4) so it fits in a post neatly...
string MAP[4][4] = {
{"|I|", "|I|", "|I|", "|I|" },
{"|I|", "|I|", "|I|", "|I|" },
{"|I|", "|I|", "|I|", "|I|" },
{"|I|", "|I|", "|I|", "|I|" }
};
But you're right, you can't initialize one 'row' at a time. It has to be done all at once.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster

Re: Need help cleaning up code and or making it faster.

 
0
  #3
Nov 26th, 2008
Originally Posted by MattEvans View Post
The nicest solution (in terms of future flexibility), is to encode your data in either a bitmap image or a text file.

Alternatively, if you just want to initialize an array of arrays:
// made smaller (4x4) so it fits in a post neatly...
string MAP[4][4] = {
{"|I|", "|I|", "|I|", "|I|" },
{"|I|", "|I|", "|I|", "|I|" },
{"|I|", "|I|", "|I|", "|I|" },
{"|I|", "|I|", "|I|", "|I|" }
};
But you're right, you can't initialize one 'row' at a time. It has to be done all at once.
Whenever I try to do what you told me, it says" Error: Excess "
What should I do to solve this,
I happens here (",|I|" } }; <== )
What should I do to combat this problem?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Need help cleaning up code and or making it faster.

 
0
  #4
Nov 26th, 2008
Post the full line of code where you get the error.

But, it looks like you have the double quote and comma in the wrong order in that excerpt.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Need help cleaning up code and or making it faster.

 
0
  #5
Nov 26th, 2008
Also, if you have a mismatch between the number of items you say are in the array, and the number of items you actually put in the array, you'll get an error that says something along the lines of "too many initializers".
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Game Development Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC