understanding source code
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.
---Joker2000Stevie Ray Vaughan - The Legend
It gets called like this: if_monster_does_this_or_that();
then it does whatever was inside of those lovely braces.
Dare wa neko o koroshiteimasuka? (Ha! Learn Nihongo!)
then it does whatever was inside of those lovely braces.
Dare wa neko o koroshiteimasuka? (Ha! Learn Nihongo!)
"Now watch as I run away in a womanly fashion." - Batman
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?
---Joker2000Stevie Ray Vaughan - The Legend
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...
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...
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.
---Joker2000Stevie Ray Vaughan - The Legend
Even thuogh it''s called from other files, it''s still a hassle to look for the where it is called from. Unless you use the find fast thingie. But still a hassle nonetheless
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|-| ~
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|-| ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement