use one function for 10 objects, with different results based on ID #

Started by Cogliostro, Wed 30/04/2014 15:34:03

Previous topic - Next topic

Cogliostro

Okay, the idea is this, when you click on an object it calls a function and generates different results based on the ID of the object. 

IN THIS CASE, I have 10 buttons (all objects) on screen, when you click it, a different object briefly becomes transparent.  (i.e. Click on Object[10] and Object[0] briefly appears.)

Is there a more elegant way to do this - presumably using EXTENDER FUNCTIONS - or am I reduced

Code: ags

function Syn (short value) {
  object[value].TweenTransparency(0.5, 0, eEaseInTween, eBlockTween);
  object[value].TweenTransparency(0.5, 100, eEaseOutTween, eBlockTween);
}

function oBut0_AnyClick() //Object 10;
{
  Syn(0);
}

function oBut1_AnyClick() //Object 11;
{
  Syn(1);
}

//et cetera...


- Cogliostro
"First things first, but not necessarily in that order." - Dr. Who

JSH

You can override on_mouse_click() in room scripts so something like this should work. ClaimEvent() will prevent any other script files from receiving the click event.

Code: AGS

function on_mouse_click(MouseButton button)
{
  if(button == eMouseLeft)
  {
    Object* pObj = Object.GetAtScreenXY(mouse.x, mouse.y);, 
    if(pObj != null)
    {
      Syn(pObj.ID);
      ClaimEvent();
    }
  } 
}

Cogliostro

#2
JSH -

It worked like a charm, thanks!

- Cogliostro
"First things first, but not necessarily in that order." - Dr. Who

SMF spam blocked by CleanTalk