Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Function keyDown(key) how to?

Asked by 10 years ago

I have a script here

function keyDown(key)
    if key == "e" then
script.Parent.Parent.Frame.Visible = true
script.Parent.Visible = false
script.Parent.Parent.Frame.Play.Script.Disabled = false
    end
end 

The problem is, how do you make it so the script activates when you press esc?

Do you type in Esc, Escape, etc.

1 answer

Log in to vote
0
Answered by 10 years ago

http://wiki.roblox.com/index.php?title=File:Ascii_Table.png

Here is a list of the ASCII characters used in Lua, if you look down a bit, you can see that no. 27 is for the escape key.

In order to detect what key was pressed, we need to convert the key (Which is a string) into it's ASCII decimal representation, and then we can check to see if the key is really the escape key.

To convert a string (Ie: "a") into a decimal (65), we use string.byte(string).

Since we know that the ASCII value of the esc key is 27, we can use string.byte to see if they pressed the escape key.

function keyDown(key)
    if string.byte(key) == 27 then
script.Parent.Parent.Frame.Visible = true
script.Parent.Visible = false
script.Parent.Parent.Frame.Play.Script.Disabled = false
    end
end 
0
Thanks! EzraNehemiah_TF2 3552 — 10y
Ad

Answer this question