[Resolved] Need help from Flash/Actionscript programmer

I just bought the source code for a word game and try to figure out how they programmed the initial array with letters.

As I’m not an ActionScript / Flash programmer, I need to translate that simple function to Lua.

Is there anyone out there who can help me with this?

It’s not a lot of work, just one function. I can send you the source on request.

Thanks in advance [import]uid: 50459 topic_id: 34808 reply_id: 334808[/import]

I’m new to LUA, but have 10+ years AS experience. No guarantees, but I’d be willing to take a look at it. [import]uid: 202223 topic_id: 34808 reply_id: 138366[/import]

Ok, here’s some code:

It starts with defining the arrays:

this.alphabetArray = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");  
this.frequencyArray = new Array(0.0806425, 0.0960163, 0.1229086, 0.1661953, 0.2950576, 0.3195423, 0.3391679, 0.4001551, 0.4692106, 0.4703283, 0.4765805, 0.5175973, 0.542607, 0.6124568, 0.6862399, 0.7032713, 0.7043362, 0.7659019, 0.8297193, 0.9199659, 0.9478228, 0.9580807, 0.979273, 0.9809672, 0.9990304, 1);  
  

Then, for each row and column, the letters are picked:

 public function locateLetters():void  
 {  
 var loc2:\*=0;  
 var loc1:\*=0;  
 while (loc1 \< this.gameHeight)   
 {  
 this.locatedLettersArray[loc1] = new Array();  
 loc2 = 0;  
 while (loc2 \< this.gameWidth)   
 {  
 this.addLetter(loc1, loc2, Math.random());  
 ++loc2;  
 }  
 ++loc1;  
 }  
 this.showBestScore();  
 this.lineShape = new flash.display.Shape();  
 addChild(this.lineShape);  
 stage.addEventListener(flash.events.MouseEvent.MOUSE\_DOWN, this.startDrawing);  
 return;  
 }  
  

The AddLetter function looks like this:

 public function addLetter(arg1:\*, arg2:\*, arg3:\*):void  
 {  
 var loc2:\*=null;  
 this.aLetter = new letterMc();  
 addChild(this.aLetter);  
 this.aLetter.scaleX = 0;  
 this.aLetter.scaleY = 0;  
 caurina.transitions.Tweener.addTween(this.aLetter, {"scaleX":1, "scaleY":1, "time":0.3, "delay":arg3, "transition":"easeOutExpo"});  
 this.locatedLettersArray[arg1][arg2] = this.aLetter;  
 this.aLetter.x = arg2 \* this.letterWidth + this.startX;  
 this.aLetter.y = arg1 \* this.letterHeight + this.startY;  
 var loc1:\*=Math.random();  
 var loc3:\*=0;  
 while (loc3 \< this.frequencyArray.length)   
 {  
 if (loc1 \< this.frequencyArray[loc3])   
 {  
 loc2 = this.alphabetArray[loc3];  
 break;  
 }  
 ++loc3;  
 }  
 this.aLetter.letterTxt.text = loc2;  
 return;  
 }  

And finally, when a word is found, it adds new letters from the top:

 public function collapseLetters():void  
 {  
 var a:int;  
 var intervalForNewLetters:uint;  
 var addNewLetters:Function;  
 var b:int;  
 var collapseCount:int;  
 var c:int;  
  
 var loc1:\*;  
 intervalForNewLetters = 0;  
 addNewLetters = null;  
 b = 0;  
 collapseCount = 0;  
 c = 0;  
 addNewLetters = function ():\*  
 {  
 var loc2:\*=0;  
 flash.utils.clearInterval(intervalForNewLetters);  
 var loc1:\*=0;  
 while (loc1 \< gameHeight)   
 {  
 loc2 = 0;  
 while (loc2 \< gameWidth)   
 {  
 if (locatedLettersArray[loc1][loc2] == "")   
 {  
 addLetter(loc1, loc2, 0);  
 setChildIndex(lineShape, (numChildren - 1));  
 }  
 ++loc2;  
 }  
 ++loc1;  
 }  
 stage.addEventListener(flash.events.MouseEvent.MOUSE\_DOWN, startDrawing);  
 return;  
 }  
 a = (this.gameHeight - 1);  
 while (a \> -1)   
 {  
 b = (this.gameWidth - 1);  
 while (b \> -1)   
 {  
 collapseCount = 0;  
 c = a;  
 while (c \> -1)   
 {  
 if (this.locatedLettersArray[c][b] != "")   
 {  
 if (collapseCount != 0)   
 {  
 caurina.transitions.Tweener.addTween(this.locatedLettersArray[a - collapseCount][b], {"y":this.locatedLettersArray[a - collapseCount][b].y + this.letterHeight \* collapseCount, "time":0.2, "transition":"linear"});  
 this.locatedLettersArray[a][b] = this.locatedLettersArray[a - collapseCount][b];  
 this.locatedLettersArray[a - collapseCount][b] = "";  
 }  
 break;  
 }  
 else   
 {  
 ++collapseCount;  
 }  
 --c;  
 }  
 --b;  
 }  
 --a;  
 }  
 intervalForNewLetters = flash.utils.setInterval(addNewLetters, 300);  
 return;  
 }  

The author seems to use this.frequencyArray to determine how often a letter should be used.
The thing I want to know, how to create an array with letters, using the frequencyArray method.

BTW Here’s a link to the final game:
http://activeden.net/item/word-me-6/full_screen_preview/3213919

If you need the full source, pls give me your Email address. [import]uid: 50459 topic_id: 34808 reply_id: 138399[/import]

I’ll get you started on defining the tables:

this.alphabetArray = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");  
this.frequencyArray = new Array(0.0806425, 0.0960163, 0.1229086, 0.1661953, 0.2950576, 0.3195423, 0.3391679, 0.4001551, 0.4692106, 0.4703283, 0.4765805, 0.5175973, 0.542607, 0.6124568, 0.6862399, 0.7032713, 0.7043362, 0.7659019, 0.8297193, 0.9199659, 0.9478228, 0.9580807, 0.979273, 0.9809672, 0.9990304, 1);  

would become

alphabetArray = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }  
  
frequencyArray = { 0.0806425, 0.0960163, 0.1229086, 0.1661953, 0.2950576, 0.3195423, 0.3391679, 0.4001551, 0.4692106, 0.4703283, 0.4765805, 0.5175973, 0.542607, 0.6124568, 0.6862399, 0.7032713, 0.7043362, 0.7659019, 0.8297193, 0.9199659, 0.9478228, 0.9580807, 0.979273, 0.9809672, 0.9990304, 1 }  

[import]uid: 199310 topic_id: 34808 reply_id: 138406[/import]

Anybody else can help? [import]uid: 50459 topic_id: 34808 reply_id: 138464[/import]

It looks like Rob Miracle covered the array. The rest would take a little more work than I have time for at the moment.

Cheers. [import]uid: 202223 topic_id: 34808 reply_id: 138496[/import]

No problem. I figured it out :slight_smile:

Thanks all. [import]uid: 50459 topic_id: 34808 reply_id: 138498[/import]

I’m new to LUA, but have 10+ years AS experience. No guarantees, but I’d be willing to take a look at it. [import]uid: 202223 topic_id: 34808 reply_id: 138366[/import]

Ok, here’s some code:

It starts with defining the arrays:

this.alphabetArray = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");  
this.frequencyArray = new Array(0.0806425, 0.0960163, 0.1229086, 0.1661953, 0.2950576, 0.3195423, 0.3391679, 0.4001551, 0.4692106, 0.4703283, 0.4765805, 0.5175973, 0.542607, 0.6124568, 0.6862399, 0.7032713, 0.7043362, 0.7659019, 0.8297193, 0.9199659, 0.9478228, 0.9580807, 0.979273, 0.9809672, 0.9990304, 1);  
  

Then, for each row and column, the letters are picked:

 public function locateLetters():void  
 {  
 var loc2:\*=0;  
 var loc1:\*=0;  
 while (loc1 \< this.gameHeight)   
 {  
 this.locatedLettersArray[loc1] = new Array();  
 loc2 = 0;  
 while (loc2 \< this.gameWidth)   
 {  
 this.addLetter(loc1, loc2, Math.random());  
 ++loc2;  
 }  
 ++loc1;  
 }  
 this.showBestScore();  
 this.lineShape = new flash.display.Shape();  
 addChild(this.lineShape);  
 stage.addEventListener(flash.events.MouseEvent.MOUSE\_DOWN, this.startDrawing);  
 return;  
 }  
  

The AddLetter function looks like this:

 public function addLetter(arg1:\*, arg2:\*, arg3:\*):void  
 {  
 var loc2:\*=null;  
 this.aLetter = new letterMc();  
 addChild(this.aLetter);  
 this.aLetter.scaleX = 0;  
 this.aLetter.scaleY = 0;  
 caurina.transitions.Tweener.addTween(this.aLetter, {"scaleX":1, "scaleY":1, "time":0.3, "delay":arg3, "transition":"easeOutExpo"});  
 this.locatedLettersArray[arg1][arg2] = this.aLetter;  
 this.aLetter.x = arg2 \* this.letterWidth + this.startX;  
 this.aLetter.y = arg1 \* this.letterHeight + this.startY;  
 var loc1:\*=Math.random();  
 var loc3:\*=0;  
 while (loc3 \< this.frequencyArray.length)   
 {  
 if (loc1 \< this.frequencyArray[loc3])   
 {  
 loc2 = this.alphabetArray[loc3];  
 break;  
 }  
 ++loc3;  
 }  
 this.aLetter.letterTxt.text = loc2;  
 return;  
 }  

And finally, when a word is found, it adds new letters from the top:

 public function collapseLetters():void  
 {  
 var a:int;  
 var intervalForNewLetters:uint;  
 var addNewLetters:Function;  
 var b:int;  
 var collapseCount:int;  
 var c:int;  
  
 var loc1:\*;  
 intervalForNewLetters = 0;  
 addNewLetters = null;  
 b = 0;  
 collapseCount = 0;  
 c = 0;  
 addNewLetters = function ():\*  
 {  
 var loc2:\*=0;  
 flash.utils.clearInterval(intervalForNewLetters);  
 var loc1:\*=0;  
 while (loc1 \< gameHeight)   
 {  
 loc2 = 0;  
 while (loc2 \< gameWidth)   
 {  
 if (locatedLettersArray[loc1][loc2] == "")   
 {  
 addLetter(loc1, loc2, 0);  
 setChildIndex(lineShape, (numChildren - 1));  
 }  
 ++loc2;  
 }  
 ++loc1;  
 }  
 stage.addEventListener(flash.events.MouseEvent.MOUSE\_DOWN, startDrawing);  
 return;  
 }  
 a = (this.gameHeight - 1);  
 while (a \> -1)   
 {  
 b = (this.gameWidth - 1);  
 while (b \> -1)   
 {  
 collapseCount = 0;  
 c = a;  
 while (c \> -1)   
 {  
 if (this.locatedLettersArray[c][b] != "")   
 {  
 if (collapseCount != 0)   
 {  
 caurina.transitions.Tweener.addTween(this.locatedLettersArray[a - collapseCount][b], {"y":this.locatedLettersArray[a - collapseCount][b].y + this.letterHeight \* collapseCount, "time":0.2, "transition":"linear"});  
 this.locatedLettersArray[a][b] = this.locatedLettersArray[a - collapseCount][b];  
 this.locatedLettersArray[a - collapseCount][b] = "";  
 }  
 break;  
 }  
 else   
 {  
 ++collapseCount;  
 }  
 --c;  
 }  
 --b;  
 }  
 --a;  
 }  
 intervalForNewLetters = flash.utils.setInterval(addNewLetters, 300);  
 return;  
 }  

The author seems to use this.frequencyArray to determine how often a letter should be used.
The thing I want to know, how to create an array with letters, using the frequencyArray method.

BTW Here’s a link to the final game:
http://activeden.net/item/word-me-6/full_screen_preview/3213919

If you need the full source, pls give me your Email address. [import]uid: 50459 topic_id: 34808 reply_id: 138399[/import]

I’ll get you started on defining the tables:

this.alphabetArray = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");  
this.frequencyArray = new Array(0.0806425, 0.0960163, 0.1229086, 0.1661953, 0.2950576, 0.3195423, 0.3391679, 0.4001551, 0.4692106, 0.4703283, 0.4765805, 0.5175973, 0.542607, 0.6124568, 0.6862399, 0.7032713, 0.7043362, 0.7659019, 0.8297193, 0.9199659, 0.9478228, 0.9580807, 0.979273, 0.9809672, 0.9990304, 1);  

would become

alphabetArray = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }  
  
frequencyArray = { 0.0806425, 0.0960163, 0.1229086, 0.1661953, 0.2950576, 0.3195423, 0.3391679, 0.4001551, 0.4692106, 0.4703283, 0.4765805, 0.5175973, 0.542607, 0.6124568, 0.6862399, 0.7032713, 0.7043362, 0.7659019, 0.8297193, 0.9199659, 0.9478228, 0.9580807, 0.979273, 0.9809672, 0.9990304, 1 }  

[import]uid: 199310 topic_id: 34808 reply_id: 138406[/import]

Anybody else can help? [import]uid: 50459 topic_id: 34808 reply_id: 138464[/import]

It looks like Rob Miracle covered the array. The rest would take a little more work than I have time for at the moment.

Cheers. [import]uid: 202223 topic_id: 34808 reply_id: 138496[/import]

No problem. I figured it out :slight_smile:

Thanks all. [import]uid: 50459 topic_id: 34808 reply_id: 138498[/import]