Calling Update function in another function (JS)

Hi all,

I’m trying to make a script that makes a text file which stores an int value when the application is exited, then reads it back when re-opened. This all works fine however now I’m trying to get that int variable from the text file to some UI text.

Here is my code:

import System;
import System.IO;

var prevooftext : UnityEngine.UI.Text;
var fileName = "MyFile.txt";
var targetScript: Dupe;


function OnApplicationQuit()
{
	var sr = File.CreateText(fileName);
	targetScript.oofs -= 0;
	sr.WriteLine (targetScript.oofs);
	sr.Close();
	if (File.Exists(fileName))
	{
		var sa = new StreamReader(fileName);
		var fileContents = sa.ReadToEnd();
		sa.Close();
 
		var prevoof = fileContents;
		print (prevoof);
		Update();

     }
 }

 function Update(){
 prevooftext.text = prevoof.ToString();
 }

I need to call the Update() function inside of the OnApplicationQuit() function. However obviously the variable can’t be used because it’s in another function. I need to know how to either call the Update() function inside the OnApplicationQuit() function or know how to use the variable prevoof in both functions.

Sorry if this seems like an obvious answer or if I was not clear.

Thanks for any help in advance.

Did you try

function OnApplicationQuit () {
   //copy and paste the codes on the Update
}