Functions Taking Dif. Numbers of Arguments at Dif. Times?

This is a discussion on Functions Taking Dif. Numbers of Arguments at Dif. Times? within the C++ Programming forums, part of the General Programming Boards category; Hi, I've been programming a few months. Basically, I've been looking at some code for this bot in Quake 2 ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    127

    Functions Taking Dif. Numbers of Arguments at Dif. Times?

    Hi,

    I've been programming a few months. Basically, I've been looking at some code for this bot in Quake 2 recently, and I've noticed that at one point in the code for it, in p_client.c, a function is declared with three arguments:

    Code:
    void	SelectSpawnPoint (edict_t *ent, vec3_t origin, vec3_t angles)
    {
    ...
    Yet in a header file, oak.h, it's declared with 2 arguments, ie

    Code:
    void SelectSpawnPoint(vec3_t origin, vec3_t angles);
    And then in another source file, it's called with 2 arguments:

    Code:
    SelectSpawnPoint(spawn_origin, spawn_angles);
    So what's going on? I thought once you'd declared your function, it had a set number of arguments to it?

    Thanks.

  2. #2
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    You're probably seeing what's called function overloading.
    - Leeor

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    127
    Thanks mate. But I dunno about this. Surely if it's function overloading I should be able to call the function with 3 arguments as well as 2?

    ie by doing this:

    void SelectSpawnPoint(ent, vec3_t origin, vec3_t angles);

    But that doesn't work. It won't compile if I do that. It tells me there are too few arguments.

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by bengreenwood View Post
    Thanks mate. But I dunno about this. Surely if it's function overloading I should be able to call the function with 3 arguments as well as 2?

    ie by doing this:

    void SelectSpawnPoint(ent, vec3_t origin, vec3_t angles);

    But that doesn't work. It won't compile if I do that. It tells me there are too few arguments.
    The code you provided is not a call, but a prototype. Yes, you should be able to call the function using 2 or 3 arguments provided they are the correct type for that function.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    127
    Oh oops I mean... when I called it in the game I did it like this:

    SelectSpawnPoint (newOak, spawn_origin, spawn_angles);

    But that doesn't work. It tells me there are too few arguments for the function. I don't understand why.

    The code I'm dealing with is from this zip here if you're willing to take a look:

    http://www.quake2.com/dll/tutorials/bot/src.zip

    In the file called oak.c, the selectspawnpoint function is called with 2 arguments. In the file p_client.c, it's called with 3 arguments.

    Thanks for your help.

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by bengreenwood View Post
    Oh oops I mean... when I called it in the game I did it like this:

    SelectSpawnPoint (newOak, spawn_origin, spawn_angles);

    But that doesn't work. It tells me there are too few arguments for the function. I don't understand why.

    The code I'm dealing with is from this zip here if you're willing to take a look:

    http://www.quake2.com/dll/tutorials/bot/src.zip

    In the file called oak.c, the selectspawnpoint function is called with 2 arguments. In the file p_client.c, it's called with 3 arguments.

    Thanks for your help.
    Well I've searched those two files for the SelectSpawnPoint function, and I haven't seen it called with 3 arguments. I've only seen it called and defined as having 2 arguments, unless I'm missing something.

    Try posting the exact error message you get from your compiler.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    127
    Thanks for doing that.

    Actually I just realised something. That source code I gave you the link to is not exactly what I'm using. Basically that is for a bot designed for an old version of Quake 2 (v3.17 I think). I compiled that and when I tried it with my version of Quake 2 (v3.2), the bot didn't work.

    Then I realised you can get the source code for the latest version of Quake 2 here:

    ftp://ftp.idsoftware.com/idstuff/qua...e/q2src320.exe

    Basically the code for the oak bot is pretty much the same as the source code for the 3.17 version of Quake 2, but with a few modifications. So I thought OK, I'll just try sticking those extra files (oak.h, oakai.c, oak.c) in the source code for Quake 2 v 3.2 , and see what happens when I compile that. Oh and I also made a few little changes to some files in the Quake 2 source as in the Quake 2 Oak 2 tutorials that are up on the tutorials section of this:

    http://www.quake2.com/dll/

    To my amazement it worked and I got the bot running in the game.

    But the point is, if you get the source code for Quake 2 v3.2 and look in p_client.c you'll see that selectspawnpoint takes three arguments in there. Whereas in the bot.c file I'm using it only takes 2. I think maybe in 3.17 p_client.c used to have a selectspawnpoint function that only takes 2 arguments whereas in the 3.2 version of Quake 2 it takes 3. Weird because the bot still works anyway though.

    Anyway thanks for your help with this. It'd be cool to be able to understand what's going on better...
    Last edited by bengreenwood; 03-23-2009 at 04:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Times function for rational numbers
    By CaliJoe in forum C++ Programming
    Replies: 1
    Last Post: 05-01-2009, 04:09 PM
  2. Help With Functions and Random Numbers
    By CaliJoe in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2009, 03:22 PM
  3. Something about probablility
    By mike_g in forum A Brief History of Cprogramming.com
    Replies: 116
    Last Post: 03-13-2008, 05:33 PM
  4. how can I re-sort a map
    By indigo0086 in forum C++ Programming
    Replies: 8
    Last Post: 06-01-2006, 06:21 AM
  5. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 10:15 AM

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