generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Mapping the number strip?

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Nov 2014 10:35 PM
I can use the KeyUp method to get the number keys but there are other keys on the keyboard that have the same byte string as some of the numbers. For example, the Right Ctrl key has the same byte string as the 2 key.

Is there any other way to map these keys without mapping unwanted ones?
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
28 Nov 2014 11:17 AM
local keys = {
["One"] = function()
print("1")
end;
E = function()
print("E")
end;
Q = function()
print("Q")
end;
}

game:getService("UserInputService").InputBegan:connect(function(key)
if keys[tostring(key.KeyCode):sub(14)] then
keys[tostring(key.KeyCode):sub(14)]()
else
print("No hotkey set up to: " .. tostring(key.KeyCode):sub(14))
end
end)
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 12:36 PM
local keys = {
["One"] = function()
print("1")
end;
["Two"] = function()
print("1")
end;
["Three"] = function()
print("1")
end;


}

game:getService("UserInputService").InputBegan:connect(function(key)
if keys[tostring(key.KeyCode):sub(14)] then
keys[tostring(key.KeyCode):sub(14)]()
else
print("No hotkey set up to: " .. tostring(key.KeyCode):sub(14))
end
end)

2 and 3 are printing out as 1. I may need an explanation for this service.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
28 Nov 2014 12:42 PM
UserInputService allows you to get the rotation, movement, taps, and et cetera of a mobile device, as well as functions for keyboard and mouse.

key.KeyCode is an enum. I don't think you can just do :sub(14) on an enum.

So, you can do
Keys[key.KeyCode]()
and for the functions
Keys = {}
Keys[Enum.KeyCode.LeftShift] = function() end
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
28 Nov 2014 12:43 PM
Actually, I don't remember exactly how I did it, but you can look in my models to see, since I made a module for UserInputService. I'm still working on it occasionally, but I used some method in there for this specific purpose.
Report Abuse
ModuleMaker is not online. ModuleMaker
Joined: 26 Sep 2014
Total Posts: 182
28 Nov 2014 12:48 PM
To get the last item of an Enum, this works for most you can use the string pattern %a+$

For example:
print(tostring(Enum.KeyCode.One):match('%a+$')) -->One
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 12:49 PM
local keys = {
["One"] = function()
print("1")
end;
["Two"] = function()
print("1") <------- Really? Am I that freakin blind?
end;
["Three"] = function()
print("1") <------- I might be that freakin blind lmao
end;
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
28 Nov 2014 12:58 PM
Bli-iiind
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 01:02 PM
Jarod you only have 2 pages of models and didn't see anything on input.
I like the idea of this UserInputService, but it seems more complicated than it should be.
I'm a visual thinker so I need a proper example with step by step explanations for each line. It's the only way I can learn.

An example that simply prints would be sufficient but I'll still need explanations for each line.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
28 Nov 2014 01:12 PM
http://www.roblox.com/Input-Module-item?id=185662108

Oh also, it says in the description that it has no documentation, but I think I recently added it.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 01:24 PM
I don't understand any of it.


How bout we just focus on the original reply for now.


if keys[tostring(key.KeyCode):sub(14)] then
keys[tostring(key.KeyCode):sub(14)]()
else

What's up with this? First off, I don't know what :sub(14) is and I can't find it on the wiki.
Secondly, it's confusing.

if keys[tostring(key.KeyCode):sub(14)] then --ok there's a condition
keys[tostring(key.KeyCode):sub(14)]() --This makes no sense. I thought this was the condition?
--Why is it trying to apply a function that is already the condition?
else
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 01:28 PM
It just doesn't make any sense.
That's like saying:

IF (Doge is brown) then
(Doge is brown)
else

It's applying the condition as a command. That doesn't make any sense to me.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
28 Nov 2014 01:30 PM
game:getService("UserInputService").InputBegan:connect(function(key)
print(tostring(key.KeyCode))
end)

press 1 -->Enum.KeyCode.One
Enum.KeyCode. is 13 letters
sub(14) gets letters 14 and up, so 'One'


in a condition, anything thats not false or nil is counted as true
so

local keys = {
A = function()
print("A")
}

if keys["A"] then --keys.A is a function, a function is not false or nil
keys["A"]() --call the function
end

if keys["B"] then --keys.B does not exist, it is nil, if we don't check if it exist first we would try to do nil() and nil is not a function
keys["B"]()
end
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 01:41 PM
OH! Now I get it!

So what we're actually doing here is placing the functions themselves into the table.
If the function does not exist, it prints nil pretty much, but if the function does exist, it applies the function.
Ok I get it now.

I think I can do this. Just one last question. Will I have to worry about key tangling?

For example there have been situations where I tried KeyDown with W and D for airplanes and while holding down W and pressing D then letting go of W, W would still fire. I call that key tangling.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
28 Nov 2014 01:42 PM
that depends on how you set up your keys to repeat while the key is being held down
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 01:44 PM
oh the repeating caused it? That explains that because WASD did have repeating functions when I did them.

My plans for this game don't call for anything to repeat that I can think of as far as these controls go.
Yeah I think this will work perfectly. Thank you so much.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 01:50 PM
Since this is so new to me, is there any way I can talk you into giving me a list of the keys I can use for this and how to use them? Or maybe a link to a list?

So, for 1, I type out "One", but let's say I wanted to use \, I don't know if I can type out "Backslash".
I just want to know my options.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
28 Nov 2014 03:11 PM
game:getService("UserInputService").InputBegan:connect(function(key)
print(tostring(key.KeyCode))
end)
Use that to see what the key is
Just press the key you need to know

heres a list though
http://wiki.roblox.com/index.php?title=API:Enum/KeyCode
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
28 Nov 2014 05:19 PM
Just wanted to give you guys an update on my progress. I'm finally beginning to understand this really well and I've been having a lot of fun experimenting with it.

I've been able to bypass the animation glitch roblox created to create my own animations using welds instead of having to create a fake character first, though I may still do that because of joints and whatnot.
I prefer elbows and knees in my characters. xD

Thanks a lot for all the help. My game is coming along extremely slowly but it is coming along. Hopefully in a few months I should have a pretty nice alpha ready to test.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image