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

This is a strange bug with UserInputService, is it not?

Asked by 10 years ago

UserInputService is messy. Everything is defined. The only thing that doesn't go according to plan is that the ToggleEquipSword function doesn't trigger when I press One, nor does it notify me in the output that I pressed a key. It only prints the type of user input.

01userInput.InputBegan:connect(
02    function(input)
03        print(input.UserInputType)
04        if input.UserInputType == 'Keyboard' then
05            print('Keyboard') --To let me know that I've pressed a key
06            if input.KeyCode == Enum.KeyCode.One then
07                print'1'
08                ToggleEquipSword()
09            end
10        end
11    end
12)

Strangely enough, even though the UserInputType is Keyboard, It doesn't print 'Keyboard' to the output as intended

0
Change line 6 to 'if input == Enum.KeyCode.One then'. Goulstem 8144 — 10y
0
That's not helpful for explaining. Even though your solution is correct. I prefer Taslem's answer. DragonODeath 50 — 10y

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

input.UserInputType isn't a string -- it's an enum. (You can print it out to check this)

Things of different types will not usually be equal.


Enums represent "enumerated" values.

This is meant to solve a problem related to what you're doing.

What happens if I say part.TopSurface = "Blorp"? "Blorp" isn't one of the surface types. Enums are a solution where you explicitly state all of the values that are acceptable: Enum.SurfaceType. has them all. (Of course, ROBLOX lets you use strings usually for assignment).



1local KeyboardEnum = Enum.UserInputType.Keyboard
2 
3.....
4 
5    if input.UserInputType == KeyboardEnum then
1
Oh, only for assignment. I see. Thank you, you've been of great help, Portal guy. DragonODeath 50 — 10y
Ad

Answer this question