Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

first rpg (text)

This topic is 6089 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 stared working on a text rpg for practice and I get 2 errors and I can''t figure out why... this is what I get when I compile 1.obj : error LNK2001: unresolved external symbol "int __cdecl battle(void)" (?battle@@YAHXZ) Debug/nw text rpg.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I''ll post the source code if necassary

Share this post


Link to post
Share on other sites
Advertisement
I suppose take a look at this it''s not very organised but it''s my first program
I proly didn''t include the right header files but I dunno which ones to include

#include
int monsterhp = 10;
int herohp = 50;
int totalherohop = 50;
int choice = 0;
int damage = 5;
int potion = 3;
int potionuse;
int itemchoice = 0;
int battle();
void menu();
int itemamount();
int battle(int monsterhp, int herohp, int choice, int damage)
{

if (herohp==0)
{
cout<<" \n your dead \n" ;
}
if (herohp>0)
{
cout<<"\n A monster appears, what will you do? \n";
menu();
cin>>choice;
switch(choice)
{
case 1: cout<<"You attacked monster and did " < monsterhp = monsterhp - damage;
break;
case 2: itemamount();
break;
case 3: cout<<"\n you cant run \n";
break;
default : cout<<" \n Invalid entry \n";
break;
}
}


return monsterhp,herohp;
}
int itemamount()
{

cout<<" 1. Potion(s): " << potion << endl << "\n 2.cancel \n";
cout<< "what item will you use?";
cin>>itemchoice;
switch(itemchoice)
{ case 1 : cout<<" \n potion used 20 hp restored";
if(herohp < 30)
{
herohp = herohp + 20;
}
if(herohp > 30)
{
potionuse = 50 - herohp;
herohp = herohp + potionuse;
}
battle();
case 2 : battle();
}
return potion;
}
void menu()
{
cout<<"\n 1. Attack \n 2. item \n 3. run" << endl;
}
void main()
{
battle();
}

Share this post


Link to post
Share on other sites
You have not defined the method int battle(), instead you have int battle(int, int, int, int).
You have to pass those parameters because the method battle() is considered to be different than battle(int, int, int, int).

"If consquences dictate our course of action, it doesn''t matter what''s right, it''s only wrong if you get caught."
- Tool

Share this post


Link to post
Share on other sites
You declare a function
int battle(); 

which is equivalent to
int battle( void ); 

and you call it in several places, but you never define it (fill out its body). You instead define a function
int battle(int monsterhp, int herohp, int choice, int damage) 

which is not the same thing. The compiler is simply telling you it can''t find the first function ( int battle( void ) ).

Also, MSVC (which I assume you''re using) outputs an error code with each line. Place your insertion carat there and hit F1 (Help). It''ll bring up the MSDN page on that error with an example of the error. It''s very useful when you''re learning the compiler.

Share this post


Link to post
Share on other sites
wierd
when I posted it, for some reason chunks of my source are gone

is gone and part of the case 1 is missing

Share this post


Link to post
Share on other sites
int battle();

right there you declared a function prototype.


int battle()
{
hp = hp - damage;
return 0;
}

is the definition.

and int battle(); is how you call your function.

now that is trying to read the variable damage, and hp. Damage and hp are variables in int main(), and they need to be passed as parameters to your battel function, so instead:

int battle(int hp, int damage);
as the prototype.

int battle()
{
hp = hp - damage;
return 0;
}

stays the same.

and when you call it this time:

int battle(100, 9);

that would take 9 away from 100.

"I''ve sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do''Urden

Share this post


Link to post
Share on other sites

  • 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!