View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Back to the grindstone

11 replies to this topic

### #1bluwind  Members

Posted 17 June 2013 - 04:46 AM

currently experiencing a Coding Horror - for the past three days I have been stuck on a section of my game which switches between different phases (buy menu - move cycle).. and no matter what I try it throws back trouble. Its going to make me that much more happier with the finished product though in the end.. so ummm yeah.. back to it.

### #2bluwind  Members

Posted 17 June 2013 - 05:10 AM

Yey I fixed it... "puts on his cool shades and struts"..

YEAH baby

### #3Alpheus  GDNet+

Posted 17 June 2013 - 06:24 AM

You're type of programmer I love to hate. You give a vague or even no description of the problem. Then you come back with "I solved it" and yet give no description of the solution to said problem.

May the Debugging Gods strip you of your IDE and your breakpoints prove false

External Articulation of Concepts Materializes Innate Knowledge of One's Craft and Science

Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley

If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts

Spoiler

### #4Olof Hedman  Members

Posted 17 June 2013 - 07:39 AM

Since it's in the "Coding Horrors" forum, I assume he didn't really wanted help with anything, just vent some frustration...

### #5FLeBlanc  Members

Posted 17 June 2013 - 08:19 AM

I see Coding Horrors as more of a TheDailyWTF forum, rather than a place to just vent frustration in a vague, abstract manner. @OP: Post some ugly code for us to mock, dangnabbit!

### #6LennyLen  GDNet+

Posted 17 June 2013 - 09:36 AM

@OP: Post some ugly code for us to mock, dangnabbit!

Here's some ugly C# code I wrote this morning:



using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]

public static extern int GetShortPathName(

[MarshalAs(UnmanagedType.LPTStr)]

string path,

[MarshalAs(UnmanagedType.LPTStr)]

StringBuilder shortPath,

int shortPathLength

);

static void Main(string[] args)
{
if (File.Exists("playlist"))
{
File.Delete("playlist");
}
FileStream writetext = File.Create("playlist");
DirSearch(writetext, "C:\\music");
writetext.Close();
}

static void DirSearch(FileStream FS, string sDir)
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
string temp = f.Substring(f.Length - Math.Min(4, f.Length));
if (temp.ToUpper() == ".MP3")
{
StringBuilder shortPath = new StringBuilder(255);
GetShortPathName(f, shortPath, shortPath.Capacity);
FS.WriteByte((byte)(shortPath.Length + 17));
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)176);
FS.WriteByte((byte)(shortPath.Length - 12));
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)12);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)0);
FS.WriteByte((byte)10);
}
}
DirSearch(FS, d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}

private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
}



A bit of backstory: The CD changer we use in the restaurant I manage is dying, so I purchased us a cheap MP3 player.  It works well enough, but it only has two methods of choosing tracks - either from the complete library or from a user defined playlist (of which their are five slots).  Since there is some music on it intended for use later on Friday/Saturday nights that isn't really suitable to play at lunch, playing from the entire library isn't good enough, which leaves using the playlists.

The playlist functionality is atrocious however, you can't add entire albums or directories. Each song you want on the playlist must be loaded individually and then added manually to the list.  And since I'd put about 6Gb of music on it, that was a LOT of songs to add one at a time.  So I poked around on the player's filesystem and managed to find its playlist files.  The format was easy to figure out.  Each record has a 16 byte header, followed by the filename(which is stored in 8.3 format).  The first byte of the header is the length of the record (including the header itself).  The fifth byte was always the length - 29 (I have no idea why), and every other byte of the header was the same for every record.

Discovering all that, I decided it would be a LOT faster to write a program to generate the playlist files than it would be to create them manually.  And that is whatthe code above does.  I created a directory on the C: drive called music (as that is where the MP3s are stored on the device), and for each playlist I want, I just put the tracks I want in the music directory and then run the program.

I'm not overly familiar with C#.  I used it briefly about three years ago and haven't used it since (though I really did enjoy using it back then as I found it very easy to develop with C#/.net).  I used it for this task though as it can do the filename conversion in a few lines of code. It would have taken me a lot longer to code the same functionality using plain C.  I didn't care too much if it was a quick hack as it's purely for my own use (though I am considering writing a better version with a GUI for selecting which tracks to add to the playlist.

The main thing was that I needed something very quickly (I wanted it done before I left for work), and it took me very little time to refresh myself with C# and write the code.  It actually took less time to write it than it did to download VS Express.

The best part is: The playlists I fabricated worked perfectly on the player first time. Yay!

### #7Alpheus  GDNet+

Posted 17 June 2013 - 11:15 AM

Since it's in the "Coding Horrors" forum, I assume he didn't really wanted help with anything, just vent some frustration...

But there's no "code". This isn't the "Only Venting Corner".

Anyway, I was being slightly facetious. Everyone has had a similar issue to the OP. Next time, he just needs to post code as well as vent

External Articulation of Concepts Materializes Innate Knowledge of One's Craft and Science

Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley

If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts

Spoiler

### #8bluwind  Members

Posted 17 June 2013 - 12:10 PM

Lmao. Wasn't expecting a debate and a small fire to break, I. Said that I was experience a coding horror of my own. I must have missed the sticky that specified "must contain code", it is very rare I will actually ask for help with code.Only when I knows piece of code should be working but doesn't and I need an extra set of eyes will I ask for help. And the " have sorted it"reply was simply in response to the per defined expected level of happiness at solving the problem. Didn't feel a need to post my solution as I never posted a problem, if u believe I posted in the wrong forum then please assist me with directions to a more appropriate place.
Oh an on a different note, please feel free to head over to the beginner section as I am possibly going to post p another little problem if I can't work out a solution soon.

### #9FLeBlanc  Members

Posted 17 June 2013 - 12:55 PM

Said that I was experience a coding horror of my own. I must have missed the sticky that specified "must contain code",

To be fair, there really isn't any such rule. It's just more fun for us onlookers if you do post code so we can sit back and say, "whoops, yeah, that's a heckuva WTF there, bro" all while busily hiding our own WTFs from public view and pretending like we know what we're talking about and that our own code is pristine and perfect, rather than the WTF-riddled mess of hacks that it really is.

### #10bluwind  Members

Posted 17 June 2013 - 01:00 PM

Lol, aye FLeBlanc. I must admit I have been looking though a few other peoples - all looks neater and better written than mine, I was actual on the bus when I read Alpha's reply and I gave out a little WTF. But I fixed the second problem too .. games looking good now.. anyway... if I get time I will post up the code to this particular coding horror ..

### #11Alpheus  GDNet+

Posted 17 June 2013 - 01:53 PM

Lol, aye FLeBlanc. I must admit I have been looking though a few other peoples - all looks neater and better written than mine, I was actual on the bus when I read Alpha's reply and I gave out a little WTF. But I fixed the second problem too .. games looking good now.. anyway... if I get time I will post up the code to this particular coding horror ..

My job here is done

External Articulation of Concepts Materializes Innate Knowledge of One's Craft and Science