Be a Supporter!
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: Key Queue 2005-09-15 12:51:34 Reply

AS: Main

please continue developing as you please and ask any questions,

common uses:
check if expression was typed
cheats
other nifty similar stuff

instructions:
first of all create a new instance of the class by typing

my_keyqueue=new KeyQueue(<your max length here>);
//the longer the max is the bigger cheats it can contain and the more usage it takes
my_keyqueue.listen();//starts key queuing
//actual checking for cheats
this.onEnterFrame=function(){/*if in movieclip put anything before this in a onClipEvent(load) and everything from now on in an enter frame*/
if(my_keyqueue.cheatCheck("hey lolz"){//replace hey lolz with your cheat
//actions that trigger when cheat is true go here
}

you can use this for a lot more than cheats

this is a pretty simple docs I just whipper up:

NOTE: inherits from the MovieClip class to enable pathing (passing this to the listener)

properties:
innerQueue :Array;
this is the actual queue the data goes in and out of. this is encapsulated so apart from knowing it's there it's not really an interest

constructor:
KeyQueue(length:Number)
creates a new KeyQueue the length of the passed parameter

Functions:

function getLastKey(Void):Number - returns the last typed key, pretty useless but it makes sense to have it there, type my_keyqueue.getLastKey(); to get the last user typed key

function listen(Void):Void -starts the actual watching over the user keys, use this to activate the actual capture

function getKeyFromQueue(pos:Number):Number - returns the pos key typed, for example if you typed omg, getKeyFromQueue(17) would return 'o' I believe in a 20 sized queue,

function toString(Void):String - convers the current KeyQueue to a string, usage: trace(my_keyqueue.toString);

the qts function is irrelevant, it basically does what toString does but being private you can't access it

function wasTyped(expression:String):Boolean - checks if the last expression typed is equal to the passed string for example wasTyped("hello") returns a boolean true if the last typed thing was "hello"

public function cheatCheck(expression:String):Boolean -identical to wasTyped

enjoy the code :)
(simple code instructions: copy contents into a new file, call it KeyQueue.as , the name is IMPORTENT, any other name WILL CAUSE A FAULT, put it in the same directory as your .fla file, the output will still be one .swf file, don't worry)

This code is under the GNU GPL meaning, edit it freely, distribute it freely, gimme credit

dynamic class KeyQueue extends MovieClip {
//KeyQueue Class V.01 by Inglor September 15th 2005
private var innerQueue:Array;
function KeyQueue(leng:Number) {
innerQueue = new Array(leng);
for(i=0;i<leng;i++){
innerQueue[i]=65;
}
}
public function getLastKey(Void):Number {
return Key.getAscii();
}
public function listen(Void):Void {
_root.keylisten = new Object();
_root.keylisten.creator = this;
_root.keylisten.onKeyDown = function(Void):Number {
this.creator.innerQueue.push(Key.getAscii(
));
return this.creator.innerQueue.shift();
};
Key.addListener(_root.keylisten);
}
public function getKeyFromQueue(pos:Number):Number {
return this.innerQueue[pos];
}
public function toString(Void):String {
s = new String();
for (var i = 0; i<this.innerQueue.length; i++) {
s += String.fromCharCode(this.innerQueue[i]);
}
return s;
}
private function qts(a:Array):String {
s = new String();
for (var i = 0; i<a.length; i++) {
s += String.fromCharCode(a[i]);
}
return s;
}
public function wasTyped(expression:String):Boolean {
var loc:Number = this.innerQueue.length-expression.length;
s = this.qts(this.innerQueue).substr(loc,this.
innerQueue.length);
trace(s);
return (s == expression);
}
public function cheatCheck(expression:String):Boolean {
return this.wasTyped(expression1);
}
}

dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Key Queue 2005-09-15 12:57:13 Reply

"go inglor, go inglor, its ya birthday, its ya birthday were gunna party like its ya birthday"

nice handy class there inglorsh, oooo, inglorsh anyways:
ill be sure to use it and or modify it once i need to

time to eat some sweet sweet pizza


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
gorman2001
gorman2001
  • Member since: Aug. 18, 2002
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Key Queue 2005-09-15 13:02:14 Reply

lol i see that u rushed to type that one :p


website :: hugostonge.com
my job :: we+are

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Key Queue 2005-09-15 13:07:42 Reply

At 9/15/05 12:57 PM, dELta_Luca wrote:

:stuff

quoted for great justice on teh quotes page :)

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Key Queue 2005-09-15 13:15:15 Reply

Me like-y.

Nice job.


BBS Signature
Starogre
Starogre
  • Member since: May. 8, 2004
  • Offline.
Forum Stats
Member
Level 18
Artist
Response to AS: Key Queue 2005-09-15 13:19:20 Reply

good jorb! I might use this some time...input text without a field eh? This should be pretty useful...i think this is a really good tutorial...surprised you didn't have to use inglorpostlimit alt account...


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature
XTra-KrazzY
XTra-KrazzY
  • Member since: Jul. 29, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Key Queue 2005-09-15 13:49:48 Reply

wow.... I'm gonna have cheats in my new game :D
I <3 cheats

Nice tutorial.
Out.

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Key Queue 2005-09-16 09:05:19 Reply

V 0.3
Big additions added before the final V1 release, you can now simply addCheat and remCheat.
also, this version (and post) are fully documented, mods, if you read this, please remove the last 3 posts by me.

common uses:
was expression typed?
cheats
other nifty stuff

since V0.03 you can use a simpler form of code and do

i = new KeyQueue(20);//20 is the length
i.listen();//starts listening to to the keys
i.setCheat("heyz", function () { //sets heyz as the cheat, and when it triggers, launches
//"function", notice that there are only 2 params, simply add ,true if you want it to only
//trigger once, read the setCheat docs for more instructions
trace("heyz"+random(50));
});

Deprecated instructions: (works)
create a new instance of the class by typing

my_keyqueue=new KeyQueue(<max length>);
//the longer the max is the bigger cheats it can contain and the more usage it takes
my_keyqueue.listen();//starts key queuing
//actual checking for cheats
this.onEnterFrame=function(){/*if in movieclip from this point on put in onClipEvent(enterFrame) /*
if(my_keyqueue.cheatCheck("hey lolz"){//replace hey lolz with your cheat
//actions that trigger when cheat is true go here
}

this is a pretty simple docs I whipper up:
NOTE: inherits from the MovieClip class to enable pathing (passing 'this' to a listener)

Properties:
innerQueue :Array
this is the actual queue the data goes in and out of. this is encapsulated so apart from knowing it's there it's not really an interest

constructor:
KeyQueue(length:Number)
creates a new KeyQueue the length of the passed parameter

Functions:
function setCheat(cheat:String, f:Function[, once:Boolean])- sets a cheat for the current queue, the once parameter is optional and it determines if the cheat triggers once or not, by default, the cheat triggers constantly , the "f" parameter is a function, remmember not to sent the () but only the name, or use the function() creator, the cheat parameter is the actual cheat, for example you can do

function myFunc(){
_root.hero.gotoAndStop(5);
}
setCheat("43243,myFunc,true);

or simply

setCheat("43243",function(){
_root.hero.gotoAndStop(5);
},true);

function remCheat() - removes the cheat set with the last setCheat call.

function getLastKey():Number - returns the last typed key, pretty useless but it makes sense to have it there, type my_keyqueue.getLastKey(); to get the last user typed key

function listen() -starts the actual watching over the user keys, use this to activate the actual capture

function getKeyFromQueue(pos:Number):Number - returns the pos key typed, for example if you typed omg, getKeyFromQueue(17) would return 'o' I believe in a 20 sized queue,

function toString():String - returns the current KeyQueue as a string

function wasTyped(expression:String):Boolean - checks if the last expression typed is equal to the passed string for example wasTyped("hello") returns a boolean true if the last typed thing was "hello"

public function cheatCheck(expression:String):Boolean -identical to wasTyped

function stop():Boolean - call this function to stop updating the queue (stop listening), this function is useless if "listen" hasn't been called, it doesn't delete the queue, it just stops updating it, returns true if the stop call was successful

function reset():Boolean - resets the current queue and stops listening formatting the current queue, returns true if both queue is reformatted and listening is stopped

function flush():Boolean --resets the content of the queue, for example if you check if a cheat is true often you want the check to only trigger once, in such a case you often want to flush the KeyQueue

enjoy :)
(instructions: copy contents into a new file, call it KeyQueue.as , the name is IMPORTENT, put it in the same dir as your fla file, it will still be one .swf file)

This code is under the GNU GPL (edit it freely, distribute it freely, credit me)


dynamic class KeyQueue extends MovieClip {
//KeyQueue class V 0.3 by Inglor Sep 15th 2005
//Last update Sep 16th 2005
private var innerQueue:Array;
public function KeyQueue(leng:Number) {
innerQueue = new Array(leng);
for (i=0; i<leng; i++) {
innerQueue[i] = 65;
}
}
public function stop(Void):Boolean {
return delete _root.keylisten;
}
public function reset(Void):Boolean {
return this.flush() && this.stop();
}
public function getLastKey(Void):Number {
return Key.getAscii();
}
public function listen(Void):Void {
_root.keylisten = new Object();
_root.keylisten.creator = this;
_root.keylisten.onKeyDown = function(Void):Number {
this.creator.innerQueue.push(Key.getAscii(
));
return this.creator.innerQueue.shift();
};
Key.addListener(_root.keylisten);
}
public function getKeyFromQueue(pos:Number):Number {
return this.innerQueue[pos];
}
public function toString(Void):String {
s = new String();
for (var i = 0; i<this.innerQueue.length; i++) {
s += String.fromCharCode(this.innerQueue[i]);
}
return s;
}
private function qts(a:Array):String {
s = new String();
for (var i = 0; i<a.length; i++) {
s += String.fromCharCode(a[i]);
}
return s;
}
public function flush(Void):Boolean {
var templen:Number = this.innerQueue.length;
this.innerQueue = new Array();
for (var i = 0; i<templen; i++) {
this.innerQueue.push(65);
}
return Boolean(this.innerQueue.length);
}
public function wasTyped(expression:String):Boolean {
var loc:Number = this.innerQueue.length-expression.length;
s = this.qts(this.innerQueue).substr(loc, this.innerQueue.length);
return (s==expression);
}
public function cheatCheck(expression:String):Boolean {
return this.wasTyped(expression);
}
public function setCheat(cheat:String, f:Function, once:Boolean):Void {
_root.createEmptyMovieClip("KeyQueueCheatC
hecker", 532432);
KeyQueueCheatChecker.ch = cheat;
_root.KeyQueueCheatChecker.func = f;
KeyQueueCheatChecker.ref = this;
if ((arguments.length == 2) || ((arguments.length) == 3 && (once == false))) {
_root.KeyQueueCheatChecker.onEnterFrame = function() {
if (this.ref.wasTyped(this.ch)) {
this.func();
}};
} else if (arguments.length == 3 && (once == true)) {
_root.KeyQueueCheatChecker.onEnterFrame = function() {
if (this.ref.wasTyped(this.ch)) {
this.func();
this.ref.remCheat();
}};
}
}
public function remCheat():Void {
delete _root.KeyQueueCheatChecker.onEnterFrame;
_root.KeyQueueCheatChecker.removeMovieClip
();
}
}