11 Replies - 995 Views - Last Post: 15 January 2010 - 02:39 PM Rate Topic: -----

#1 popshot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 13-January 10

Error With Sound in C++

Posted 15 January 2010 - 02:02 PM

Well i added all these includes, and when i run my program I get this error everywhere I tried to play sound.

1>c:\users\kevin\documents\visual studio 2010\projects\true rpg\true rpg\main.cpp(39): error C2065: 'SND_ASYNC' : undeclared identifier


#include <cstdlib>
#include <cstdio>
#include <string>
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib,"Winmm.lib")


Is This A Good Question/Topic? 0
  • +

Replies To: Error With Sound in C++

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Error With Sound in C++

Posted 15 January 2010 - 02:15 PM

Try to include windows.h and mmsystem.h first.
Was This Post Helpful? 0
  • +
  • -

#3 popshot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 13-January 10

Re: Error With Sound in C++

Posted 15 January 2010 - 02:16 PM

View Postsarmanu, on 15 Jan, 2010 - 01:15 PM, said:

Try to include windows.h and mmsystem.h first.


I put them first and still nothing
Was This Post Helpful? 0
  • +
  • -

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Error With Sound in C++

Posted 15 January 2010 - 02:18 PM

Oh wait, you need to include <mmsystem.h> in every source file where PlaySound is used!
Was This Post Helpful? 0
  • +
  • -

#5 popshot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 13-January 10

Re: Error With Sound in C++

Posted 15 January 2010 - 02:19 PM

View Postsarmanu, on 15 Jan, 2010 - 01:18 PM, said:

Oh wait, you need to include <mmsystem.h> in every source file where PlaySound is used!


I only have one source file and it is in there
Was This Post Helpful? 0
  • +
  • -

#6 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Error With Sound in C++

Posted 15 January 2010 - 02:21 PM

Yea, my bad. I just saw your RPG, from the other topic. So I have copied it & compile & ran it without a problem! I'm using Visual Studio 2008, and I'm not sure about your problem ...
EDIT: Right click on SND_ASYNC, the click on Go To Definition. If it opens mmsystem.h, then SND_ASYNC is defined there, but somehow it won't get "extracted" by the compiler. If it won't, then somehow it is missing

This post has been edited by sarmanu: 15 January 2010 - 02:23 PM

Was This Post Helpful? 0
  • +
  • -

#7 popshot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 13-January 10

Re: Error With Sound in C++

Posted 15 January 2010 - 02:23 PM

View Postsarmanu, on 15 Jan, 2010 - 01:21 PM, said:

Yea, my bad. I just saw your RPG, from the other topic. So I have copied it & compile & ran it without a problem! I'm using Visual Studio 2008, and I'm not sure about your problem ...
EDIT: Right click on SND_ASYNC, the click on Go To Definition. If it opens mmsystem.h, then SND_ASYNC is defined there, but somehow it won't get "extracted" by the compiler. If it won't, then somehow it is missing


well i have changed it a bit because it would not run earlier. This is it now. Added level system and stuff today at school and it worked, but wont here. I think it has to do with my windows 7

#include <conio.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#include <cstdlib>
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int intName;
int intNameChoice;
int intStatChoice;
int intTownChoice;

string strName;
string strPass;

int intCharChoice;
int intStrength;
int intDexterity;
int intVitality;
int intHealth;
int intExperience;
int intLevel = 1;
int intExpNeeded = intLevel * 5;

int intGold;
int intPay;
int intWorkHours;

void LevelFunction()//Runs when you level up
{
	if (intExperience >= intLevel * 5) //If your experience is equal to your level X 50	 then you level up.
	{
		intExperience = intExperience - intLevel * 5; //Puts all your experience back		 to 0 but keeps the leftover eg. 157/150 would be 7/300 for next level.
		intLevel = intLevel + 1;
		PlaySound("mastersword.wav", NULL, SND_FILENAME | SND_ASYNC); 
		Sleep(3);
		PlaySound("mastersword.wav", NULL, SND_FILENAME | SND_PURGE); 
		cout << "You gained a level\n";
		cout << "You gained 5 to all your stats\n";
		intStrength = intStrength + 5;
		intDexterity = intDexterity +5;
		intVitality = intVitality +5;
		return;
	}
}


void setcolor(unsigned short color)				 //The function that you'll use to
{												   //set the colour
	HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hcon,color);
}
void cls(){
	COORD coordScreen = { 0, 0 }; 
	DWORD cCharsWritten; 
	CONSOLE_SCREEN_BUFFER_INFO csbi; 
	DWORD dwConSize; 
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);  // Handle to stdout

	// Gets the console resolution
	GetConsoleScreenBufferInfo(hConsole, &csbi); 
	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
	// Fill every cell with spaces
	FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
	// Fill the console attributes
	FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
	// Sets the cursor position back to the first row and column
	SetConsoleCursorPosition(hConsole, coordScreen); 
	system("CLS");
}
void Name()
{
	setcolor(15);
	cout << "Do you have a name and password already? " << endl;
	cout << "1. Yes\n2. No" << endl;
	cin >> intNameChoice;

	if (intNameChoice == 1)
	{
		cout << " What was your name? " << endl;
		cin >> strName;
		cout << "Good what was your password? " << endl;
		cin >> strPass;
		cout << "Account Loaded" << endl;
	}


	if (intNameChoice == 2)
	{
		cout << "Time to create your account" << endl;
		cout << "Enter your account name " << endl;
		cin >> strName;
		cout << "Good now enter your password " << endl;
		cin >> strPass;
	}
}

void CreateChar()
{
	for(;;)
	{
		setcolor(15);
		cout << "Now would you like to be a\n1. Archer\n2. Paladin\n3. Druid\n" << endl;
		cin >> intCharChoice;

		if (intCharChoice == 1)
		{

			cout << "You choose to be a gracious Archer " << endl;
			cout << "Your stats will be " << endl;
			cout << "Strength = 15\nDexterity = 25\nVitality = 10 " <<endl;
			cout << "Is this ok?\n1. Yes\n2. No " << endl;
			cin >> intStatChoice;
		}

		if (intStatChoice == 1)
		{
			intStrength = 20;
			intDexterity = 25;
			intVitality = 10;
			cout << "Stats are now set\n\n";
			break;
		}
		else if (intStatChoice == 2)
		{
			continue;
		}

		else if (intCharChoice == 2)
		{

			cout << "You choose to be a powerful Paladin " << endl;
			cout << "Your stats will be " << endl;
			cout << "Strength = 25\nDexterity = 10\nVitality = 15 " <<endl;
			cout << "Is this ok?\n1. Yes\n2. No " << endl;
			cin >> intStatChoice;
		}

		if (intStatChoice == 1)
		{
			intStrength = 25;
			intDexterity = 10;
			intVitality = 15;
			cout << "Stats are now set\n\n";
			break;
		}
		else if (intStatChoice == 2)
		{
			continue;
		}

		else if (intCharChoice == 3)
		{

			cout << "You choose to be a cunning Druid " << endl;
			cout << "Your stats will be " << endl;
			cout << "Strength = 15\nDexterity = 25\nVitality = 10 " <<endl;
			cout << "Is this ok?\n1. Yes\n2. No " << endl;
			cin >> intStatChoice;
		}

		if (intStatChoice == 1)
		{
			intStrength = 15;
			intDexterity = 25;
			intVitality = 10;
			cout << "Stats are now set\n\n";
			break;
		}
		else if (intStatChoice == 2)
		{
			continue;
		}
	}

}



int main()


{

	int intWorkHour;

	int intWeapShopChoice;
	int intUpgradeChoice;
	int intBattleChoice;

	int intSwordCost;
	intSwordCost = 0;

	int intBowCost;
	intBowCost = 0;

	int intMaceCost;
	intMaceCost = 0;

	int intSwordLevel;
	intSwordLevel = 1;

	int intBowLevel;
	intBowLevel = 1;

	int intMaceLevel;
	intMaceLevel = 1;

	int intHealth;

	int Sword_Damage = (rand() % 10)  + intSwordLevel;
	int Mace_Damage = (rand() % 13) + + intMaceLevel;
	int Bow_Damage = (rand() % 15) + + intBowLevel;
	int Gobling_Health = 500;
	int Gobling_Damage = 5;
	int Gobling_Exp = 5;
	int Troll_Health = 1000;
	int Troll_Damage = 10;
	int Troll_Exp = 15;
	int bonus_10 = 10;

	PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC); 

	Name();
	cls();
	CreateChar();
	cls();
	setcolor(14);
	cout << "\t\t\tWelcome To The Rogue Encampment!\n\n\n";

	setcolor(15);

	{   //Displays users attack, defence, and gold on the screen
		int intHealth = (intVitality) * (25);


		for (;;)
		{

			LevelFunction();

			cout << "\nHealth: " << intHealth << "\nStrength: " << intStrength <<"\nDexterity: " << intDexterity << "\nLevel: " << intLevel << "\nExperience: " << intExperience << "/" << intExpNeeded <<"\nGold: " << intGold <<"\n\n";



			//Asks user what they would like to do
			cout << "\n\nWhat would you like to do?\n\n";
			setcolor(10);
			cout << "1 - Charsi" << endl;
			setcolor(11);
			cout << "2 - Akara" << endl;
			setcolor(13);
			cout << "3 - Battle in Pandemonium Fortress" << endl;
			setcolor(14);
			cout << "4 - Battle in Harogath" << endl;
			setcolor(4);
			cout << "5 - Quit" << endl;

			setcolor(15);

			cin >> intTownChoice;


			if (intTownChoice == 1)
			{
				//work
				setcolor(10);
				cout << "\n\nHow long would you like to work? (1000 hour maximum) "; //If they choose 1, it will bring them to the work screen where they pick 
				cin >> intWorkHours; //how many hours they work
				intPay = intWorkHours * 100; // gives their money

				if (intWorkHours > 1000)
				{
					cout << "You cant do that ";
					intWorkHours = 1000;
				}

				if (intWorkHours >= 1)
				{
					cout << "\n\nYou worked for " << intWorkHours
						<< " hour(s) and earned " << intPay << " gold piece(s)!\n\n"; //Tells user how long they worked and how much they earned

					intGold += intPay;
					cls();
					setcolor(15);
					continue;

				}
				cls();
				setcolor(15);
				continue;

			}


			if (intTownChoice == 2)
			{
				intSwordCost = intSwordLevel * 100;
				intBowCost = intBowLevel * 100;
				intMaceCost = intMaceLevel * 100;

			
				setcolor(11);
				cout << "Welcome to the Shop of Kanto " << endl;
				cout << "Do you need\n1. Sword(Attack:5)\n2. Bow(Attack:10)\n3. Mace(Attack:8)\n4. Leave " <<endl;

				cin >> intUpgradeChoice;
				cls();

				//This is if they choose to upgrade sword
				if (intUpgradeChoice == 1 && intGold >= intSwordCost)
				{
					intSwordLevel++; //makes sword level up
					cout << "You paid the blacksmith " << intSwordCost
						<< " gold pieces.\nYour sword has been upgraded to level " //Outputs how much they paid + what level their sword goes too
						<< intSwordLevel << "!\n\n";			
						intGold -= intSwordCost; //Subtracts gold
				}
				if (intUpgradeChoice == 2 && intGold >= intBowCost)
				{
					intBowLevel++; //makes sword level up
					cout << "You paid the blacksmith " << intBowCost
						<< " gold pieces.\nYour bow has been upgraded to level " //Outputs how much they paid + what level their sword goes too
						<< intBowLevel << "!\n\n";
						intGold -= intBowCost; //Subtracts gold
				}
				if (intUpgradeChoice == 3 && intGold >= intMaceCost)
				{
					intMaceLevel++; //makes sword level up
					cout << "You paid the blacksmith " << intMaceCost
						<< " gold pieces.\nYour mace has been upgraded to level " //Outputs how much they paid + what level their sword goes too
						<< intMaceLevel << "!\n\n";
						intGold -= intMaceCost; //Subtracts gold
				}
				if (intUpgradeChoice == 4)
				{
					cls();
					setcolor(15);
					continue;

				}
				setcolor(15);
				continue;
			}



			if (intTownChoice == 3)
			{
				setcolor(13);

			cout << "You travel to the Pandemonium Fortress...";
			PlaySound("kurast.wav", NULL, SND_FILENAME | SND_ASYNC); 
			Sleep(3000);
			cls();
			cout << "Appearing in the star is Diablo!\n\n";
			if (intHealth <= 0)
			{
				cout << "You Died" <<endl;
				PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC);
				continue;
			}

			while (Gobling_Health >= 1)


			{///master while for combat

				srand(static_cast<unsigned int>(time(0)));  

				
				cout<<"your health "<<intHealth<<endl;
				cout<<"Diablo "<<Gobling_Health<<"\n\n";

				srand(Gobling_Damage);

				Gobling_Damage = (rand() % 5) + 1;

				cout<<" Diablo did "<<Gobling_Damage<<" Damage"<<endl;

				intHealth = intHealth - Gobling_Damage;


				cout<<"your health "<<intHealth<<endl;
				cout<<"Diablo "<<Gobling_Health<<"\n\n";


				system("pause");
				


				cout << "What do you want to do\n\n";
				cout << "1: Attack with sword\n2: attack with mace\n3: attack with bow\n4: Run\n";
				cin >> intBattleChoice;
				cls();
				


				int Sword_Damage = (rand() % 10) + intStrength + intSwordLevel;
				int Mace_Damage = (rand() % 13) + intVitality + intMaceLevel;
				int Bow_Damage = (rand() % 15) + intDexterity + intBowLevel;
				
				if (intBattleChoice == 1)	
				{
					Gobling_Damage = (rand() % 5) + 1;   
					Gobling_Health = Gobling_Health - Sword_Damage;
					cout<<"Sword Attack dealed " << Sword_Damage << " Damage! "<<endl;
				}
				if (intBattleChoice == 2)
				{
					Gobling_Damage = (rand() % 5) + 1;   
					Gobling_Health = Gobling_Health - Mace_Damage;
					cout<<"Mace Attack dealed " << Mace_Damage << "Damage" <<endl;
				}
				else if (intBattleChoice == 3)	
				{
					Gobling_Damage = (rand() % 5) + 1;   
					Gobling_Health = Gobling_Health - Bow_Damage;
					cout<<"Bow Attack dealed " << Bow_Damage << " Damage! "<<endl;
				}


				if (intBattleChoice == 4)
				{
					PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC);
					continue;
				}
			}
			

			Gobling_Health = 500;
			intHealth = (intVitality) * (25);
			cls();
			cout << "You Defeated Diablo\n";
			cout << "You gained 15 experience";
			intExperience = intExperience + Gobling_Exp;
			PlaySound("pokelevelup.wav", NULL, SND_FILENAME | SND_ASYNC);
			Sleep(3000);
			cls();
			
			PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC);
			continue;


			Gobling_Health = 500;
			intHealth = (intVitality) * (25);
		}
	



		if (intTownChoice == 4)
		{
		setcolor(14);

		cout << "You travel to Harrogath...";
		PlaySound("kurast.wav", NULL, SND_FILENAME | SND_ASYNC); 
		Sleep(3000);
		cls();
		cout << "Approaching from the Worldstone Chamber comes Baal!\n\n";
		if (intHealth <= 0)
		{
			cout << "You Died" <<endl;
			PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC);
			continue;
		}

		while (Troll_Health >= 1)


		{///master while for combat

			srand(static_cast<unsigned int>(time(0)));	  
			
			cout<<"your health "<<intHealth<<endl;
			cout<<"Baal "<<Troll_Health<<"\n\n";

			srand(Troll_Damage);

			Troll_Damage = (rand() % 10) + 1;

			cout<<"Baal did "<<Troll_Damage<<" Damage"<<endl;

			intHealth = intHealth - Troll_Damage;


			cout<<"your health "<<intHealth<<endl;
			cout<<"Baal "<<Troll_Health<<"\n\n";

			system("pause");
			

			cout << "What do you want to do\n\n";
			cout << "1: Attack with sword\n2: attack with mace\n3: attack with bow\n4: Run\n";
			cin >> intBattleChoice;
			cls();
			

			int Sword_Damage = (rand() % 10) + intStrength + intSwordLevel;
			int Mace_Damage = (rand() % 13) + intVitality + intMaceLevel;
			int Bow_Damage = (rand() % 15) + intDexterity + intBowLevel;
			cls();
			if (intBattleChoice == 1)	
			{
				Troll_Damage = (rand() % 5) + 1;   
				Troll_Health = Troll_Health - Sword_Damage;
				cout<<"Sword Attack dealed " << Sword_Damage << " Damage! "<<endl;
			}
			if (intBattleChoice == 2)
			{
				Troll_Damage = (rand() % 5) + 1;   
				Troll_Health = Troll_Health - Mace_Damage;
				cout<<"Mace Attack dealed " << Mace_Damage << "Damage" <<endl;
			}
			else if (intBattleChoice == 3)	
			{
				Troll_Damage = (rand() % 5) + 1;   
				Troll_Health = Troll_Health - Bow_Damage;
				cout<<"Bow Attack dealed " << Bow_Damage << " Damage! "<<endl;
			}


			if (intBattleChoice == 4)
			{
				PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC);
				continue;
			}
		}

		Troll_Health = 1000;
		intHealth = (intVitality) * (25);
		cls();
		cout << "You Defeated Baal\n";
		cout << "You gained 30 experience";
		intExperience = intExperience + Troll_Exp;
		PlaySound("pokelevelup.wav", NULL, SND_FILENAME | SND_ASYNC);
		Sleep(3000);
		cls();

		PlaySound("rougeencampment.wav", NULL, SND_FILENAME | SND_ASYNC);
		continue;


		Troll_Health = 1000;
		intHealth = (intVitality) * (25);
	}

		if(intTownChoice == 5)
		{
			break;
		}
		



	system ("PAUSE");
	return 0;

}
}
}

This post has been edited by popshot: 15 January 2010 - 02:25 PM

Was This Post Helpful? 0
  • +
  • -

#8 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Error With Sound in C++

Posted 15 January 2010 - 02:27 PM

Try <windows.h> instead of <mmsystem.h>, and include header <ctime>
Was This Post Helpful? 0
  • +
  • -

#9 popshot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 13-January 10

Re: Error With Sound in C++

Posted 15 January 2010 - 02:28 PM

View Postsarmanu, on 15 Jan, 2010 - 01:27 PM, said:

Try <windows.h> instead of <mmsystem.h>, and include header <ctime>


still not workin
Was This Post Helpful? 0
  • +
  • -

#10 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Error With Sound in C++

Posted 15 January 2010 - 02:35 PM

Ok, I have replaced <mmsystem.h> with <windows.h> and added <ctime> and it compiled & ran for me. Maybe your problem is platform-dependent, which is beyond my power. Sorry for not being able to help you there ...

Hmm, why don't you try to add something like that:

#undef SND_ASYNC
#define SND_ASYNC 0x0001



right after the pragma directive?
The SND_ASYNC value is taken from mmsystem! This is basically a reimplementation of SND_ASYNC bit

This post has been edited by sarmanu: 15 January 2010 - 02:37 PM

Was This Post Helpful? 0
  • +
  • -

#11 popshot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 13-January 10

Re: Error With Sound in C++

Posted 15 January 2010 - 02:36 PM

View Postsarmanu, on 15 Jan, 2010 - 01:35 PM, said:

Ok, I have replaced <mmsystem.h> with <windows.h> and added <ctime> and it compiled & ran for me. Maybe your problem is platform-dependent, which is beyond my power. Sorry for not being able to help you there ...

Hmm, why don't you try to add something like that:

#define SND_ASYNC 0x0001



right after the pragma directive?
The SND_ASYNC value is taken from mmsystem!


I tried that also and nothing. This is a lost cause im pretty sure
Was This Post Helpful? 0
  • +
  • -

#12 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Error With Sound in C++

Posted 15 January 2010 - 02:39 PM

Yes, if this didn't work, even after
#undef SND_ASYNC
#define SND_ASYNC 0x0001


then is a Visual Studio 2010 BETA bug.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1