• What are you working on? November 2011 Edition
    3,673 replies, posted
[QUOTE=FlashStock;33341579]try while (sw.Peek() >= 0) { input = sw.ReadLine(); }[/QUOTE] That just returns "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, etc"
[QUOTE=Loli;33341644]That just returns "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, etc"[/QUOTE] Try this: [cpp]String buffer; while ( ( buffer = sw.ReadLine() ) != null ) { // do stuff }[/cpp] You should also wrap the StreamReader in a BufferedReader for more efficient reading of lines. Additionally it is not necessary to allocate the string array in advance, as the String.split function will allocate one for you. Your final code will be something like this: [cpp]if (File.Exists("tilemap.txt")) { StreamReader sw = new StreamReader("tilemap.txt"); BufferedReader reader = new BufferedReader(sw); String buffer; String[] data; while ((buffer = reader.ReadLine()) != null) { data = buffer.Split(','); for (int Y = 0; Y < 32; Y++) { mTileMapData[i, Y] = Convert.ToInt16(Data[i]); } } reader.Close(); }[/cpp]
[QUOTE=Loli;33341294]Working on mah comp entry... Could anybody help me fix this? [code] if (File.Exists("tilemap.txt")) { StreamReader sw = new StreamReader("tilemap.txt"); string input = ""; string[] Data = new string[48]; for (int i = 0; i < 32; i++) Data[i] = "0"; for (int i = 0; i < 48; i++) { input = sw.ReadLine(); Data = input.Split(','); for (int Y = 0; Y < 32; Y++) { mTileMapData[i, Y] = Convert.ToInt16(Data[i]); } } sw.Dispose(); sw.Close(); } [/code] It throws this error: Object reference not set to an instance of an object. At this line: Data = input.Split(',');[/QUOTE] Split returns null if you try to split a string with a character the string doesn't contain. You sure all the lines contains a ','?
[QUOTE=Dj-J3;33341817]Split returns null if you try to split a string with a character the string doesn't contain. You sure all the lines contains a ','?[/QUOTE] [QUOTE=Loli;33341294]It throws this error: Object reference not set to an instance of an object. [highlight]At this line: Data = input.Split(',');[/highlight][/QUOTE]
I've got it working mostly now. Rendering is an issue though. this is what it looks like when rendering a loaded file [img]http://img526.imageshack.us/img526/9979/tempde.png[/img] But as you can see it shouldn't. [code]2,1,2,1,0,0,0,0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(int y = 0; y < 32; y++) { for (int x = 0; x < 48; x++) { spriteBatch.Draw(mAsset, mCamera + new Vector2(32 * x, 32 * y), new Rectangle(32 * mTileMapData[x, y], 0, 32, 32), Color.White); } } [/code] I can't just flip the X and Y either because it won't fit in the array.
I had an idea about a top down shooter game where explosions actually work the way they are supposed to. So I made a pressure simulation thing. [video=youtube;vEGfs9RNMM4]http://www.youtube.com/watch?v=vEGfs9RNMM4[/video]
Yeah, that's because your reading method is wrong. Your file has a row on every line, that means the Y value of every line is fixed and the X is variable. For example: [code]0 1 2 1 0 3 4 1 1 5 3 2 ( 0, 0 ) = 0 ( 1, 0 ) = 1 ( 2, 0 ) = 2 ( 3, 0 ) = 1 ( 0, 1 ) = 0 ( 1, 1 ) = 3 ( 2, 1 ) = 4 ...[/code] This is what you did in your first example: [cpp]for (int i = 0; i < 48; i++) { input = sw.ReadLine(); Data = input.Split(','); for (int Y = 0; Y < 32; Y++) { mTileMapData[i, Y] = Convert.ToInt16(Data[i]); } }[/cpp] Here you assume that on a single line in your input file, every coordinate has a variable Y coordinate and the X coordinate is fixed. This is of course, the other way around. That's why lines in your render appear vertical instead of horizontal.
Everything working now, thanks for the help.
[QUOTE=Darwin226;33341995]I had an idea about a top down shooter game where explosions actually work the way they are supposed to. So I made a pressure simulation thing. [video=youtube;vEGfs9RNMM4]http://www.youtube.com/watch?v=vEGfs9RNMM4[/video][/QUOTE] that's really cool :eng101: too bad the average user probably won't be able to tell what's happening compared to, say, giving an impulse to nearby objects
[QUOTE=icantread49;33342318]that's really cool :eng101: too bad the average user probably won't be able to tell what's happening compared to, say, giving an impulse to nearby objects[/QUOTE] Well in theory, if I did it well it would allow for interesting level design. For example, lure a large group of enemies into a narrow dead end, then throw a pressure grenade and watch them all be blown out of the tunnel.
[QUOTE=icantread49;33342318]that's really cool :eng101: too bad the average user probably won't be able to tell what's happening compared to, say, giving an impulse to nearby objects[/QUOTE] I think game devs consistently underestimate what players notice. When a game has shitty grenades with shitty ways of hit detection/how far they hit/etc. I notice. It'd be really really cool to me to like throw a high explosive in a small room and watch a bit of flame lick out the doorway or something like that, instead of some generic circle.
[QUOTE=Loli;33341294]Working on mah comp entry... Could anybody help me fix this? [csharp] if (File.Exists("tilemap.txt")) { StreamReader sw = new StreamReader("tilemap.txt"); string input = ""; string[] Data = new string[48]; for (int i = 0; i < 32; i++) Data[i] = "0"; for (int i = 0; i < 48; i++) { input = sw.ReadLine(); Data = input.Split(','); for (int Y = 0; Y < 32; Y++) { mTileMapData[i, Y] = Convert.ToInt16(Data[i]); } } sw.Dispose(); sw.Close(); } [/csharp] It throws this error: Object reference not set to an instance of an object. At this line: Data = input.Split(',');[/QUOTE] Your inconsistent naming is bothering me. Anyways you should really use lists. [csharp] if (File.Exists("tilemap.txt")) { using (var sw = new StreamReader("tilemap.txt")) { var rowlength = mTileMapData.GetLength(0); var columnlength = mTileMapData.GetLength(1); for (int y = 0; y < columnlength; y++) { var row = sw.ReadLine(); if (row == null) break; var columns = row.Split(','); for (int x = 0; x < rowlength; x++) { short num; if (x < columns.Length && short.TryParse(columns[x], out num)) { mTileMapData[x, y] = num; } else { mTileMapData[x, y] = 0; } } } } }[/csharp]
[QUOTE=BlkDucky;33340294]it always was.[/QUOTE] It just makes everything go so smoothly.
I always learn more from these silly game jams than I do from making something on my own time. Bad design decisions become apparent very quickly, and each time I do one I feel like I get better.
[img]http://dl.dropbox.com/u/11093974/Junk/response.gif[/img] Collision response. It's a little iffy sometimes but HOLY MOTHER OF GOD IT WORKS. [url=http://dl.dropbox.com/u/11093974/Junk/Photo%20Nov%2018%2C%208%2021%2009%20PM.jpg]Made good use of my new whiteboard, too.[/url] By the way: A friend of mine bought a whiteboard about the same size as this one for like $300... anyone looking to get one, don't waste your money. They sell 8x4 foot ones at Lowes for like $14. Not as elegant, but better than paying $286 on a frame...
Oh hey there's a service pack, looks like this'll fix a few thin- [img]http://i.imgur.com/ErCkd.png[/img] never mind
[QUOTE=NovembrDobby;33345688]Oh hey there's a service pack, looks like this'll fix a few thin- [img]http://i.imgur.com/ErCkd.png[/img] never mind[/QUOTE] Intellisense errors are different than actual errors. It tries to guess what might be an issue but it doesn't actually know because it doesn't compile the code. VS always warns me of 2 intellisense errors in windows.h.
Making a library for C++ that simplifies writing OpenGL 3+ applications. Here, have a complimentary triangle: [img]http://i.imgur.com/nObTi.png[/img] And, the code to draw that is [url=http://pastebin.com/vnVAeD38]here[/url]. All nice and non deprecated (unless you count GLUT, but that's just used for the test project, the actual library uses gl3w - 100% core profile functions).
After seeing this, I suddenly want to start a collaboration project on git/svn with other facepunchers and then see the results through gource [media]http://www.youtube.com/watch?v=NjUuAuBcoqs[/media] Not shown in this video: File names on the little nodes Collaborator names
[QUOTE=high;33344894]Your inconsistent naming is bothering me. Anyways you should really use lists. [csharp] if (File.Exists("tilemap.txt")) { using (var sw = new StreamReader("tilemap.txt")) { var rowlength = mTileMapData.GetLength(0); var columnlength = mTileMapData.GetLength(1); for (int y = 0; y < columnlength; y++) { var row = sw.ReadLine(); if (row == null) break; var columns = row.Split(','); for (int x = 0; x < rowlength; x++) { short num; if (x < columns.Length && short.TryParse(columns[x], out num)) { mTileMapData[x, y] = num; } else { mTileMapData[x, y] = 0; } } } } }[/csharp][/QUOTE] His variable names annoy you, yet you don't even explicitly type variables?!
What im up to: [video=youtube;hQgMLQdbp1s]http://www.youtube.com/watch?v=hQgMLQdbp1s[/video] Having some problems with matricies if anypne is kind enought to give me a hand. [url]http://www.facepunch.com/threads/1092921?p=33343163&viewfull=1#post33343163[/url]
[QUOTE=Dotmister;33346115]His variable names annoy you, yet you don't even explicitly type variables?![/QUOTE] Whats wrong with implicit variable types?
Video for rayboy1995 and I's Viking project that I filmed today. [media]http://www.youtube.com/watch?v=4iqCmovxfdU[/media] Any comments or criticism about the game (or the commentary) is greatly appreciated. [url]http://bombsightgames.dyndns.org/index.htm[/url] WIP website for WIP games.
[QUOTE=high;33346325]Whats wrong with implicit variable types?[/QUOTE] It was designed for web development, mainly to ease people comming from PHP. Not that thats a reason not to use it, but its clearer to see what your variable will be holding if you use variable types
[QUOTE=Richy19;33346347]It was designed for web development, mainly to ease people comming from PHP. Not that thats a reason not to use it, but its clearer to see what your variable will be holding if you use variable types[/QUOTE] You sure? I thought it was implemented for linq. Anyways intellisense will tell you its type. Also its pretty easy to tell what the variables will be where I used it.
[QUOTE=high;33346369]You sure? I thought it was implemented for linq. Anyways intellisense will tell you its type. Also its pretty easy to tell what the variables will be where I used it.[/QUOTE] I only use var when either the type is unambiguous, like when creating an object with new, or the type is too damn long to type. I wouldn't replace int or string with var. e: I tend to not rely on intellisense because I do half of my coding on vim, which obviously doesn't have it.
[QUOTE=raBBish;33346392]I only use var when either the type is unambiguous, like when creating an object with new, or the type is too damn long to type. I wouldn't replace int or string with var.[/QUOTE] That's how I originally used them but with intellisense and obvious types I see no reason not to use them more. I mean hell, in most cases were its designed to be used it can be very ambiguous without intellisense telling you what it is. var ages = People.Select(p => p.Age); Is ages IEnumerable<byte/short/int/long>? [QUOTE=raBBish;33346392]e: I tend to not rely on intellisense because I do half of my coding on vim, which obviously doesn't have it.[/QUOTE] Well after using C# so long I don't even see the places I used them as ambiguous. Length is always int, ReadLine is string, Split is string[]. Anyways intellisense is a huge part of .net development. I recommend using at least monodevelop or sharpdevelop.
[QUOTE=high;33346464]Anyways intellisense is a huge part of .net development. I recommend using at least monodevelop or sharpdevelop.[/QUOTE] I'm well aware of that, it's been ages since I last used vim for C#. Can't live without VS + ReSharper now.
[QUOTE=high;33346464]That's how I originally used them but with intellisense and obvious types I see no reason not to use them more. I mean hell, in most cases were its designed to be used it can be very ambiguous without intellisense telling you what it is. var ages = People.Select(p => p.Age); Is ages IEnumerable<byte/short/int/long>? Well after using C# so long I don't even see the places I used them as ambiguous. Length is always int, ReadLine is string, Split is string[]. Anyways intellisense is a huge part of .net development. I recommend using at least monodevelop or sharpdevelop.[/QUOTE] Sure, you can hover over the names for intellisense to tell you what they are, but it's so much easier to just glance up at variable names (especially since people rarely use hungarian notation anymore) to see what they are. I think it's easily as important as having good variable names
[QUOTE=high;33346464]That's how I originally used them but with intellisense and obvious types I see no reason not to use them more. I mean hell, in most cases were its designed to be used it can be very ambiguous without intellisense telling you what it is. var ages = People.Select(p => p.Age); Is ages IEnumerable<byte/short/int/long>? Well after using C# so long I don't even see the places I used them as ambiguous. Length is always int, ReadLine is string, Split is string[]. Anyways intellisense is a huge part of .net development. I recommend using at least monodevelop or sharpdevelop.[/QUOTE] Relying on intellisense to make your code readable is perhaps the silliest thing I've ever heard. Plenty of devs use flat text file editors + make etc.
Sorry, you need to Log In to post a reply to this thread.