x


do variables update in an update function

if i have a variable set in an update function, that has to be inside the update will this keep on setting it every frame, or does it just do it once until it has changed..

more ▼

asked Aug 04 '12 at 05:19 PM

reptilebeats gravatar image

reptilebeats
1.2k 53 105 137

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The function update runs once per frame, and keeps on repeating this every frame.

more ▼

answered Aug 04 '12 at 05:27 PM

Chris12345 gravatar image

Chris12345
276 2 19 40

i thought as much, ill have to rearrange my code

Aug 04 '12 at 05:47 PM reptilebeats
(comments are locked)
10|3000 characters needed characters left

If I correctly understood your question, variables declared inside a function are temporary and must be initialized each time the function runs, while variables declared outside any function are member variables - they are initialized once when the script instance is created and retain their values while the instance exists:

var m: int = 1; // member variable

function Update(){
  var tmp: int = 1; // temporary variable
}

You also have the properties, which are a kind of virtual variables accessed by dedicated routines known as getter and setter - usually the setter routine does nothing unless the current value is changed (equal values are ignored).

more ▼

answered Aug 04 '12 at 05:47 PM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x494
x18

asked: Aug 04 '12 at 05:19 PM

Seen: 171 times

Last Updated: Aug 04 '12 at 05:47 PM