Results 1 to 2 of 2

Thread: How to connect a function?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Squire
    Join Date
    Jan 2012
    Posts
    10

    Default How to connect a function?

    Hi!

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

    Code:
    int compare(Entity *pParent, int random)
    {
    	
    	int bSwap = 0;
    	switch (random)
    	{
    	case 0:
    		SetButtonStyleEntity(player->getButton(0),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		SetButtonStyleEntity(ai->getButton(0),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		break;
    	case 1:
    		SetButtonStyleEntity(player->getButton(1),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		SetButtonStyleEntity(ai->getButton(1),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		break;
    	case 2:
    		SetButtonStyleEntity(player->getButton(2),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		SetButtonStyleEntity(ai->getButton(2),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		break;
    	case 3:
    		SetButtonStyleEntity(player->getButton(3),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		SetButtonStyleEntity(ai->getButton(3),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		break;
    	case 4:
    		SetButtonStyleEntity(player->getButton(4),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		SetButtonStyleEntity(ai->getButton(6),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    		break;
    	}
    	return 0;
    }

    I am calling the above function like this:


    Code:
    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);
    		  pEnt->GetShared()->GetFunction("OnSelect")->sig_function.connect(&compare);
    		}
    	}
    }
    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

    Code:
    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?

    Code:
    SetButtonStyleEntity(player->getButton(4),Button2DComponent::eButtonStyle::BUTTON_STYLE_CLICK_ON_TOUCH_PRESS_RELEASE);
    Last edited by rtr_18; 05-04-2012 at 06:38 AM.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    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:

    pEnt->GetFunction("OnSelect")->sig_function.connect(&compare);

    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.
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. Test Drive Function
    By anonymous1 in forum Tanked
    Replies: 5
    Last Post: 04-28-2012, 05:14 PM
  2. Mount a script as global function ?
    By Spider_hip in forum Novashell Game Creation System
    Replies: 0
    Last Post: 04-04-2011, 11:02 AM
  3. Best way to call a function every 5 secs
    By BigBMan in forum Proton SDK
    Replies: 1
    Last Post: 01-31-2011, 08:34 AM
  4. Quick screen res function request
    By Interference in forum Novashell Game Creation System
    Replies: 1
    Last Post: 06-09-2008, 07:05 AM
  5. Connect to signals
    By void_kill in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 04-11-2007, 02:23 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •