Avatar of hzrdc2
hzrdc2
 asked on

Create simple loop

How can I get the attached code to loop forever?
var user:String;
var cpu:String;
 
user = userTxtField.text = "" + (Math.floor(Math.random() * 100000));
cpu = cpuTxtField.text = "" + (Math.floor(Math.random() * 100000));
 
	if (user == cpu){
		trace( user + " " + cpu + " = OMG! We Have A match!!!")
	}else{
		trace( user + " " + cpu + " = No Match")
	}

Open in new window

Adobe Flash

Avatar of undefined
Last Comment
hzrdc2

8/22/2022 - Mon
Affiliated_IT

yes, but why? is that really a good idea?

var i:int;
i=1;
while(i>0){
your code
}
ASKER CERTIFIED SOLUTION
MMDeveloper

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hzrdc2

ASKER
I don't know if it is a good idea...? Basically, I want to see if I let this run for a couple days (locally), will I get a match. I am trying to see how random it really is...

your code worked, but flash puked with this error:

Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.      at random_test_fla::MainTimeline/random_test_fla::frame1()

Is there a way around this?
MMDeveloper

I dont think you can disable that via code, I did however find this page

http://blog.justgreat.nl/2007/08/24/joy-with-the-script-timeout-period/

which states "Just great; I forgot to mention HOW to set the timeout . Well here is how:
You cant set the timeoutperiod by code (neither in as3 nor in as2). You have to set the timeout manually in the publish settings of your fla: Ctrl+Shift+F12 > flash-tab > Script time limit.
Let me know if you still have trouble."
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
MMDeveloper

maybe use the setInterval and slow down the interval. I have an alarm clock I made in flash years ago that plays random MP3's on my computer as the alarm. It has intervals in there that check every 29 seconds. Maybe slow the interval down on your code to around every .1 seconds (100 milliseconds) or every 1/2 second (500)
hzrdc2

ASKER
I changed the script time limit to 60 and it still stops at 10,000 runs regardless.

I realize this is probably something flash was not intended to do and I am hitting some built in limit of the the output dialogue.

Is there a way to write directly to a file?
hzrdc2

ASKER
I'll just have it print if there was a match and call it done...

thanks MM
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.