how do i update a var only once in js under 'function update'

normal:

var uptry = 0; function update(){ uptry +=1; }

once:

var uptry = 0; var upswitch = 0; function update(){ if(upswitch != 1){ uptry +=1; upswitch = 1; } }

to value:

var uptry = 0; function update(){ if(uptry != 19){ uptry +=1; } }

It depends a bit on what the variable is and under what circumstances. Doing it inside Update often means checking for if the variable isn’t what it’s suppose to be yet whilst some other condition is met - if this is not supposed to happen first frame (first frame executions could 99% of the times be done in Awake or Start).

function Update () {
    // Changes myVariable once otherCondition is true
    if (myVariable != 1 && otherCondition)
        myVariable = 1;
}

Often the best solution is to change the variable from outside the Update function when the condition is met / certain function has been run.

var condition : boolean = false;

function Start () {
    // Wait for 10 seconds then run ChangeCondition function
    yield WaitForSeconds(10);
    ChangeCondition();
}

function Update () {
    // This will run 10 seconds later
    if (condition) {
        // Awesome code goes here
    }
}

function ChangeCondition () {
    /* Some important things happens here where we 
        lastly tell the rest of the program that the 
        condition is true */

    condition = true;
}