Jump to content
  • Advertisement
Sign in to follow this  
Drew_Benton

Unity [.net] First C# Program - GameDev Thread Saver

This topic is 4735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've recently started taking a look at C# since it's been on my todo list for so long. And what better way to start learning it with other than making tools! This C# program is called Thread Saver and what it does is you give it an id of the GameDev.net thread you want to save, and it will save the entire thread, all pages, into one html file to your hard drive. Now you will have to look at the code to see everything I did. It is very brekable right now, but anything that does popup with specific threads could be fixed with more code. One of the major things that I added in was the resolving of all relative links to absolute links, so when you save the page, it looks like a gamedev page rather than what you get when you save it from your browser. Here's the complete source, since I have no reason to keep it closed. There are lots of room for improvements and modifications. If you uncomment out a lot of the stuff in the CombineGameDevThread function, then you will end up with a nice page that is print ready! Since there are a lot of slashes and tags the forum might eat, I will just post the file instead. Now for my C# questions/comments from making this: 1. Is the StreamReader.ReadToEnd(); function used in a good sense how I did it? Is there anything that would be faster? I tried using the StreamReader.Read function, but I could not figure out how to convert from a char[] to a string. 2. How do you convert from a char[] to a string? The .toString method returns simply System.char[] or whatever that string is for the object name. 3. Why, oh why do functions such as Replace, Insert, etc.. return the new string rather than modify the current! It took me so long to figure out that the new modified string is returned rather than the updated itself. I can see the logics, but darn, that was so confusing! 4. It took me a bit to figure out that .Find is really .IndexOf [headshake] 5. Other than that, does anyone see any improvements that I can make in terms of C# concepts? Ok thanks for any help/suggestions. As for the program, if you want to do some comparing, I saved the thread, Single Word Game, and my results were:
102 Pages
...
Operation time: 358.234 seconds
The final file is 7.962MB and takes quite a bit for FF to load [lol]. I plan to improve this a lot more, but for right now, I'm just learning the concepts. If there's anything you'd like to see in it, feel free to make a suggestion and I will write it down. - Drew

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Drew_Benton
Now for my C# questions/comments from making this:

1. Is the StreamReader.ReadToEnd(); function used in a good sense how I did it? Is there anything that would be faster? I tried using the StreamReader.Read function, but I could not figure out how to convert from a char[] to a string.

2. How do you convert from a char[] to a string? The .toString method returns simply System.char[] or whatever that string is for the object name.

3. Why, oh why do functions such as Replace, Insert, etc.. return the new string rather than modify the current! It took me so long to figure out that the new modified string is returned rather than the updated itself. I can see the logics, but darn, that was so confusing!


I'm tired and about to crash, but here is a little help. Strings are immutable objects, meaning that they can't be changed once they are set. Since that is the case,, and function that returns a different string must make a new string. If you are modifying a string a lot, consider using its mutable cousin the StringBuilder. As far as converting char[] to a string, just pass the character array into the string constructor.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Now for my C# questions/comments from making this:

1. Is the StreamReader.ReadToEnd(); function used in a good sense how I did it? Is there anything that would be faster? I tried using the StreamReader.Read function, but I could not figure out how to convert from a char[] to a string.

Dunno, would have to read the code to know. [grin]
Quote:

2. How do you convert from a char[] to a string? The .toString method returns simply System.char[] or whatever that string is for the object name.

String constructor
Quote:

3. Why, oh why do functions such as Replace, Insert, etc.. return the new string rather than modify the current! It took me so long to figure out that the new modified string is returned rather than the updated itself. I can see the logics, but darn, that was so confusing!

strings are immutable, aka: they cannot change. Use StringBuilder/StringWriter/StringReader.
Quote:

4. It took me a bit to figure out that .Find is really .IndexOf [headshake]

lol, made sense to me.
Quote:

5. Other than that, does anyone see any improvements that I can make in terms of C# concepts?

Your naming scheme is inconsistant. Stop mixing cases of the method names. If you are going to use upper camel case, then stick with that, mixing lower and upper camel case (pascal case) just confuses things.

It's also not done in a very OO fashion. You might also want to look into the MS HTML processing stuff. You can use it to build a DOM of the pages, find hyperlinks, images, stylesheets. That information could be used to download a whole tree of the pages, based on the information. You are replicating a lot of code that's already been done.

Definantly need to use a StringBuilder, your current code is very....memory inneficient.

Share this post


Link to post
Share on other sites
If you're interested in efficiency, you might want to check out the CLR Profiler. An article on it is available here. The call graph view is interesting. It'll let you see what functions are taking up the most time.

Regarding your code itself, like Washu I'd recommend naming consistency. I'd also recommend following .NET naming conventions for even more consistency; I've always found it annoying when Java naming conventions sneak into .NET and vice versa. The link is quite in depth; you can find summaries through Google.

Share this post


Link to post
Share on other sites
Sorry guys for the late replies, I will be getting back to this thread in a week or so when I have my dev computer up again. It's broken now so I am working with an old celeron 633mhz. It's not that bad and Visual C# 2005 Beta > Visual Studio 2003 C# [wink]. I'll start reading all the replies and respond again soon. Thanks for all your time!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Aryndon
      Project Redemption is an semi-fantasy RPG with a linear story and an elaborate combat system.
      We are building in Unity and are currently looking animators and artists.
      What we are looking for
      -Someone who is okay with split revenue/profits when finished
      -Collaborate with others in the team. Do you have an idea/thought on what should be included? Tell us!
      -Someone who wants to work with people that are passionate about this project
      If you are interested. Please message me and I will get back to you as soon as possible! Or add me on Discord AJ#6664
    • By Aggrojag
      Hello!
      I'm working on a game that is a narrative driven dark comedy with some small aspects of platforming and puzzle solving. The project is rather small as well. It touches on topics such as suicide, mental illness, family, corruption, free-will, and redemption.
      This project is exercise in polish, this means some experimentation will be needed along with some reworking of assets as they're provided.
      This will be a revshare model.
      First, I'm looking for a 2D sprite artist, not pixelated, that can compliment the style of the attached images, and be similar to the temporary character.
      We are looking to bring on a SFX designer at this time. Full list of required SFX will be available upon request, as well as a build with all elements related to sound implemented in some form (many SFXs pulled from the web for now). Will likely require some field recording, and some pretty strange SFX for when things get weird. I imagine a good portion of these will be quite fun to create.
      Lastly, I'm looking for a male voice actor, English should be your primary language. There will be at minimum two characters that will need to be brought to life through vocals. The first voice is similar to Marvin from Hitchhiker's Guide to the Galaxy. A reference for the second voice would be a mix of Ren (Ren & Stimpy), and Android 21 (DragonBallFighterZ). Due to formatting, I'm not including YouTube links in the post, sorry.
       
      WIP Scene with our custom shaders attached (platforms are lazily placed, as this was an asset test):

      A scene with dynamic lighting and temp character:

       
      Unshaded asset:

      If you made it to the bottom, thank you, and I look forward to hearing from you.
    • By SickTwistGames
      Ok, firstly, Hi.
       
      This is my first post on this forum. I am an Indie Dev making my first game so bear with me when I say dumb stuff, I'm on a huge learning curve.
       
      My first question is about inventory systems for unity. I am trying to make a survival type game with crafting. I have purchased Inventory manager pro by devdog from the unity asset store and it seems like a pretty powerful assett but for an intermediate coder its a little tough to use.  I'm beginning to wonder if it was the right purchase.
      So my question is.... does anyone have any experience of inventory plugins / systems for unity and can anyone reccomend a system to me?
      It needs to have the following: Loot system, crafting system, character sheet, blueprint system,  character stats system. Ideally with as little coding as possible.
       
      Thanks
    • By ethancodes
      I've got a bug with my brick breaker style game. The bricks move down one line at a time ever 1.5 seconds. What appears to be happening is occasionally the ball will be just about to hit the brick when the brick moves down a line, and now the ball is behind it. I'm not sure how to fix this. I have two ideas but I'm not sure of implementation. 1 solution would be to check where they were and where they are going to be before rendering the frame. Then if they crossed paths, then register the brick as hit. Solution 2 would be change how the bricks move. I could maybe slide them down line by line, instead of a jump down. I'm not sure of this will fix the issue or not. Any ideas?
    • By Pixeye
      I wrote an extension for unity inspector that allows to group/fold variables. 
      Available on github  , cheers!

       
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!