Archived

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

understanding source code

This topic is 6387 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 know this is probably a dumb question, but I''m new, so bear with me. Ok, as I look through the source code of almost any game, all I see are functions filled with if-else statements. That''s about it. Now, this may sound stupid, but where the heck are the calling statements for all these functions?! For example, in the Descent 1 source code, in the file AI.C (yes, I know it''s stands for Artificial Intelligence...which I think is what I have), there are just lines and lines of: void if_monster_does_this_or_that() { if (monster == big) blah blah else blah blah } Ok, that''s all great and dandy and I can understand what that function does, but I just want to know how it gets invoked. I''m still used to beginning programming (you know, where you have to have a main(); and all that). Thanks. Please check my post one or two spots above this one for a related topic.

Share this post


Link to post
Share on other sites
But doesn''t "if_monster_does_this_or_that();" have to be called from another function? I mean, if it''s never called, the function wouldn''t execute right? That''s my question - where is the function called...not what does it do?

Share this post


Link to post
Share on other sites
True, it does need to be called from another function. And it is. It is called from a function in some other file, most likely, which in turn may be called from yet another function, perhaps in another file. It seems to me that you haven''t yet grasped the idea that functions can call functions in other files, so I''ll try to explain it for you.

Ahem...
Functions can call functions in other files.

There are these ".h" files which contain declarations (I hope I''m using the right term) of the functions in the related ".cpp" file. Other unrelated files in the same project use these ".h" files to know which functions can be called even if they aren''t in that source code file.

Hope that helped, otherwise I just spent way too long ranting. Oh well


- IO Fission

Tearing 'em apart for no particular reason...

Share this post


Link to post
Share on other sites
Yeah...hehe...don''t worry, you''re ranting was done with good cause. I understand what you are saying. I figured they were getting called from other files but I just wanted to make sure so I wouldn''t sound like such an idiot next time. Well, that about explains everything. Thanks.

Share this post


Link to post
Share on other sites
If you are using Visual Studio to look at the code, you can use the "Find in Files" option from the edit menu to find the calls or references for that particular function.
Just enter
"if_monster_does_this_or_that()" into the search string box if you want to find the places where it gets called ( it will also return the definition and implementation ).

If thats of any use to you


Give me one more medicated peaceful moment..
~ (V)^|) |<é!t|-| ~

Share this post


Link to post
Share on other sites