# \[FMX\] Help working out/learning lottery script

**URL:** <https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563>\
**Category:** Uncategorized\
**Created:** [May 28, 2004, 5:53am UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563 "2004-05-28T05:53:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![daboz](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@daboz](https://forum.kirupa.com/u/daboz)\
**Post date:** [May 28, 2004, 5:53am UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/1 "2004-05-28T05:53:28Z")

</div>

Hey all,

Recently I started a thread about a lottery draw and got a good response that helped me out thanks to Adam14 and Kode.

[http://www.kirupaforum.com/forums/showthread.php?t=52438](http://www.kirupaforum.com/forums/showthread.php?t=52438)  
[url=“[http://www.kirupaforum.com/forums/showthread.php?t=52438](http://www.kirupaforum.com/forums/showthread.php?t=52438)”]  
Kode gave a basic file that included a random number draw and a ‘bank’ that payed out if lotto balls were correct.

My problem is the script is rather advanced and just passes over my head and I am still an newbie at action script, I would be very grateful if anyone could help explain/comment the script. User ‘Futureflash’ has added some parts.

The basic file is attached and script is below.  
[url=“[http://www.kirupaforum.com/forums/newthread.php?do=newthread&f=9](http://www.kirupaforum.com/forums/newthread.php?do=newthread&f=9)”]  
[color=black][font=Verdana]  
[/font][/color][color=black][font=‘Trebuchet MS’]function resetLotto(reset)[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]{for (var prop in output) [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]{output[prop].text = “?”;[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]status.htmlText = “\<p align=“center”\>\<a href=“asfunction:playLotto”\>Click here to play!\</a\>\</p\>”;[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]clearInterval(id);[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]function playLotto() {[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]var prop, numbers, index, ran; ‘variables[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]Message.text = “”; ‘clears the message box from any message displayed out[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]for (prop in input) { [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]if (!input[prop].length) { [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]message.htmlText = “\<p align=“center”\>Enter a number in all the fields!\</p\>”; ‘ Displays out message, why htmlText[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]id = setInterval(resetLotto, interval); ’[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]return; ‘not sure, going by the message a check to ensure all input boxes have values[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]numbers = []; [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]for (index=1; index\<=maxvalue; index++) { [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]numbers.push(index); ‘ not sure[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]for (index=0; index\<output.length; index++) { [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]ran = Math.floor(Math.random()\*numbers.length); [/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]output[index].text = numbers[ran]; ‘not sure[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]numbers.splice(ran, 1); ‘ not sure[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]for (index=0; index\<output.length; index++) {[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]if (input[index].text != output[index].text) {[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]status.htmlText = “\<p align=“center”\>You’ve lost!\</p\>”; 'Displays out loosing message, any reason for html??[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]id = setInterval(resetLotto, interval);[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]return;[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]Message.htmlText = “\<p align=“center”\>\<b\>You’ve won!\</b\>\</p\>”; displays out winning message,any reason for html??[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]var id, interval = 2000; ‘ Variables and sets the interval to 2 seconds ???[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]var maxvalue = 49; ‘Set the maximum value[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]var output = [output0, output1, output2, output3, output4, output5]; ‘ Sets variables out for the text boxes[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]var input = [input0, input1, input2, input3, input4, input5]; ‘ Sets variables out for the text boxes[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]for (var prop in input) {[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]input[prop].restrict = “0-9”;[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]input[prop].onChanged = function() {[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]var n = parseFloat(this.text);[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]if (!isNaN(n) && n\>maxvalue) {[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]this.text = maxvalue;[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]};[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]}[/font][/color][color=black][font=‘Trebuchet MS’]

[/font][/color][color=black][font=‘Trebuchet MS’]resetLotto();[/font][/color][color=black][font=Verdana][/font][/color]

[font=Times New Roman][size=3] [/size][/font]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 2:11pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/2 "2004-05-28T14:11:58Z")

</div>

anybody know about this script, it would be a great help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 3:00pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/3 "2004-05-28T15:00:47Z")

</div>

Pretty cool little game. I am working on commenting it so give me a few . . .

:hr:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 3:49pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/4 "2004-05-28T15:49:58Z")

</div>

Here ya go. If you still dont’ understand some of the code

1. look stuff up in the actionscript reference in Flash
2. ask more questions here!

:hr:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 4:33pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/5 "2004-05-28T16:33:58Z")

</div>

Lunatic you are a ledgend,

I hoped someone would help me out a little but that’s brilliant.  
I will slowly…slowly go thru the script and work out in my head the various parts.

Thanks a million for taking the time to help me out, the game is cool but I didnt understand the script workings, so now I can sleep at night…lol

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 4:36pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/6 "2004-05-28T16:36:02Z")

</div>

lol, no problem daboz. Good luck getting through it - there was one line of code that I didn’t get. I’m gonna post it here and hopefully someone (HEY SCOTTY! HINT HINT) will jump on it and translate it for us . . .

:hr:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 4:40pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/7 "2004-05-28T16:40:17Z")

</div>

Okay here it is, and it is within a great big for loop:

```auto

for (index=0, total=0; index<output.length; index++) {
//yadda yadda yadda
**total += input[index].text == numbers[ran];**
//yadda yadda yadda
}

```

total = total + input[index].text but only when input[index].text is (comparatively) equal to numbers[ran]?

Is this like a shorthand if statement? Does anyone know?

total = a variable that tracks the number of correct guesses  
input[index] = the array of numbers input by the user  
numbers[ran] = the array of randomly generated numbers created by the program  
output = an array of dynamic textboxes that display the randomly generated numbers

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 28, 2004, 10:52pm UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/8 "2004-05-28T22:52:47Z")

</div>

I heard a princess shout for help, so I took my horse to find what was wrong=)

```auto
total += input[index].text == numbers[ran];

```

I think you’re right (I’m not completely sure) that it’s a sort if statement:  
if numbers[ran] (the random number) equals the input number, so is true (equals 1) , add 1 to total.  
Hope this makes sense;)

scotty(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2004, 2:20am UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/9 "2004-05-29T02:20:44Z")

</div>

Thanks so much Scotty!!

:bu:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 29, 2004, 9:47am UTC](https://forum.kirupa.com/t/fmx-help-working-out-learning-lottery-script/111563/10 "2004-05-29T09:47:48Z")

</div>

welcome=)
