variable function calling

Started by
0 comments, last by thuned 22 years, 12 months ago
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
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
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

This topic is closed to new replies.

Advertisement