x


Is "Invoke" just a short version for "yield WaitForSeconds" + FunctionCall?

Found this in the FPS-Tutorial, in the DamageReceiver.js: Is

Invoke ("DelayedDetonate", detonationDelay);

the same as:

yield WaitForSeconds (detonationDelay);
DelayedDetonate ();

? Or am I missing some siginficant detail here?

Thanks & Greetz, Ky.

more ▼

asked Dec 07 '09 at 10:03 PM

SisterKy gravatar image

SisterKy
2.4k 33 41 59

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

1 answer: sort voted first

The two examples you gave would give identical results. However, if you placed a piece of code afterwards, with Invoke it will get executed immediately, whereas with the yield it will be delayed as well.

For example, with this function, someOtherFunction will be called immediately, and DelayedDetonate will be called after detonationDelay seconds.

function Delay() {
    Invoke("DelayedDetonate", detonationDelay);
    someOtherFunction();
}

Whereas with this function, DelayedDetonate will be called after detonationDelay seconds, and someOtherFunction will be called right after DelayedDetonate.

function Delay() {
    yield WaitForSeconds(detonationDelay);
    DelayedDetonate();
    someOtherFunction();
}

Also, you cannot pass arguments using Invoke.

more ▼

answered Dec 07 '09 at 10:36 PM

Stelimar gravatar image

Stelimar
3k 14 16 50

You are correct: you can't pass arguments to Invoke.

Dec 07 '09 at 11:07 PM Ehren

Thanks, very helpful, both of you =) HA! Can upvote now! ^^

Dec 09 '09 at 12:48 PM SisterKy
(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:

x5081
x472

asked: Dec 07 '09 at 10:03 PM

Seen: 5901 times

Last Updated: Mar 11 '10 at 03:33 PM