View Full Version : How to connect a function?

05-04-2012, 05:45 AM

I've to attach a function to a button entity when it's clicked. My function has tow arguments.
It's coded like this:

int compare(Entity *pParent, int random)

int bSwap = 0;
switch (random)
case 0:
SetButtonStyleEntity(player->getButton(0),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
SetButtonStyleEntity(ai->getButton(0),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
case 1:
SetButtonStyleEntity(player->getButton(1),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
SetButtonStyleEntity(ai->getButton(1),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
case 2:
SetButtonStyleEntity(player->getButton(2),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
SetButtonStyleEntity(ai->getButton(2),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
case 3:
SetButtonStyleEntity(player->getButton(3),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
SetButtonStyleEntity(ai->getButton(3),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
case 4:
SetButtonStyleEntity(player->getButton(4),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
SetButtonStyleEntity(ai->getButton(6),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
return 0;

I am calling the above function like this:

void OnEntitySelect(VariantList *pVList)
Entity *pEnt = pVList->m_variant[1].GetEntity();

for(int i = 3; i < 9; i++)
if(pEnt->GetName() == player->getName(i))
//compare(pEnt, i);

But the code is not compiled. It shows the following erros:

error C2198: 'int (__cdecl *)(Entity *,int)' : too few arguments for call

If I use the commented line, ie

compare(pEnt, i);

The function didn't get called. When I debug the program, the control is not going into compare().

How to connect a function to a button entity?

Also I want to have irrlicht like push buttons. Is it enough to have some thing like the following line or do I've to
do in some other way?

SetButtonStyleEntity(player->getButton(4),Button2DComponent::eButtonStyle::BUTT ON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);

05-05-2012, 05:04 AM
Well, huh. So you have a button, you click it, then void OnEntitySelect(VariantList *pVList) gets called, right? If that doesn't happen, go study MainMenu.cpp in the RTSimpleApp example to learn how to setup your buttons.

This call:


Doesn't really call anything, it just connects a virtual wire (something you only want to do once, at the start, when you setup your button), so future calls that DO call it will go to that function.

But here's the thing, the function HAS to look like this:

void compare(VariantList *pVList)
//here it you can extra passed variables from pVList if you want


And to actually call it, you do:
pEnt->GetFunction("OnSelect")->sig_function(NULL); //or instead of null, send a *VariantList,

and THEN your function (and any others that connected themself to "OnSelect") would get called.