1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Where do I declare indentifiers?

Discussion in 'Civ4 - SDK/Python' started by CaptainMidnight, Nov 29, 2007.

  1. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    I've just started using of VB 2003 standard edition. I compiled Bhruhic 3.13 BTS patch source code and it came out working normally (but larger in size). However, I'm rapidly making very little progress with my "own" code. I've been trying to graft the "UpgradeCost" building tag from the Warlords CCCP source code onto Bhruhics BTS code. What I find is that some identifiers are apparently undeclared. Don't you declare them in the header (.h) files? I can't see where I haven't done the declaration.

    Any help for this poor, simple beginner would be greatly appreciated.
     
  2. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Okay the source files I have indentified as relevant are:

    CVplayer.h
    CVplayer.cpp
    CVunit.cpp
    CVinfos.cpp
    CVinfos.h
    CV.Gametextmgr.cpp
     
  3. Seven05

    Seven05 Warmonger

    Joined:
    Dec 5, 2005
    Messages:
    2,056
    Gender:
    Male
    Location:
    USA
    It depends on which identifies you are talking about and their scope, how familiar with C++ are you? (before I get into a overly-complicated technical explanation) :)
     
  4. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Erm, I've started learning it about two days ago... Mmmm, perhaps I need to study up a bit more before launching into coding new things.
     
  5. Seven05

    Seven05 Warmonger

    Joined:
    Dec 5, 2005
    Messages:
    2,056
    Gender:
    Male
    Location:
    USA
    Ok, let's try the short definition :)

    An identifier is normally something like pPlayer or iCount, basically a named variable. Declaring an identifier is the first step you have to complete before you can use it. So the following code will give you an error (undeclared identifier):
    Code:
    int myFunction(int x)
    {
       y = 4;
    
       return x + y;
    }
    
    You get there error here because y hasn't been properly declared. Notice that x was declared as an argument (int x) for the function. In other words, the compiler knows that x is an integer but it doesn't know what y is. However, the following code would work:
    Code:
    int myFunction(int x)
    {
       int y = 4;
    
       return x + y;
    }
    
    Now the compiler knows that y is also an integer so everything is fine. :)

    Hope that helps, it's a bit simplified but it should get you pointed in the right direction.
     
  6. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Oh, I see... And lets say the part "int y = 4", the "4" could be a string or word that represents a variable or number from another equation.

    Looking through CCCP code I often see values (variables? or simply words?) that don't seem to be declared in the sense you discussed above. This is what I think is happening crystalised in this wonderful example:

    "myfunction" declares that int X is going to be use; in order to use there is another function that uses (and declares) both int y and int z, this function culminates in int x value. Therefore "myfunction" would not have to declare int y and z because they are already declared under int x.

    So C++ is effectively a (3D) web of code, rather than just a linear list like XML.

    (Pardon my naivety and cruel butchering of programming vocab)

    Am I getting the wrong end of the stick?

    I am working through a C++ tutorial, so heres hoping things will become clearer sooner or later. Thanks for your input Seven05
     
  7. Seven05

    Seven05 Warmonger

    Joined:
    Dec 5, 2005
    Messages:
    2,056
    Gender:
    Male
    Location:
    USA
    Not really, every variable will be declared somewhere within the function unless it is a member variable of the class that contains the method (proper name for a function in a class) or a global. However, variables can have scope, that is they can apply to only part of the method or function but not the rest, this is frequently seen in for loops where you have something like for (int i = 0, i < 10, ++i) in which case using 'i' outside of the for loop will return an undeclared identifier error in the compiler. Oh, and they have some macros in the SDK too, just to keep us on our toes and confuse the non-programmers out there even more.

    What C++ is, rather than a web of code, is an object oriented language. So you will deal with a lot of objects in the form of classes. It is still very structured and limited by scope but until you have a basic understanding of object oriented programming (OOP) it can be quite confusing :)

    Some good tutorial subjects to learn about would be OOP in general, classes (incl. private and public data) and of course the basics like variables and loops. The good news is that once you get the basics the rest falls into place pretty easily.
     

Share This Page