|
| 29 Dec 2014 09:34 PM |
How can i do this? I was told that you can use inputservice to check if TAB has been pressed, but the wiki link doesnt mention key down functions :/ Wiki link: http://wiki.roblox.com/index.php?title=API:Class/UserInputService |
|
|
| Report Abuse |
|
|
025110
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 57661 |
|
|
| 29 Dec 2014 09:37 PM |
| there's a key:byte number for it |
|
|
| Report Abuse |
|
|
025110
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 57661 |
|
|
| 29 Dec 2014 09:39 PM |
http://wiki.roblox.com/index.php/Special_Characters
if (key:byte() == 48) then |
|
|
| Report Abuse |
|
|
025110
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 57661 |
|
| |
|
Unclear
|
  |
| Joined: 27 Aug 2011 |
| Total Posts: 17060 |
|
|
| 29 Dec 2014 09:42 PM |
"there's a key:byte number for it"
No point in doing that when your code reads a lot better using UserInputService instead. Lua is a high enough level language (far away from machine code) that the difference between these sorts of things is completely trivial, which is why readability is (almost) always preferred.
Use the InputBegan event from UserInputService. Recall that UserInputService is a service, so you should get the event like so...
game:GetService("UserInputService").InputBegan:connect(inputBegan)
We will create the inputBegan function. InputBegan (the event) returns an InputObject. If you look at the wiki, you will see that InputObjects have a property called KeyCode. This returns an Enum value (Enum.KeyCode) that you can use to compare values. If we wanted to print "hello" everytime we pressed the X key, we would get type the following...
function inputBegan(inputObject) local keyCode = inputObject.KeyCode if keyCode == Enum.KeyCode.X then print("hello") end end
game:GetService("UserInputService").InputBegan:connect(inputBegan)
You can read more about the above in the following links...
http://wiki.roblox.com/index.php?title=InputBegan_(Event) http://wiki.roblox.com/index.php?title=InputObject http://wiki.roblox.com/index.php?title=API:Class/InputObject/KeyCode
Good luck! |
|
|
| Report Abuse |
|
|
025110
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 57661 |
|
|
| 29 Dec 2014 09:43 PM |
| whats the point of that if you can just do key:byte |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2014 09:45 PM |
Yes, but tab(9) doesnt work with mouse.Keydown I heard using inputservice would work, somehow.
|
|
|
| Report Abuse |
|
|
Unclear
|
  |
| Joined: 27 Aug 2011 |
| Total Posts: 17060 |
|
|
| 29 Dec 2014 09:46 PM |
| byte is nearly unreadable unless you know it by heart or refer to a chart. Commenting code for that is unnecessary as well. Why would you use byte? Making your code more unreadable is a ridiculous thing to do and is only done by people who really have no idea what they are doing, or are just trying to impress newbies with complex code. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2014 09:59 PM |
| Well what's the alternate for tab? |
|
|
| Report Abuse |
|
|
Unclear
|
  |
| Joined: 27 Aug 2011 |
| Total Posts: 17060 |
|
|
| 29 Dec 2014 10:05 PM |
http://wiki.roblox.com/index.php?title=API:Enum/KeyCode
Enum.KeyCode.Tab will do. |
|
|
| Report Abuse |
|
|
025110
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 57661 |
|
|
| 29 Dec 2014 10:24 PM |
| lol you're telling me key:byte is complex and unreadable |
|
|
| Report Abuse |
|
|
Unclear
|
  |
| Joined: 27 Aug 2011 |
| Total Posts: 17060 |
|
|
| 29 Dec 2014 10:35 PM |
| It's a lot less readable than something that reads like pure English, haha. There is no way you really believe that comparing the numerical output of :byte() is more readable than comparing with Enum.KeyCode. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2014 10:39 PM |
025110 you should stop before you sound sillier than you already do ;/
~CoffeeFlux. For you. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2014 10:44 PM |
| i understand what 025 is saying, doesn't look silly to me |
|
|
| Report Abuse |
|
|
025110
|
  |
| Joined: 23 Nov 2012 |
| Total Posts: 57661 |
|
|
| 29 Dec 2014 10:55 PM |
jsing mine is easier
+who cares if your script doesnt read like english |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2014 11:06 PM |
"jsing mine is easier" not necessarily, you have to look up the bytecode each time
"+who cares if your script doesnt read like english" oh my god are you serious code readability matters a lot /lot/
~CoffeeFlux. For you. |
|
|
| Report Abuse |
|
|