1 posts
Posted 29 November 2016 - 04:29 AM
Hi guys current i making a simple program for enter key but an error occur in 3rd line.
Is there any problem with these coding?
function(input)
local event
If event == input then
local key = os.pullEvent()
key = keys.enter
end
end
7083 posts
Location
Tasmania (AU)
Posted 29 November 2016 - 06:19 AM
Lua is case sensitive; you meant "if" instead of "If".
Other than that, it's not obvious what you expect this script to actually do. If you have further problems, provide more details on what you're actually expecting.
119 posts
Posted 30 November 2016 - 01:02 AM
Assuming you're trying to test for a "key" event, and testing that the key expected is meant to be the enter key, here is what you could be doing wrong:
- You're defining a function, however you're not giving it a name. This will likely result in a error looking near to: 'name' expected.
To define the function, just put the name between the 'function' and the '()'. For example, function test(input) … end can be run with test(input)
- The variable event is being defined to nil. You're then checking if input is equal to event (= nil), which is only true when you do not give it input at all.
- The variable key will be assigned to the event from os.pullEvent.
- The variable key is then overwritten to the value of keys.enter, which is 28. Therefore keys will be equal to 28 instead of the event from os.pullEvent.
How to fix these problems:
- If you're looking to only get the event which is inserted by input ,you can just instead use the line os.pullEvent(input), as os.pullEvent allows for one optional argument defining which events it will filter to you.
- Look at the page for os.pullEvent. In order to get the key which has been pressed for the event, "key" or "key_up", it will put the key as the first parameter, however event is technically the first so this would be second. You can use something like this, "local event,key = os.pullEvent(input)" so that it will assign the first parameter to "event" and the second to "key"
- Use the "key" variable you assigned above to test if key == keys.enter.