WHY is this (apparently) an infinite loop??

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

WHY is this (apparently) an infinite loop??

Post by Xuri »

I fail to see how this turns into an infinite loop :/ That's UO minutes it's getting, btw, which changes every few seconds (depending on your setting).

Code: Select all

	var iMinute = GetMinute();
	var tempMinute = iMinute + 3;
	do
	{
		iMinute = GetMinute();
		pUser.SysMessage( "Minute nr: "+iMinute );
	}
	while (iMinute < tempMinute )
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

That's a good question... looks to me like it should work fine.

Try this instead

Code: Select all

var tempMinute = GetMinute() + 3;
for( var iMinute = GetMinute(); iMinute < tempMinute; iMinute = GetMinute() )
{
pUser.SysMessage();
}
Scott
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Hmmm same issue, apparently. Strange.
-= Ho Eyo He Hum =-
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

That's an easy one :)

The UO time gets updated once per execution loop. The JS you're executing occurs within the same execution loop. Ergo, GetMinute returns the same value *every* time. It never has a chance to update. It's like doing

Code: Select all

var x = 1;
for( ; x < 10; x = 1 )
{
  DoSomething();
}
Guess what happens? :)
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Gah. So it's not possible. Okay.
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Heh, quite right.

*blushes*

Ahh well, just run a timer that executes every second, Xu.
Scott
Post Reply