BackDoor- Door 1
You find yourself in a strange house with only a man on the phone as a guide.
4.07 / 5.00 28,368 ViewsMini Commando
Action adventure game with nazi enemies in the second world war.
3.88 / 5.00 24,839 Views'Better than having sex with a noob'
AS: KeyCode
So all of you know how to check if Space or Enter is pressed, by simply applying the following code:
if(Key.isDown(Key.SPACE))
But you have always wondered how to use WASD and 1 2 3. That's why I'm making this tutorial. It will teach you how to use different keys for your games, better than up down left right.
KeyCodes: How to use?
This is very simple and alike to other keys. Simply use:
if(Key.isDown(<keycode here>))
What are the keycodes?
Numbers
The following keycode are codes you need to use for all the numbers appearing on your keyboard: 1,2,3,4,5,6,7,8,9,0.
1 = 49.
2 = 50.
3 = 51.
4 = 52.
5 = 53.
6 = 54.
7 = 55.
8 = 56.
9 = 57.
0 = 58.
Example:
if(Key.isDown(50)){
trace("Yay!");
}
That would trace 'yay' if the key '2' is pressed.
KeyCodes: Alphabet
Now this is very simple, just like the numbers every letter of the alphabet has its own code.
a = 65
b = 66
c = 67
d = 68
e = 69
f = 70
g = 71
h = 72
i = 73
j = 74
k = 75
l = 76
m = 77
n = 78
o = 79
p = 80
q = 81
r = 82
s = 83
t = 84
u = 85
v = 86
w = 87
x = 88
y = 89
z = 90
Example:
if(Key.isDown(65)){
trace("You pressed 'A' ");
}
Output for if you press A:
You pressed 'A'
That's it, you're done.
Have a nice day.
-Toast.
Bai.
Did you know 'i//' would divide the var i with itself? :D
At 1/20/06 06:24 AM, -Gust- wrote: Did you know 'i//' would divide the var i with itself? :D
did you know nobody fucking care so stop posting this in every AS thread dumbass!!!
Nice toast!
You hurt my feelings. ;o;
Alright, I'll get back to doing something useful then.
Great script Toast, you should of included this though (mini tut I'm about to post):
You can also easily make something happen when a key is released. By doing so you would use the keyUp method.
onClipEvent(keyUp){
//stuff
}
I don't see a need to explain that code, it is self explanatory, but what it does is register than when any key is released and not pressed, then you can add your actions so it tells something to do something.
How would I specify that for a certain key?
Simple, this is where variables come in. Simply make it so when a key is pressed, a variable is defined (use Toat's tutorial above).
For example:
onClipEvent(enterFrame){
up=0
if(Key.isDown(Key.UP)){
up=1
}
}
onClipEvent(keyUp){
if(up==1){
//stuff
}
}
That means that when you press the key UP, the variable 'up' is defined as 1. With that said, when any key is released and up is = to 1 (from when you pressed UP) then something happens.
So yeah that's pretty much it, sorry if what I said doesn't make much sense, I hope it did. I don't write tutorials much as you can tell, but hope that helps. It is a really good way for something to happen when you release a key.
Oh, great tutroial Toast, that will help a lot of n00bies :P
Oops sorry, that was my alt account. above post was posted by me
lol
1. I didn't post any script...
2. Nah, this is a KeyCode tutorial, not Key is down and key is up.
At 1/20/06 12:21 PM, -Toast- wrote: 1. I didn't post any script...
2. Nah, this is a KeyCode tutorial, not Key is down and key is up.
oops.
1. Didn't mean to say "great script" meant tutorial.
2. True, oh well it's okay, my fault, good job it is a very helpful tutorial :P
4. Here is a simple Keygetter I made: link [in my sig]
4. That pwns. I think there should be a section in AS: Main for none NG topic AS tutorials.
At 1/20/06 06:24 AM, -Gust- wrote: Did you know 'i//' would divide the var i with itself? :D
1) no it won't, because // is a comment line
2) i divided by itself is 1, hence it's fucking redundant anyway
you fail
At 1/20/06 07:51 AM, Khao wrote:At 1/20/06 06:24 AM, -Gust- wrote: Did you know 'i//' would divide the var i with itself? :Ddid you know nobody fucking care so stop posting this in every AS thread dumbass!!!
Whoa too much coffee for someone
Crap tutorial toast stop trying
- Matt, Rustyarcade.com
At 1/22/06 09:50 AM, Sekky wrote:At 1/20/06 06:24 AM, -Gust- wrote: Did you know 'i//' would divide the var i with itself? :D1) no it won't, because // is a comment line
2) i divided by itself is 1, hence it's fucking redundant anyway
Hehe, don't you understand...? :P
http://www.newground../topic.php?id=417297
http://www.newground../topic.php?id=417284
At 1/22/06 10:01 AM, -Toast- wrote: Hehe, don't you understand...? :P
http://www.newground../topic.php?id=417297
http://www.newground../topic.php?id=417284
...I feel null and void after reading those
one thing i like to do in flash when dealing lots of keycodes is, i declare a variable = to the Key.isDown condition. id put this right below the start of the clipEvent
_global.a=Key.isDown(65)
then when i wanna use it i just say
if(a){}
its great when you use alot of ifs of the same kind(like for doubletap keys)
At 1/22/06 11:58 AM, ImpotentBoy2 wrote: _global.a=Key.isDown(65)
if(a){}
how is that anymore efficient than if (Key.isDown(65)) { }
it's actually less efficient doing it that way.
At 1/22/06 12:30 PM, Sekky wrote: how is that anymore efficient than if (Key.isDown(65)) { }
He didn't say it was more efficient, he said he liked to do that =/
At 1/22/06 12:35 PM, Rantzien wrote: He didn't say it was more efficient, he said he liked to do that =/
True, point withdrawn
At 1/22/06 12:30 PM, Sekky wrote:At 1/22/06 11:58 AM, ImpotentBoy2 wrote: _global.a=Key.isDown(65)how is that anymore efficient than if (Key.isDown(65)) { }
if(a){}
it's actually less efficient doing it that way.
why is it less efficient, because it has more lines?
well this way only checks if its down once, instead of checking over and over it just refers to the boolean. so i think it would bemore efficient. but when i tested it, i tried haveing like 40 ifs with
_x++;_x--;_rotation=random(360)
and they took less than 1 millisecond to do. but every once and a while the one with Key.isDown(65) in each if would say 1 millisecond instead of 0 and they were tested simultaneously so bleh.
At 1/22/06 01:05 PM, ImpotentBoy2 wrote: why is it less efficient, because it has more lines?
well this way only checks if its down once, instead of checking over and over it just refers to the boolean. so i think it would bemore efficient. but when i tested it, i tried haveing like 40 ifs with
It only checks once anyway... if(meh) { }
At 1/22/06 01:06 PM, Sekky wrote: It only checks once anyway... if(meh) { }
are you sure about that? out of 158 tests, my way took shorter timer to process 58 times, the regular way was shorter 7 times. most of the time they both took 0 milliseconds saince i guess i didnt try anything too computer intesive.
At 1/22/06 01:27 PM, ImpotentBoy2 wrote:At 1/22/06 01:06 PM, Sekky wrote: It only checks once anyway... if(meh) { }are you sure about that? out of 158 tests, my way took shorter timer to process 58 times, the regular way was shorter 7 times. most of the time they both took 0 milliseconds saince i guess i didnt try anything too computer intesive.
wait, are you using multiple if (meh) {} if (meh) {} statements in the same code?
At 1/22/06 01:28 PM, Sekky wrote: wait, are you using multiple if (meh) {} if (meh) {} statements in the same code?
this is the code im using to check
onClipEvent (load) {
var ties:Number = 0;
var wins:Number = 0;
var loss:Number = 0;
var said:Boolean = false;
}
onClipEvent (enterFrame) {
var t:Number = getTimer();
//time it started my ways test
var a:Boolean = Key.isDown(65);
for (var i = 0; i < 5000; i++) {
if (a) {
_x++;
_x--;
_rotation = random(360);
}
}
if (a) {
var myTime:Number = getTimer() - t;
//time it took for my ways test
}
t = getTimer();
//time it started other ways test
for (i = 0; i < 5000; i++) {
if (Key.isDown(65)) {
_x++;
_x--;
_rotation = random(360);
}
}
if (Key.isDown(65)) {
var otherTime:Number = getTimer() - t;
//time it took for other ways test, all code afterwards is not counted in that number so it should be 100% accurate.
myTime < otherTime ? wins++ : myTime > otherTime ? loss++ : ties++;
//tallys up score
said = false;
//allows it to trace score
} else if (!a && (wins || losses || ties) && !said) {
trace([wins, loss, ties]);
said = true;
//so it only traces once
}
_rotation = 0;
}
i changed the for loop from 50 to 5000 to get a more accurate answer.
At 1/22/06 01:43 PM, ImpotentBoy2 wrote: stuff
Gotcha, my bad
At 1/22/06 01:52 PM, Sekky wrote:At 1/22/06 01:43 PM, ImpotentBoy2 wrote: stuffGotcha, my bad
lol serv't
Sweet tut Toast. I've been wondering how to use letter and number keys. Reminds me of graphing calc programming.