Jump to content
  • Advertisement

Archived

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

thuned

variable function calling

This topic is 6291 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

have something like this
	switch (nScene)
	{
	case 0:		
		Scene_0(lCurrTime, lStartTime);
		break;
	case 1:
		Scene_1(lCurrTime, lStartTime);
		break;
	default:
		break;
	}
 
just 2 cases in the above code. how would i make this more variable like so i can easily put this in a loop instead of having 100 case statements? thuned life is unfair, take advantage of it. UNMB2 - if the link doesn''t work, try clicking it

Share this post


Link to post
Share on other sites
Advertisement
Function pointers

typedef void (*fptrScene)(time lCurrTime, time lStartTime);

fptrScene SceneArray[20];

Scene_0(time lCurrTime, time lStartTime);
Scene_1(time lCurrTime, time lStartTime);
Scene_2(time lCurrTime, time lStartTime);

then in your init function somewhere:

...

SceneArray[0] = Scene_0;
SceneArray[1] = Scene_1;
SceneArray[2] = Scene_2;
...

Then for your loop

  
for (i=0; (i<20) && (SceneArray[i] != NULL); i++)
SceneArray[i](lCurrTime, lStartTime);


... I think. Don''t quote me on that though, I have never made an array of function pointers. In theory it should work

-Chris Bennett of Dwarfsoft - The future of RPGs Thanks to all the goblins in the GDCorner niche

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!