00:00
00:00
Newgrounds Background Image Theme

Ryor just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

setTimeout? 2015-04-06 17:52:12


I've been struggling trying to make a piece in my game move to a specific tile, and after a few seconds move over to a different tile. However, no matter how big I make the delay in setTimeout, it seems to be making it at the same speed always. Is it because I am invoking it inside a function and therefore code executes really fast or is it another thing?
Here's part of the code:

resi = 14;
function return(retnum) {
	for (var indexnum:Number = 0; indexnum < allplayerarray.length; indexnum++) {
		if (allplayerarray[indexnum]._x == tileset[retnum]._x && allplayerarray[indexnum]._y == tileset[retnum]._y-6) {
			resi -= 1;
			return true;
		}
	}
}
function check(arg) {
	for (var initiate:Number = 1; initiate <= 9; initiate++) {
		var testphase = _root.return(resi);
		if (testphase == true) {
			_root.return(resi);
		}
	}
	arg._x = _root.tileset[resi]._x;
	arg._y = _root.tileset[resi]._y-6;
	resi = 14;
}

And here I invoke the function with a delay of 5 seconds inside another function:

setTimeout(_root.check, 5000, chip);

$$$ | Strawberry Dodge | Abusive Reviews! | Sig by TheDingo

BBS Signature

Response to setTimeout? 2015-04-07 03:29:10


just for my own curiosity what is the 'chip' at the end for?

setTimeout(_root.check, 5000, chip); <======This. What is this?

Response to setTimeout? 2015-04-07 04:52:07


At 4/6/15 05:52 PM, Hacsev wrote: However, no matter how big I make the delay in setTimeout, it seems to be making it at the same speed always. Is it because I am invoking it inside a function and therefore code executes really fast or is it another thing?

What is "the same speed as always", specifically? Instantly? The five seconds you had set before?

The call to setTimeout() being in a function won't matter, so that's definitely not the problem.

At 4/7/15 03:29 AM, Star250 wrote: just for my own curiosity what is the 'chip' at the end for?

Any extra arguments to setTimeout() after the second are passed to the callback. So, in the OP's code, the value of the chipvariable will be passed as an argument to the _root.check function.

Response to setTimeout? 2015-04-07 07:17:15


At 4/7/15 04:52 AM, Diki wrote:
At 4/6/15 05:52 PM, Hacsev wrote: However, no matter how big I make the delay in setTimeout, it seems to be making it at the same speed always. Is it because I am invoking it inside a function and therefore code executes really fast or is it another thing?
What is "the same speed as always", specifically? Instantly? The five seconds you had set before?

Yes, for some reason the code always seems to run instantaneously no matter how much of a delay I give it.


The call to setTimeout() being in a function won't matter, so that's definitely not the problem.

Ok, at least that is good to hear.

At 4/7/15 03:29 AM, Star250 wrote: just for my own curiosity what is the 'chip' at the end for?
Any extra arguments to setTimeout() after the second are passed to the callback. So, in the OP's code, the value of the chipvariable will be passed as an argument to the _root.check function.

This is correct. I am passing chip as the argument to the "check" function.


$$$ | Strawberry Dodge | Abusive Reviews! | Sig by TheDingo

BBS Signature

Response to setTimeout? 2015-04-07 09:13:50


At 4/7/15 07:17 AM, Hacsev wrote: Yes, for some reason the code always seems to run instantaneously no matter how much of a delay I give it.

Are you certain you don't have setTimeout(_root.check(), 5000, chip) somewhere (note the parenthesis after 'check')? That would cause the function to be called instantly rather than after the timeout, and it's the only thing I can think of that could be the problem.

Response to setTimeout? 2015-04-07 11:30:08


At 4/7/15 09:13 AM, Diki wrote:
At 4/7/15 07:17 AM, Hacsev wrote: Yes, for some reason the code always seems to run instantaneously no matter how much of a delay I give it.
Are you certain you don't have setTimeout(_root.check(), 5000, chip) somewhere (note the parenthesis after 'check')? That would cause the function to be called instantly rather than after the timeout, and it's the only thing I can think of that could be the problem.

I tried the function without the () in the setTimeout and it acted the same way, so that's not the problem. The way the code is being run is like this: I click a button that calls a function that determines if the piece can move and where it will move. If it lands on a special tile, I want to move it to that tile and then call another function to move it to another tile. I want the delay to happen so I can see that the piece lands on the special tile first and moves after a few seconds to another.


$$$ | Strawberry Dodge | Abusive Reviews! | Sig by TheDingo

BBS Signature

Response to setTimeout? 2015-04-07 12:19:12


http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9b.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7f6e

Reserved words are words that you cannot use as identifiers in your code because the words are reserved for use by ActionScript
return

You do not get the compiler error as advertised, though.

Response to setTimeout? 2015-04-07 14:13:03


At 4/7/15 12:19 PM, milchreis wrote: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9b.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7f6e

Reserved words are words that you cannot use as identifiers in your code because the words are reserved for use by ActionScript
return
You do not get the compiler error as advertised, though.

No I am getting no errors. Does it help if I point out that I am using AS2?


$$$ | Strawberry Dodge | Abusive Reviews! | Sig by TheDingo

BBS Signature

Response to setTimeout? 2015-04-08 05:50:48


At 4/7/15 02:13 PM, Hacsev wrote:
No I am getting no errors. Does it help if I point out that I am using AS2?

That might explain the lack of a proper error message. You should in general avoid using reserved words.

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000477.html

Response to setTimeout? 2015-04-08 09:37:38


At 4/8/15 05:50 AM, milchreis wrote:
At 4/7/15 02:13 PM, Hacsev wrote:
No I am getting no errors. Does it help if I point out that I am using AS2?
That might explain the lack of a proper error message. You should in general avoid using reserved words.

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000477.html

I am not really following you on that. Can you elaborate more please? What reserved words am I using in my code that are causing the problem?


$$$ | Strawberry Dodge | Abusive Reviews! | Sig by TheDingo

BBS Signature

Response to setTimeout? 2015-04-08 11:20:50


At 4/8/15 09:37 AM, Hacsev wrote: I am not really following you on that. Can you elaborate more please? What reserved words am I using in my code that are causing the problem?

I'm not sure that your setTimeout() issue is caused by it, but he's referring to your function being named 'return'.

Can you post the entirety of the code that makes the call to setTimeout()? The problem might be there.

Response to setTimeout? 2015-04-08 11:32:29


At 4/8/15 11:20 AM, Diki wrote:
At 4/8/15 09:37 AM, Hacsev wrote: I am not really following you on that. Can you elaborate more please? What reserved words am I using in my code that are causing the problem?
I'm not sure that your setTimeout() issue is caused by it, but he's referring to your function being named 'return'.

Its not that because, the real code does not have a function named "return". I just changed it here because of confidentiality.


Can you post the entirety of the code that makes the call to setTimeout()? The problem might be there.

Nevermind, all of the code is over 400 lines long, but I managed to fix it. It seems I was calling the function too late in the code and as a result it wouldn't trigger. I made the delay to 1000 and it works fine. Thanks for the help though from both you guys, I learned a lot from the reserved words too!


$$$ | Strawberry Dodge | Abusive Reviews! | Sig by TheDingo

BBS Signature