Thread: Simple Half-Life Coding Question

  1. #1
    Registered User
    Join Date
    Sep 2007

    Question Simple Half-Life Coding Question


    I'm taking a look at the HPB bot template for Half-Life, trying to understand and edit a bit of basic stuff in there. You won't need to understand the bot to answer my question though, I think. It's pretty basic.

    In the source code file, bot.cpp, there's a function that is declared as follows:

    void BotCreate( edict_t *pPlayer, const char *arg1, const char *arg2,const char *arg3, const char *arg4).

    Okay. Now within that function there are the following declarations of pointers:

    edict_t *BotEnt; bot_t *pBot;

    I have this idea that these pointers point to structures of type edict_t in another code file, that contain loads of functions and variables and stuff. Hence:

    BotEnt->v.idealpitch = BotEnt->v.v_angle.x;

    and other stuff like:

    pBot->idle_angle = 0.0;

    So what I'm thinking is that in the botcreate function declaration, edict_t *pPlayer is going to basically identify each bot in the same way that each player would be identified in a game. Is this right? Sorry if this sounds dumb, I'm just trying to figure out how this works.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    If you just declare a pointer, you can't start accessing stuff through it. You have to point the pointer to something first.
    int x = 0;
    int *p = &x;
    printf("%d %d\n", x, *p);  /* prints "0 0" */
    x += 1;
    *p += 1;
    printf("%d %d\n", x, *p);  /* prints "2 2" */
    Assuming that your pointers actually point to something . . . how is this code being used? If it's something like this:
    void handle_integer(int *p) {
        /* ... */
    and the function is called for every integer or whatever that you are handling, then the function's code is executed once for every integer. p will point to every integer that the function is called with in turn.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  2. Really Simple Question!
    By slevytam in forum C Programming
    Replies: 3
    Last Post: 01-31-2005, 02:28 PM
  3. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. A Simple Question
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 10-26-2001, 05:23 PM