Loffen Posted November 1, 2004 Posted November 1, 2004 (edited) I am actually coding a map-loader class for my game. In the beginning the map format was quite simple, and i could just read line after line and put things together. Now, my mapformat is getting more complicated, and its much easier to make the whole thing crash. I have done some PHP and i know what regular expressions are, but i never bothered to learn them (mostly because i never needed them), but i think thats the thing i have to use.. My maps are separated into four sections. Config, Terrain data, Object data and Trigger data. I want to read the whole file, then split it up using reg expr. To clearify this i'll make an example: The map: [MAP_CONFIG: map_name=Testmap map_tileset=Default ] [MAP_TERRAIN_DATA: 0;1;0;1;0;1;0;1; 0;1;0;1;0;1;0;1; 0;1;0;1;0;1;0;1; 0;1;0;1;0;1;0;1; ] [MAP_OBJECT_DATA: tree{pos=2,2;} tree{pos=6,3;} ] [MAP_TRIGGER_DATA: hurt{pos=0,0;dmgamount=10;} ] Here i'd like to separate the config, terrain data etc, like this: ConfigVar = map_name=Testmap map_tileset=Default TerrainDataVar = 0;1;0;1;0;1;0;1; 0;1;0;1;0;1;0;1; 0;1;0;1;0;1;0;1; 0;1;0;1;0;1;0;1; etc... I really have no ideas how to do this. If you know some good tutorials, please post them here. Suggestions?? I dont care if i have to change the map format a little... -- Loffen Edited November 1, 2004 by Loffen Quote Erutangis a si tahw
John_0025 Posted November 2, 2004 Posted November 2, 2004 I think you should consider writing the config in XML and using XMLSerialization. It'd be much easier than reading it using regular expressions. There are plenty of web sites and books offering regular expression tutorials. You may find this site helpful, not for tutorials, but there is a pattern testing page and some good example patterns. http://www.regexlib.com John Quote
Loffen Posted November 2, 2004 Author Posted November 2, 2004 Thanks John! I peeked into the site already befor i posted, but i couldnt find anything i could use. I figured i can just use normal Split() function. This will be more code, but i think it will be easier to read. -- Loffen Quote Erutangis a si tahw
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.