How to connect two functions (Javascript)

I don’t think i made the question very clear in the title so here is a little explaining.

I have a button in my function OnGUI and i would like for it to trigger a few lines of code in my function update (its for crafting) but im not 100% sure on how to connect the two of them.

I would like for the Crafting function to always be on but i only want the button to show when Tab is pressed. So far i have it when tab is pressed the inventory is on and everything works well except the button wont craft the objects because it has no way to say that the crafting has been in place.

I hope this made a little sense and i put a few of my variables and the lines of code that i am having the problems with. I paraphrased my script below so i cut out many of the irrelevant parts of it. For a little more information the Debug.Log(“button”); does show up in the console but the Debug.Log(“Ammount”); does not and yes i do know amount is spelled with one m.

Thank you in advance!

var Crafting : boolean[];
var Ammount : int[] = [0,0,0,0];


function OnGUI()
    {
    if(InventoryOn == true)
         {
         if(GUI.Button(Rect(200,500,80,30),"Craft Item"))
			{
			Debug.Log("button");
			}

function Update () 
       {
		if(Crafting[2] == true)
		{
		Debug.Log("Ammount");
		if(Ammount[0] >=1 && Ammount[1] >=1)
		{
		Ammount[0]-=1;
		Ammount[1]-=1;
		Ammount[2]+=1;
		Crafting[2] = false;
		}
		}
if(Input.GetKeyDown(KeyCode.Tab))
    {
    InventoryOn = !InventoryOn;
    }

Hi,

You could just make a function that has all the code you currently have in your update, and then just call it on update/whenever you need.

If I didn’t fully answer your question, or you need further assistance, please don’t be afraid to ask.

Best of luck,

SeeSharp.