x


Is it possible to call update function from another function??

hi all,

I want to know that is it possible to call update from another function???

If it is possible means how can i pass values as arguments into update....i have tried that but it shows "Update can not take arguments"...

I want to know alternative way for this??

Can any one suggest your answer...

Thanks in advance.

more ▼

asked Dec 13 '10 at 10:53 AM

sriram90 gravatar image

sriram90
460 33 37 47

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

2 answers: sort voted first

Here is an example: Script B accesses 2 variables in Script A and changes them and Update function in A is endlessly executing the function with changed arguments.

ScriptA

static var value1:int;
static var value2:int;

function Update(){

 MyFunction(value1, value2);

}

function MyFunction(v1:int,v2:int) {

 Do something here...

}

ScriptB

function OnMouseDown(){
 ScriptA.value1 = 10;
 ScriptB.value2 = 20;
}
more ▼

answered Dec 13 '10 at 11:12 AM

Kourosh gravatar image

Kourosh
1.5k 47 53 65

hi kourosh,

function Update() { Check(id); }

function OnMouseDown() { Continue(a); }

function Continue(int a) { Do Something here... Update();

}

function Check(int id) { Do Something Here... }

is it possible???

Dec 13 '10 at 11:25 AM sriram90

Do this instead:

function Update()
{
    Check(id);
}

function OnMouseDown()
{
    Continue(a);
}

function Continue(int a)
{
    Do Something here... 
    Check(id);
}

function Check(int id)
{
    Do Something Here...
}
Dec 14 '10 at 04:37 PM anomalous_underdog
(comments are locked)
10|3000 characters needed characters left

Put the code you have in Update into a new function. That new function can have arguments in it.

Then replace the code in Update to simply just calling that function.

more ▼

answered Dec 13 '10 at 11:10 AM

anomalous_underdog gravatar image

anomalous_underdog
335 3 6 18

I couldn't agree more. Don't fiddle with the base flow. Just reroute it to a branch instead.

Dec 13 '10 at 11:27 AM Proclyon
(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

asked: Dec 13 '10 at 10:53 AM

Seen: 578 times

Last Updated: Dec 13 '10 at 11:41 AM