1. Post #41
    Icedshot's Avatar
    April 2010
    2,313 Posts
    I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree

    like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered
    Nah, i don't visit waywo to see "Im having a problem with something" which is generally a misunderstanding of how a language operates
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  2. Post #42
    Gold Member
    Fire's Avatar
    October 2005
    1,520 Posts
    Not really sure what you mean, but cant you just use a list of chars?
    List<char> myCharList;

    or a char array?
    I don't know, I'm extremely new to c# (about... 8 hours total?); The value is pulled from a textbox, but has a default value like so:

    CharacterBlacklist = "*;*;*;";
    (the forums star out the control characters in my blacklist)

    and I use it like this

            private string Filter(String filterMe, Boolean fileName)
            {
                if (!string.IsNullOrEmpty(sets.CharacterBlacklist))
                {
                    char[] delim = {';'};
                    string[] blacklist = sets.CharacterBlacklist.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string c in blacklist)
                    {
                        filterMe = filterMe.Replace(c, ""); //Get rid of all those nasty nasty unicode chars
                    }
                    if (!fileName)
                    {
                        filterMe = filterMe.Replace("\r", "").Replace("\n", "\r\n"); //Fix the line endings for multiline pastes when logging
                    }
                }
                return filterMe; // HAVE AT THEE
            }
    

    I don't know what a List is (yet).

    Ideally I'd like to be able to auto-convert characters added to the textbox into \u format (so if you put f in the textbox and then saved, it would show as \u0066), but I'm getting confused in my head how that would work and how to read them back in
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  3. Post #43
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    ... a blacklist of unicode characters? There are hundred of thousands of unicode characters. What exactly are you trying to do?
    Reply With Quote Edit / Delete Windows 7 Norway Show Events Funny Funny x 1 (list)

  4. Post #44
    Gold Member
    Fire's Avatar
    October 2005
    1,520 Posts
    ... a blacklist of unicode characters? There are hundred of thousands of unicode characters. What exactly are you trying to do?
    It's user customizable (no way in hell I would maintain a generic blacklist of bad unicode chars), and it's for chat logging, so the logger just doesn't log those characters to file.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  5. Post #45
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    It's user customizable (no way in hell I would maintain a generic blacklist of bad unicode chars), and it's for chat logging, so the logger just doesn't log those characters to file.
    Why does the chat user want to maintain a blacklist of unicode characters for logging?
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  6. Post #46
    Gold Member
    Fire's Avatar
    October 2005
    1,520 Posts
    Why does the chat user want to maintain a blacklist of unicode characters for logging?
    Because people like to put certain special characters in their steam names and some of them royally fuck up (the ability to read) logging as a result.

    Can I actually get some help?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  7. Post #47
    Wyzard's Avatar
    June 2008
    1,243 Posts
    I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree

    like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered
    I visit WDYNHW regularly, and I think questions belong here, not in WAYWO.

    Actually, I don't think I read WAYWO v17 at all, because the level of "traffic" in WAYWO sometimes takes more time to read and respond to than I really want to devote to it.
    Reply With Quote Edit / Delete Linux United States Show Events

  8. Post #48
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    Because people like to put certain special characters in their steam names and some of them royally fuck up (the ability to read) logging as a result.
    You should convert the input string to UTF-32 (i.e. int[]), and also store the blacklist as a list of UTF-32 characters. That way you can simply compare their numeric values, and easily generate a string of the "\uXXXX" format should you need it.

    You can use the StringInfo class to convert a string to UTF-32 characters.

    Can I actually get some help?
    I wasn't insinuating that the user didn't need it, I genuinely wanted to know why.
    Reply With Quote Edit / Delete Windows 7 Norway Show Events

  9. Post #49
    MadPro119's Avatar
    January 2010
    5,900 Posts
    I really broke this. First time writing such a complex script (for me). The switch and cases are all messed up. Wants case 2: to become case 3; and wants else to become else;

    Its a while loop with a switch then a if then with another two ifs inside of that.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int hhp = 5;  //I'll just declare all (most) my variables here for safe keeping
                int mhp = 5;
                int mhp2;
                int mhp3;
                int hdmg;
                int mdmg;
                int nom;
                int fight;
                int name;
                int hacc;
                int def;
                string choice;
    
                string mname = "CRAP";
    
                Console.WriteLine("Text Based Battle System Tech Demo"); //intro text
                Console.ReadLine();
    
                Random nomr;  // How many monster will you fight, 1 - 3.
                nomr = new Random();
                nom = nomr.Next(1, 4);
    
                Random namer;  //Random Name
                namer = new Random();
                name = namer.Next(0, 4);
    
                if (nom == 1) //Random Naming 
                {
                    switch (name)
                    {
                        case 1:
                            mname = "Hogworm";
                            break;
                        case 2:
                            mname = "Boar";
                            break;
                        case 3:
                            mname = "Death Claw";
                            break;
                    }
                }
                else
                {
                    switch (name)
                    {
                        case 1:
                            mname = "Hogworms";
                            break;
                        case 2:
                            mname = "Boars";
                            break;
                        case 3:
                            mname = "Death Claws";
                            break;
                    }
                }
    
                Random fightr;  //If you find a fight
                fightr = new Random();
                fight = fightr.Next(1, 10);
    
                if (fight >= 1)
                {
                    Console.WriteLine("You encounter " + nom + " wild " + mname + ".");
                    Console.ReadLine();
                    
                }
                else
                {
                    Console.WriteLine("You dont encounter any enemies!");
                    Console.ReadLine();
                    goto A;
                }
    
                A:while (hhp>0 && fight>0 && hhp>0)
                {
                    switch (nom)
                    {
                        case 1:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            choice = Console.ReadLine();
                            if (choice == "attack" || choice == "Attack")
                            {
                                Random hdmgr;
                                hdmgr = new Random();
                                hdmg = hdmgr.Next(1, 25);
    
                                Random haccr;
                                haccr = new Random();
                                hacc = haccr.Next(0, 101);
                                
                                if (hacc >= 20) //I should add the monsters damage in here too.
                                {
                                    mhp = mhp - hdmg;
                                    Console.WriteLine(" Your attack hits the enemy. The monster has " + mhp + " health remaining");
                                    goto A;
                                }
                                else
                                {
                                    Console.WriteLine ("You miss the monster!");
                                    goto A;
                                }
                            else;
                            {
                                Random defr;
                                defr = new Random();
                                def = defr.Next(1, 101);
    
                                if (def >= 35)
                                {
                                    Console.WriteLine("You defended the enemy's attack!");
                                    goto A;
                                }
                                else
                                {
                                    mhp = mhp - hdmg;
                                    mhp = mhp + 5;
                                    Console.WriteLine ("You were unable to protect yourself from the attack!");
                                    goto A;
                                }
                            }
    
    
                            break;
                            case 2:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.ReadLine();
                            break;
                            case 3:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.ReadLine();
                            break;
                        default;
                            Console.WriteLine ("CRAP");
                            break;
                            }
                    }
                }
            }
        }
        }
    }}
    Lists 18 errors in it. Primarily

    ; expected on else and cases
    invalid expression term ':' on the cases
    invalid expression term 'case'
    invalid expression terme 'ese'
    Only assignment, call, increment, decrement, and new object expressions can be used as a statement
    Syntax error, '(' expected
    Type or namespace definition, or end-of-file expected
    Reply With Quote Edit / Delete Windows XP United States Show Events

  10. Post #50
    Icedshot's Avatar
    April 2010
    2,313 Posts
    A good idea is to start with the first error and fix that, because later errors can be caused by that one original error
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events Agree Agree x 2 (list)

  11. Post #51
    Gold Member
    esalaka's Avatar
    July 2007
    10,065 Posts
    I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree

    like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered
    It's usually the smaller problems that go here, as larger ones can often qualify as something you're working on for a longer time already.

    Edited:

    Did I just arrive a page late to the party?
    Reply With Quote Edit / Delete Linux Finland Show Events Agree Agree x 2 (list)

  12. Post #52
    evil-tedoz's Avatar
    October 2007
    128 Posts
    I really broke this. First time writing such a complex script (for me). The switch and cases are all messed up. Wants case 2: to become case 3; and wants else to become else;

    Its a while loop with a switch then a if then with another two ifs inside of that.


    Lists 18 errors in it. Primarily

    ; expected on else and cases
    invalid expression term ':' on the cases
    invalid expression term 'case'
    invalid expression terme 'ese'
    Only assignment, call, increment, decrement, and new object expressions can be used as a statement
    Syntax error, '(' expected
    Type or namespace definition, or end-of-file expected
    There's a " ; " on one of your else and the case default needs a " : ", not a " ; ".
    And why do you use goto ?
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Useful Useful x 1 (list)

  13. Post #53
    MadPro119's Avatar
    January 2010
    5,900 Posts
    There's a " ; " on one of your else and the case default needs a " : ", not a " ; ".
    And why do you use goto ?
    Not sure why I had the goto. I fixed the errors you mentioned and removed the goto. Now I am up to 22 errors just doing that.... Hmmm

    Edited:

    A good idea is to start with the first error and fix that, because later errors can be caused by that one original error
    Do you mean the first error you encounter or the first in the Error List (VS2010)?

    Edited:

    Okay got it down to 20 Errors.

    Edited:

    Fuck yes. 3 errors left

    Edited:

    Okay, 1 error left

    fix'd no errors

    Edited:

    Okay, still errors but at least it compiles now.
    Reply With Quote Edit / Delete Windows XP United States Show Events

  14. Post #54
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Can C# save/load a struct to file? I know it's possible in C++, I think I did fopen on the file, casted the pointer as a byte and then casted it as my struct and that filled the struct for me.

    However, I don't see a simple way to do it in C# - Maybe I'm just missing the function?

    Edited:

    Here's how I did it in C++
    Code:
    studiohdr_t *StudioModel::LoadModel(char *modelname)
    {
    	//If they didn't specify a modelname, return 0
    	if (!modelname)
    		return 0;
    
    	//Load the File as a pointer
    	FILE	*pFile;
    	long	size;
    	void	*buffer;
    
    	if( (pFile = fopen( modelname, "rb" )) == NULL)
    	{
    		//Couldn't read the file
    		return 0;
    	}
    
    	//Find the end of the file
    	fseek( pFile, 0, SEEK_END );
    
    	//Set the size as the end (Number of Bytes in the file)
    	size = ftell( pFile );
    
    	//Find the start of the file again
    	fseek( pFile, 0, SEEK_SET );
    
    	//Set the buffer to the memory allocated for the model
    	buffer = malloc( size );
    
    	if (!buffer)
    	{
    		//Couldn't allocate the memory for it
    		fclose( pFile ); //Close the file
    		return 0;
    	}
    
    	//Read the entire file (buffer = location in memory, 
    	//size = how much memory to read, 1 = how many 'blocks' of that
    	//much to read, and pFile = file to read
    	fread( buffer, size, 1, pFile );
    	fclose( pFile ); //Close the file
    
    	byte				*pin;
    	studiohdr_t			*phdr;
    	mstudiotexture_t	*ptexture;
    	char				*pCdtexture2;
    
    
    	//Version Header/ID
    	pin = (byte *)buffer;
    
    	//Cast the Version Header/ID as a studioheader struct.
    	phdr = (studiohdr_t *)pin;
    
    	//Texture
    	ptexture = (mstudiotexture_t *) (pin + phdr->textureindex );
    
    	pCdtexture2 = phdr->pCdtexture( 0 );
    
    	if (strncmp( (const char*) buffer, "IDST", 4) && strncmp( (const char*) buffer, "IDSQ", 4))
    	{
    		//ToDo: IDSQ is probably only a HL1 header. Don't need support for it.
    		//See studio_utils.cpp line 166 from real renderer
    
    		//strncmp
    		//A value greater than zero indicates that the first character that does not 
    		//match has a greater value in str1 than in str2; And a value less than zero 
    		//indicates the opposite.
    
    		//Wrong File Header!
    		MessageBoxA( NULL, "Wrong file header!", "MDL Loader", MB_OK );
    		free( buffer );
    		return 0;
    	}
    
    	if (phdr->textureindex > 0 && phdr->numtextures <= MAXSTUDIOSKINS )
    	{
    		int n = phdr->numtextures;
    		for ( int i = 0; i < n; i++)
    		{
    			if (!m_ptexturecd[i])
    				m_ptexturecd[i] = phdr->pCdtexture( i );
    		}
    	}
    
    	if (!m_pstudiohdr)
    		m_pstudiohdr = (studiohdr_t *) buffer;
    
    	if (!m_ptexturehdr)
    		m_ptexturehdr = (mstudiotexture_t *) (pin + phdr->textureindex );
    
    	return (studiohdr_t *)buffer;
    }
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  15. Post #55
    Gold Member
    conman420's Avatar
    January 2007
    1,794 Posts
    Whenever this code gets to the pixel 8, 27 I get a run time error saying "vector subscript out of range"

    void WorldGen::CreateWorld()
    {
    	for (int x=0; x < WorldSize.x; x++)
    	{
    		for (int y=0; y < WorldSize.y; y++)
    		{
    			sf::Color MapValue;
    			float Rand = PerlinNoise(x,y);
    			if (Rand > 1.f)
    				Rand = 1.f;
    			if (Rand < 0)
    				Rand = 0;
    			MapValue.r = floor(Rand * 255);
    			MapValue.g = floor(Rand * 255);
    			MapValue.b = floor(Rand * 255);
    			if (x > 7 && y > 26)
    				std::cout << "Break";
    			ImgTexture.SetPixel(x,y, MapValue);
    		}
    	}
    	Texture.SetImage(ImgTexture);
    	Texture.SetPosition(0,0);
    	Texture.SetScale(2.f,2.f);
    }
    

    The error is in the Image.SetPixel function itself where it tries to update the pixel (8, 27) but the image is 32 by 32. So this shouldn't be out of range. Anyone got a clue what is wrong?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  16. Post #56
    MadPro119's Avatar
    January 2010
    5,900 Posts
    God dammit. Its one if statement and it fucks me over for an hour

    Same code as before, well modified a bit. One if statement is giving me some troubles.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int hhp = 100;  //I'll just declare all (most) my variables here for safe keeping
                int mhp = 100;
                int mhp2 = 100;
                int mhp3 = 100;
                int hdmg;
                int mdmg;
                int nom;
                int fight;
                int name;
                int hacc;
                int macc;
                int def;
                string choice;
    
                string mname = "CRAP";
    
                A:Console.WriteLine("Text Based Battle System Tech Demo"); //intro text
                Console.ReadLine();
    
                Random nomr;  // How many monster will you fight, 1 - 3.
                nomr = new Random();
                nom = nomr.Next(1, 4);
    
                Random namer;  //Random Name
                namer = new Random();
                name = namer.Next(1, 4);
    
                if (nom == 1) //Random Naming 
                {
                    switch (name)
                    {
                        case 1:
                            mname = "Hogworm";
                            break;
                        case 2:
                            mname = "Boar";
                            break;
                        case 3:
                            mname = "Death Claw";
                            break;
                    }
                }
                else
                {
                    switch (name)
                    {
                        case 1:
                            mname = "Hogworms";
                            break;
                        case 2:
                            mname = "Boars";
                            break;
                        case 3:
                            mname = "Death Claws";
                            break;
                    }
                }
    
                Random fightr;  //If you find a fight
                fightr = new Random();
                fight = fightr.Next(1, 10);
    
                if (fight >= 1)
                {
                    Console.WriteLine("You encounter " + nom + " wild " + mname + ".");
                    Console.ReadLine();
                    
                }
                else
                {
                    Console.WriteLine("You dont encounter any enemies!");
                    Console.ReadLine();
                    goto A;
                    
                }
    
                while (hhp>0 && fight>0 && hhp>0)
                {
                    switch (nom)
                    {
                        case 1:
                    B:Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.WriteLine("Monster's Health " + mhp + ".");
                            choice = Console.ReadLine();
                            if (choice == "attack" || choice == "Attack")
                            {
                                Random hdmgr;
                                hdmgr = new Random();
                                hdmg = hdmgr.Next(1, 25);
    
                                Random haccr;
                                haccr = new Random();
                                hacc = haccr.Next(0, 101);
    
                                if (hacc >= 20) //I should add the monsters damage in here too.
                                {
                                    mhp = mhp - hdmg;
                                    Console.WriteLine("Your attack hits the enemy. The monster has " + mhp + " health remaining");
    
                                    Random mdmgr;
                                    mdmgr = new Random();
                                    mdmg = mdmgr.Next(1, 25)- hdmg;
    
                                    hhp = hhp - mdmg;
    
                                    switch (hdmg)
                                    {
                                        case (hdmg>=1 && hdmg <=4):
                                            hhp = hhp - mdmg;
                                            hhp = hhp - 5;
                                            Console.WriteLine("Your weak attack barely hurts the monster who strikes back with ease for " +(mdmg+5)+" damage");
                                            break;
                                        case (hdmg>=5 && hdmg <=16):
                                            Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 40)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster powers on attacking you for " +mdmg+ " health.");
                                            }
                                            else
                                            {
                                                Console.WriteLine("The monster misses it's attack!");
                                            }
                                            break;
                                            case (hdmg>=17):
                                            Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
                                            break;
    
                                    
                                    }
                                else
                                {
                                    Console.WriteLine("You miss the monster!");
                                     Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 15)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster hits you for " +mdmg+" health.");
                                            }
                                }
                                    
                                }
                                }
                            else
                            {
                                Random defr;
                                defr = new Random();
                                def = defr.Next(1, 101);
    
                                if (def >= 35 && choice == "defend" || choice == "Defend")
                                {
                                    Console.WriteLine("You defended the enemy's attack!");
                                    
                                }
                                else if (choice == "defend" || choice == "Defend")
                                {
                                    Random hdmgr;
                                    hdmgr = new Random();
                                    hdmg = hdmgr.Next(1, 25);
    
                                    Random mdmgr;
                                    mdmgr = new Random();
                                    mdmg = mdmgr.Next(5, 11);
    
                                    hhp = hhp - mdmg;
                                    Console.WriteLine ("You were unable to protect yourself from the attack but took less damage!");
                                }
                                else
                                {
                                    Console.WriteLine("That is not a valid choice");
                                    goto B;
                                    
                                }
                            }
                            break;
                            case 2:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.ReadLine();
                            break;
                            case 3:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.ReadLine();
                            break;
                            default:
                            Console.WriteLine ("CRAP");
                            break;
                            }
                    }
                }
            }
        }
    Edited:

    The else I bolded is the one giving me problems.

    Edited:

    Error 1 Invalid expression term 'else' 146 29 Text Based Battle System

    Edited:

    And also it seems to think in the switch and cases involving hdmg that they are bools?

    Error 3 Cannot implicitly convert type 'bool' to 'int' 121 43 Text Based Battle System
    Reply With Quote Edit / Delete Windows XP United States Show Events

  17. Post #57
    Richy19's Avatar
    May 2010
    5,368 Posts
    God dammit. Its one if statement and it fucks me over for an hour

    Same code as before, well modified a bit. One if statement is giving me some troubles.

    Edited:

    The else I bolded is the one giving me problems.

    Edited:

    Error 1 Invalid expression term 'else' 146 29 Text Based Battle System
    Dude, seriously? ...

    Your missing a } before the else
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  18. Post #58

    May 2011
    4 Posts
    I'm working on an XNA game library and I have absolutely no idea how I'm going to compile content to the XNB Format.
    Basically I'm making a tool to convert images & xml to xnb.
    Reply With Quote Edit / Delete Windows 7 Malta Show Events

  19. Post #59
    MadPro119's Avatar
    January 2010
    5,900 Posts
    Dude, seriously? ...

    Your missing a } before the else
    Are you sure?

    Like this?

    Code:
                   Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
                                            break;
    
                                    
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("You miss the monster!");
                                     Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 15)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster hits you for " +mdmg+" health.");
                                            }
    That outputs an error. I'm probly just and idiot.

    Edited:

    Or is that the wrong else?
    Reply With Quote Edit / Delete Windows XP United States Show Events

  20. Post #60
    Richy19's Avatar
    May 2010
    5,368 Posts
    I'm working on an XNA game library and I have absolutely no idea how I'm going to compile content to the XNB Format.
    Basically I'm making a tool to convert images & xml to xnb.
    Is there meant to be a question in there?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Funny Funny x 1Agree Agree x 1 (list)

  21. Post #61

    May 2011
    4 Posts
    Can C# save/load a struct to file? I know it's possible in C++, I think I did fopen on the file, casted the pointer as a byte and then casted it as my struct and that filled the struct for me.

    However, I don't see a simple way to do it in C# - Maybe I'm just missing the function?

    Edited:

    Here's how I did it in C++
    Code:
    studiohdr_t *StudioModel::LoadModel(char *modelname)
    {
    	//If they didn't specify a modelname, return 0
    	if (!modelname)
    		return 0;
    
    	//Load the File as a pointer
    	FILE	*pFile;
    	long	size;
    	void	*buffer;
    
    	if( (pFile = fopen( modelname, "rb" )) == NULL)
    	{
    		//Couldn't read the file
    		return 0;
    	}
    
    	//Find the end of the file
    	fseek( pFile, 0, SEEK_END );
    
    	//Set the size as the end (Number of Bytes in the file)
    	size = ftell( pFile );
    
    	//Find the start of the file again
    	fseek( pFile, 0, SEEK_SET );
    
    	//Set the buffer to the memory allocated for the model
    	buffer = malloc( size );
    
    	if (!buffer)
    	{
    		//Couldn't allocate the memory for it
    		fclose( pFile ); //Close the file
    		return 0;
    	}
    
    	//Read the entire file (buffer = location in memory, 
    	//size = how much memory to read, 1 = how many 'blocks' of that
    	//much to read, and pFile = file to read
    	fread( buffer, size, 1, pFile );
    	fclose( pFile ); //Close the file
    
    	byte				*pin;
    	studiohdr_t			*phdr;
    	mstudiotexture_t	*ptexture;
    	char				*pCdtexture2;
    
    
    	//Version Header/ID
    	pin = (byte *)buffer;
    
    	//Cast the Version Header/ID as a studioheader struct.
    	phdr = (studiohdr_t *)pin;
    
    	//Texture
    	ptexture = (mstudiotexture_t *) (pin + phdr->textureindex );
    
    	pCdtexture2 = phdr->pCdtexture( 0 );
    
    	if (strncmp( (const char*) buffer, "IDST", 4) && strncmp( (const char*) buffer, "IDSQ", 4))
    	{
    		//ToDo: IDSQ is probably only a HL1 header. Don't need support for it.
    		//See studio_utils.cpp line 166 from real renderer
    
    		//strncmp
    		//A value greater than zero indicates that the first character that does not 
    		//match has a greater value in str1 than in str2; And a value less than zero 
    		//indicates the opposite.
    
    		//Wrong File Header!
    		MessageBoxA( NULL, "Wrong file header!", "MDL Loader", MB_OK );
    		free( buffer );
    		return 0;
    	}
    
    	if (phdr->textureindex > 0 && phdr->numtextures <= MAXSTUDIOSKINS )
    	{
    		int n = phdr->numtextures;
    		for ( int i = 0; i < n; i++)
    		{
    			if (!m_ptexturecd[i])
    				m_ptexturecd[i] = phdr->pCdtexture( i );
    		}
    	}
    
    	if (!m_pstudiohdr)
    		m_pstudiohdr = (studiohdr_t *) buffer;
    
    	if (!m_ptexturehdr)
    		m_ptexturehdr = (mstudiotexture_t *) (pin + phdr->textureindex );
    
    	return (studiohdr_t *)buffer;
    }

    Save the struct:
    Code:
    XmlSerializer writer = new XmlSerializer(mystruct.GetType());
       StreamWriter file = new StreamWriter("filename.xml");
       writer.Serialize(file, mystruct);
       file.Close();
    Load the struct:
    Code:
    XmlSerializer reader= new XmlSerializer(mystruct.GetType());
       StreamWriter file = new StreamWriter("filename.xml");
       return reader.DeSerialize(file, mystruct);
       file.Close();
    Reply With Quote Edit / Delete Windows 7 Malta Show Events Programming King Programming King x 1 (list)

  22. Post #62
    Richy19's Avatar
    May 2010
    5,368 Posts
    Are you sure?

    Like this?



    That outputs an error. I'm probly just and idiot.

    Edited:

    Or is that the wrong else?
    if (hacc >= 20) //I should add the monsters damage in here too.
                                {
                                    mhp = mhp - hdmg;
                                    Console.WriteLine("Your attack hits the enemy. The monster has " + mhp + " health remaining");
    
                                    Random mdmgr;
                                    mdmgr = new Random();
                                    mdmg = mdmgr.Next(1, 25)- hdmg;
    
                                    hhp = hhp - mdmg;
    
                                    switch (hdmg)
                                    {
                                        case (hdmg>=1 && hdmg <=4):
                                            hhp = hhp - mdmg;
                                            hhp = hhp - 5;
                                            Console.WriteLine("Your weak attack barely hurts the monster who strikes back with ease for " +(mdmg+5)+" damage");
                                            break;
                                        case (hdmg>=5 && hdmg <=16):
                                            Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 40)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster powers on attacking you for " +mdmg+ " health.");
                                            }
                                            else
                                            {
                                                Console.WriteLine("The monster misses it's attack!");
                                            }
                                            break;
                                            case (hdmg>=17):
                                            Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
                                            break;
    
                                    
                                    }
                                else
                                {
    

    Well there the first if never ends

    Also you probably have an extra } after that else
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  23. Post #63

    May 2011
    4 Posts
    Is there meant to be a question in there?
    The question is:
    How do i create XNB files from images or xml files using MSBuild?
    Reply With Quote Edit / Delete Windows 7 Malta Show Events

  24. Post #64
    Fox-Face's Avatar
    June 2008
    244 Posts
    Can C# save/load a struct to file? I know it's possible in C++, I think I did fopen on the file, casted the pointer as a byte and then casted it as my struct and that filled the struct for me.

    However, I don't see a simple way to do it in C# - Maybe I'm just missing the function?
    Reference the following namespaces: System.Runtime.Serialization and System.Runtime.Serialization.Formatters.Binary then do this:

    First mark your struct as Serializable (Put a [Serializable] before the struct declaration), then you need
    to implement the ISerializeable interface and add a new constructor:

            public Something(SerializationInfo info, StreamingContext context)
            {
                Name = info.GetString("Name");
                Id = info.GetInt32("Id");
            }
            //ISerializeable member
            public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                info.AddValue("Name", Name);
                info.AddValue("Id", Id);
            }

    Then to serialize you can use a BinaryFormatter, here's some handy functions:


            public static void Serialize(string destFilePath, ISerializable obj)
            {
                using (Stream fstream = File.Open(destFilePath, FileMode.Create))
                {
                    BinaryFormatter bformatter = new BinaryFormatter();
                    bformatter.Serialize(fstream, obj);
                    fstream.Close();
                }
            }
    
            public static T UnSerialize<T>(string filePath) where T : ISerializable
            {
                using (Stream fstream = File.Open(filePath, FileMode.Open))
                {
                    BinaryFormatter bformat = new BinaryFormatter();
                    T obj = (T)bformat.Deserialize(fstream);
                    fstream.Close();
                    return obj;
                }
            }
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events

  25. Post #65
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    I'm working on an XNA game library and I have absolutely no idea how I'm going to compile content to the XNB Format.
    Basically I'm making a tool to convert images & xml to xnb.
    Why's that? If you import it into the Content part of your project, they'll be compiled into xnb assets on compile. That being said, there's an example on MSDN about loading content (Mostly models) in real time - It compiles it and saves it temporarily.

    Fox-Face that makes no sense without any formatting.

    Kukks: XML :(
    I'm probably going to be storing a lot of floats, so I'd want a binary format, no? (Binary just to save time/space, not specifically cause of lots of floats)
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  26. Post #66
    MadPro119's Avatar
    January 2010
    5,900 Posts
    if (hacc >= 20) //I should add the monsters damage in here too.
                                {
                                    mhp = mhp - hdmg;
                                    Console.WriteLine("Your attack hits the enemy. The monster has " + mhp + " health remaining");
    
                                    Random mdmgr;
                                    mdmgr = new Random();
                                    mdmg = mdmgr.Next(1, 25)- hdmg;
    
                                    hhp = hhp - mdmg;
    
                                    switch (hdmg)
                                    {
                                        case (hdmg>=1 && hdmg <=4):
                                            hhp = hhp - mdmg;
                                            hhp = hhp - 5;
                                            Console.WriteLine("Your weak attack barely hurts the monster who strikes back with ease for " +(mdmg+5)+" damage");
                                            break;
                                        case (hdmg>=5 && hdmg <=16):
                                            Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 40)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster powers on attacking you for " +mdmg+ " health.");
                                            }
                                            else
                                            {
                                                Console.WriteLine("The monster misses it's attack!");
                                            }
                                            break;
                                            case (hdmg>=17):
                                            Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
                                            break;
    
                                    
                                    }
                                else
                                {
    

    Well there the first if never ends

    Also you probably have an extra } after that else
    What you said there really didnt make sense to me.

    Although I replaced my code with yours and it didnt fix anything.
    Reply With Quote Edit / Delete Windows XP United States Show Events

  27. Post #67
    Fox-Face's Avatar
    June 2008
    244 Posts
    Fox-Face that makes no sense without any formatting.
    Yea I broke the code box by mistake should be good now.
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events

  28. Post #68
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Yea I broke the code box by mistake should be good now.
    So you Sereialize data, and then write the sereialized data to file, then to load you load serealized data, and unserealize it?

    I'm not quite following what I have to do here. Based on "then you need to implement the ISerializeable interface and add a new constructor", I want to make a new class that extensd ISerealizeable with that constructor in it, and then make a new instance of the class to serealize my data?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  29. Post #69

    May 2011
    4 Posts
    Why's that? If you import it into the Content part of your project, they'll be compiled into xnb assets on compile. That being said, there's an example on MSDN about loading content (Mostly models) in real time - It compiles it and saves it temporarily.

    Fox-Face that makes no sense without any formatting.

    Kukks: XML :(
    I'm probably going to be storing a lot of floats, so I'd want a binary format, no? (Binary just to save time/space, not specifically cause of lots of floats)

    I didn't understand that example all that well and basically I'm aiming for a flexible dynamic library that doesn't require you to add content beforehand..


    Regarding your prob
    I've never had any performance issues with XML and I have no idea how to automatically serialize to a binary format so sorry :/
    Reply With Quote Edit / Delete Windows 7 Malta Show Events

  30. Post #70
    Fox-Face's Avatar
    June 2008
    244 Posts
    So you Sereialize data, and then write the sereialized data to file, then to load you load serealized data, and unserealize it?

    I'm not quite following what I have to do here. Based on "then you need to implement the ISerializeable interface and add a new constructor", I want to make a new class that extensd ISerealizeable with that constructor in it, and then make a new instance of the class to serealize my data?
    Let me post a quick example, hang on

    Here:
    [Serializable]
        public struct Something : ISerializable
        {
            public string Name;
            public int Id;
    
            public Something(string Name, int ID)
            {
                this.Name = Name;
                this.Id = ID;
            }
    
            public Something(SerializationInfo info, StreamingContext context)
            {
                Name = info.GetString("Name");
                Id = info.GetInt32("Id");
            }
            //ISerializeable member
            public void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                info.AddValue("Name", Name);
                info.AddValue("Id", Id);
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Something s = new Something("Bla", 1);
                Serializer.Serialize("test", s);
    
                Something s2 = Serializer.UnSerialize<Something>("test");
                Console.WriteLine(s2.Name);
            }
        }
    
        public class Serializer
        {
            public static void Serialize(string destFilePath, ISerializable obj)
            {
                using (Stream fstream = File.Open(destFilePath, FileMode.Create))
                {
                    BinaryFormatter bformatter = new BinaryFormatter();
                    bformatter.Serialize(fstream, obj);
                    fstream.Close();
                }
            }
    
            public static T UnSerialize<T>(string filePath) where T : ISerializable
            {
                using (Stream fstream = File.Open(filePath, FileMode.Open))
                {
                    BinaryFormatter bformat = new BinaryFormatter();
                    T obj = (T)bformat.Deserialize(fstream);
                    fstream.Close();
    
                    return obj;
                }
            }
        }

    You need to implement ISerializeable in your struct, which will contan only the GetObjectData method, this will be used by the BinaryFormatter to serialize your struct, and the constructor will be used by it to unserialize, then you just pass the object to it.
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events Programming King Programming King x 1 (list)

  31. Post #71
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    I didn't understand that example all that well and basically I'm aiming for a flexible dynamic library that doesn't require you to add content beforehand..
    Let me know how this works out. You can load Texture's at run time, and it's possible to load ASCII *FBX files. However you'll have to write your own importer.

    See here for an overview: http://thunderfist-podium.blogspot.c...om-loader.html

    That's really the biggest flaw I see with XNA right now. Makes modding very hard.

    Let me post a quick example, hang on
    Oh god I would have done it terribly, terribly wrong. :(

    Thanks for that, I'll go implement it after I get rendering up and running again.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  32. Post #72
    Richy19's Avatar
    May 2010
    5,368 Posts
    What you said there really didnt make sense to me.

    Although I replaced my code with yours and it didnt fix anything.
    because i didnt change anything

    try this
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int hhp = 100;  //I'll just declare all (most) my variables here for safe keeping
                int mhp = 100;
                int mhp2 = 100;
                int mhp3 = 100;
                int hdmg;
                int mdmg;
                int nom;
                int fight;
                int name;
                int hacc;
                int macc;
                int def;
                string choice;
    
                string mname = "CRAP";
    
                A:Console.WriteLine("Text Based Battle System Tech Demo"); //intro text
                Console.ReadLine();
    
                Random nomr;  // How many monster will you fight, 1 - 3.
                nomr = new Random();
                nom = nomr.Next(1, 4);
    
                Random namer;  //Random Name
                namer = new Random();
                name = namer.Next(1, 4);
    
                if (nom == 1) //Random Naming 
                {
                    switch (name)
                    {
                        case 1:
                            mname = "Hogworm";
                            break;
                        case 2:
                            mname = "Boar";
                            break;
                        case 3:
                            mname = "Death Claw";
                            break;
                    }
                }
                else
                {
                    switch (name)
                    {
                        case 1:
                            mname = "Hogworms";
                            break;
                        case 2:
                            mname = "Boars";
                            break;
                        case 3:
                            mname = "Death Claws";
                            break;
                    }
                }
    
                Random fightr;  //If you find a fight
                fightr = new Random();
                fight = fightr.Next(1, 10);
    
                if (fight >= 1)
                {
                    Console.WriteLine("You encounter " + nom + " wild " + mname + ".");
                    Console.ReadLine();
                    
                }
                else
                {
                    Console.WriteLine("You dont encounter any enemies!");
                    Console.ReadLine();
                    goto A;
                    
                }
    
                while (hhp>0 && fight>0 && hhp>0)
                {
                    switch (nom)
                    {
                        case 1:
                    B:Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.WriteLine("Monster's Health " + mhp + ".");
                            choice = Console.ReadLine();
                            if (choice == "attack" || choice == "Attack")
                            {
                                Random hdmgr;
                                hdmgr = new Random();
                                hdmg = hdmgr.Next(1, 25);
    
                                Random haccr;
                                haccr = new Random();
                                hacc = haccr.Next(0, 101);
    
                                if (hacc >= 20) //I should add the monsters damage in here too.
                                {
                                    mhp = mhp - hdmg;
                                    Console.WriteLine("Your attack hits the enemy. The monster has " + mhp + " health remaining");
    
                                    Random mdmgr;
                                    mdmgr = new Random();
                                    mdmg = mdmgr.Next(1, 25)- hdmg;
    
                                    hhp = hhp - mdmg;
    
                                    switch (hdmg)
                                    {
                                        case (hdmg>=1 && hdmg <=4):
                                            hhp = hhp - mdmg;
                                            hhp = hhp - 5;
                                            Console.WriteLine("Your weak attack barely hurts the monster who strikes back with ease for " +(mdmg+5)+" damage");
                                            break;
                                        case (hdmg>=5 && hdmg <=16):
                                            Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 40)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster powers on attacking you for " +mdmg+ " health.");
                                            }
                                            else
                                            {
                                                Console.WriteLine("The monster misses it's attack!");
                                            }
                                            break;
                                            case (hdmg>=17):
                                            Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
                                            break;
    
                                    
                                    }
    }
                                else
                                {
                                    Console.WriteLine("You miss the monster!");
                                     Random maccr;
                                            maccr = new Random();
                                            macc = maccr.Next (1, 100);
                                            if (macc >= 15)
                                            {
                                                hhp = hhp - mdmg;
                                                Console.WriteLine("The monster hits you for " +mdmg+" health.");
                                            }
                                }
                                    
                                }
                                
                            else
                            {
                                Random defr;
                                defr = new Random();
                                def = defr.Next(1, 101);
    
                                if (def >= 35 && choice == "defend" || choice == "Defend")
                                {
                                    Console.WriteLine("You defended the enemy's attack!");
                                    
                                }
                                else if (choice == "defend" || choice == "Defend")
                                {
                                    Random hdmgr;
                                    hdmgr = new Random();
                                    hdmg = hdmgr.Next(1, 25);
    
                                    Random mdmgr;
                                    mdmgr = new Random();
                                    mdmg = mdmgr.Next(5, 11);
    
                                    hhp = hhp - mdmg;
                                    Console.WriteLine ("You were unable to protect yourself from the attack but took less damage!");
                                }
                                else
                                {
                                    Console.WriteLine("That is not a valid choice");
                                    goto B;
                                    
                                }
                            }
                            break;
                            case 2:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.ReadLine();
                            break;
                            case 3:
                            Console.WriteLine("What would you like to do?");
                            Console.WriteLine("attack ---- defend");
                            Console.WriteLine("Health " + hhp + ".");
                            Console.ReadLine();
                            break;
                            default:
                            Console.WriteLine ("CRAP");
                            break;
                            }
                    }
                }
            }
        }
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Useful Useful x 1 (list)

  33. Post #73
    Samuka97's Avatar
    April 2007
    1,982 Posts
    How would I go about limiting the number of characters in a std::string to a specific number/pixel length? (C++, Code::Blocks, SFML2)
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events

  34. Post #74
    MadPro119's Avatar
    January 2010
    5,900 Posts
    Thank you so much! That fixed the else statement, now I just need to figure out why it thinks hdmg in the cases is a bool and not a int

    (Error 1 Cannot implicitly convert type 'bool' to 'int' 121 43 Text Based Battle System)
    Reply With Quote Edit / Delete Windows XP United States Show Events

  35. Post #75
    Richy19's Avatar
    May 2010
    5,368 Posts
    Thank you so much! That fixed the else statement, now I just need to figure out why it thinks hdmg in the cases is a bool and not a int

    (Error 1 Cannot implicitly convert type 'bool' to 'int' 121 43 Text Based Battle System)
    In your switch your telling it to compare it to an int
    but your case is a bool (hdmg>=1 && hdmg <=4)
    Your best using an if statement there

    Edited:

    Thank you so much! That fixed the else statement, now I just need to figure out why it thinks hdmg in the cases is a bool and not a int

    (Error 1 Cannot implicitly convert type 'bool' to 'int' 121 43 Text Based Battle System)
    In your switch your telling it to compare it to an int
    but your case is a bool (hdmg>=1 && hdmg <=4)
    Your best using an if statement there
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Useful Useful x 1 (list)

  36. Post #76
    Gold Member
    ZeekyHBomb's Avatar
    June 2006
    3,577 Posts
    How would I go about limiting the number of characters in a std::string to a specific number/pixel length?(C++, Code::Blocks, SFML2)
    For monospaced fonts you can do
    static const float singleCharLength = sf::Text("a", font, size).GetRect().Width;
    const std::size_t length = static_cast<std::size_t>(desiredLength / singleCharLength);
    if(string.size() > length)
        string.resize(length);
    For variable-spaced fonts it's not so fun, since each letter can have a different length. You should probably make an educated guess on the medium size and go from there.
    Reply With Quote Edit / Delete Linux Germany Show Events

  37. Post #77
    Samuka97's Avatar
    April 2007
    1,982 Posts
    For monospaced fonts you can do
    static const float singleCharLength = sf::Text("a", font, size).GetRect().Width;
    const std::size_t length = static_cast<std::size_t>(desiredLength / singleCharLength);
    if(string.size() > length)
        string.resize(length);
    For variable-spaced fonts it's not so fun, since each letter can have a different length. You should probably make an educated guess on the medium size and go from there.
    For that to work, what do I need to change exactly?
    Edit: Nevermind, I'm stupid. Thanks!
    Reply With Quote Edit / Delete Windows 7 Brazil Show Events

  38. Post #78
    MadPro119's Avatar
    January 2010
    5,900 Posts
    In your switch your telling it to compare it to an int
    but your case is a bool (hdmg>=1 && hdmg <=4)
    Your best using an if statement there

    Edited:



    In your switch your telling it to compare it to an int
    but your case is a bool (hdmg>=1 && hdmg <=4)
    Your best using an if statement there
    Thank you good sir! I studied the switch you made with the else than changed my whole switch to a an if like you said!
    Reply With Quote Edit / Delete Windows XP United States Show Events

  39. Post #79
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Let me post a quick example, hang on

    Here:

    You need to implement ISerializeable in your struct, which will contan only the GetObjectData method, this will be used by the BinaryFormatter to serialize your struct, and the constructor will be used by it to unserialize, then you just pass the object to it.
    How would you Serialize a 2D array of floats, or a 2d array of a Vector3 class?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  40. Post #80
    Gold Member
    ewitwins's Avatar
    December 2009
    14,071 Posts
    Considering this is a thread partially about Java, I thought I'd toss my problem out in the open.

    Whenever I try and use the command javac, my command prompt spits back a nasty message saying "'javac' is not recognized as an internal or external command, operable program or batch file".

    I checked to see if I had my eggs in the right basket with a quick java -version, and it spat back my version information correctly. Here's where I have my Java installed:

    C:\Program Files\Java\jre6
    C:\Program Files\Java\jdk1.6.0_25
    Reply With Quote Edit / Delete Windows Vista United States Show Events