transfer function parameter to button_OnClick? [solved]

Started by HandsFree, Fri 15/03/2013 10:51:45

Previous topic - Next topic

HandsFree

I'm trying to add some things to a game that already has a lot of scripting done.
It has a function ShowDeathGui(CauseOfDeath cod) that makes the gui visible and shows text and picture depending on 'CauseOfDeath'.

That's all ok, but now we want to add a 'try again' button. What happens when you click it is also depending on CauseOfDeath. So is there a way to make CauseOfDeath available in btnTryAgain_OnClick?

I suppose I can make CauseOfDeath a global variable, but that would change the way it was setup were it was a parameter to the ShowDeathGui function. So I was wondering if it's possible to keep that intact.

thanks

geork

I'm not quite sure what you mean: would you like "CauseOfDeath" the enumerated type (I assume that's what it is) to be available to "btnTryAgain_OnClick", or would you like the value supplied to be available i.e. "cod"
If you mean the value supplied - no, there is no way "btnTryAgain_onClick" can access "cod" as it is local to the instance of the "ShowDeathGui" function (as far as I'm aware). However, if you want to keep everything in one line, or only want a "CauseOfDeath" variable local to the GlobalScript (I presume that's where it is), you can make another value there, something like:
Code: AGS
//top of global script
CauseOfDeath cause;
//Then your function
function ShowDeathGui(CauseOfDeath cod){ //If you've used other values such as void, replace appropriately
  cause = cod;
  //etc etc
}
//Then elsewhere
function btnTryAgain_OnClick(GUIControl *control, MouseButton button)
{
 if(cause == blah)
 //etc etc
}


At the end of the day, it really just comes down to style - this method will mean that you can keep your function the same, and not need a global variable.

Hope that helps! :)


SMF spam blocked by CleanTalk