Just need more help...

This is a discussion on Just need more help... within the C++ Programming forums, part of the General Programming Boards category; [edit]Must learn to read for comprehension...[/edit]...

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    [edit]Must learn to read for comprehension...[/edit]
    Last edited by Prelude; 08-29-2004 at 01:31 PM.
    My best code is written with the delete key.

  2. #17
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I don't but this just sin't working. And that is all there was on the error thing.

    Edit: This is just plain stupid now! The more I add the more errors that make no sence come. The most errors I had so far were 54.
    Last edited by Rune Hunter; 08-29-2004 at 12:55 PM.

  3. #18
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    your main() is nested inside of startprogram(). That's not allowed.

    Code:
    void startprogram()
    {
    
      // lots of stuff
    
    int main()
    {
    
      // other stuff
    
    }  //this is the closing bracket for main()
    
    
    } //this is the closing bracket for startprogram()
    Dave

  4. #19
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok so now I need to know how to be able to use a variable in side of a void function()

    Edit: It keep saying it is undicleared.

  5. #20
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    first thing I would do is make a struct with all of that info your using for your traits.
    Code:
    struct info{
    int health;
    int attack;
    int def;
    int magic;   
    int alreadyset;
    int totaldamage;
    int dead;
    };
    which i personally would put in a header file.
    Rune think of it like this
    Code:
    //fight.h
    #ifndef fight_h
    #define fight_h
    
    void fight();
    
    #endif //fight_h
    Code:
    //fight.cpp
    #include "fight.h"
    
    void fight()
    {
    //blah blah
    //kill something
    //if you die then exit
    }
    Code:
    //main.cpp
    #include <iostream>
    #include "fight.h"
    
    int main
    {
      //whatever
      if(playerwants to fight)
      {
        fight();
      }
      return 0;
    }
    your code is able to find the fight function because you protyped it in the header file so as long as you include that your fine
    Woop?

  6. #21
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Ok here is what I got...

    I got info.h wich has all the variables in it.

    Then I got createplayer.h and .cpp.

    In create player .cpp I had to use some of the variables used in info.h. But it says that the variables are undiclared. Even if I put
    Code:
    #include "info.h"
    I have even tried
    Code:
    #include "info.cpp"
    Any help now, lol, Please.
    Last edited by Rune Hunter; 08-29-2004 at 02:00 PM.

  7. #22
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    variables need to be like this

    Code:
    //+---Variables.h---+
    #ifndef _VARIABLES_H
    #define _VARIABLES_H
    
    //+--This is not the actual declaration of the variable, Its almost like a prototype--+
    extern int Var1;
    
    #endif
    Now in a cpp file

    Code:
    #include "Variables.h"
    
    //+---Here you declare the variables--+
    int Var1;
    
    //+---Other code that uses the varibles---+
    Now in another cpp file you can get access to the variable by including the header file.

    It works like this

    The variable is declared in a source file, but the variables scope is only in the file it is declared in.

    This is where extern comes into play. It lets that variable be external of its original scope so you can use it globaly through out your project.

    Keep in mind that most of the time globals are not good to use, but thats something to worry about later on.

  8. #23
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Thanks alot now I can continue working on my game!

  9. #24
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alright now I got this error...it's always error after error...-sigh-

    Here is the error log thing...

    80 C:\Documents and Settings\Alex\Desktop\RPG Game\mainmenu.cpp
    ISO C++ forbids declaration of `P_attack' with no type

    I have that error a couple of times with P_ def too.

    here is the code now were it happens...

    P_health=P_health+10;
    P_attack=P_attack+2;
    P_def=P_def+2;
    P_mp=P_mp+3;

    Those varaibles worked in other places but here and a couple other places it doesn't like for some reason.

  10. #25
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Hmm, I would need to see the code of the actual declarations of those variables.

    did you make them int's?

    Maybe you could put your code into a zip file or something and post it so we can see what the problem is.

  11. #26
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Is P_health declard in the file? If it's in variables.h/cpp, are you including variables.h?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #27
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    well ok if you really want to look throw it...

    I gotta eat so I'll be back later to see if anyone actauly looked at it.
    Attached Files Attached Files

  13. #28
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    In callmainmenu() you're missing a closing bracket on your while loop... I'm surprised you didn't get an error before. Other than that, I didn't see anything particularly wrong when I glanced over your code.
    Last edited by Hunter2; 08-29-2004 at 04:34 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  14. #29
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I am seeing a few brackets you forgot to close. Thats probably the problem

    Go back and check your opening and closing brackets

    EDIT:
    ARGH, fricken hunter

    Yep close that bracket and it will work!
    Last edited by Vicious; 08-29-2004 at 04:36 PM.

  15. #30
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    lol pretty soon I will have people swaring at me LOL. Ok I'll go and close some brackets lol.

    Edit: Well that one bracket caused alot o truble.

    But you still didn't sware at me yet...
    Last edited by Rune Hunter; 08-29-2004 at 05:07 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21