I wanna use the love.keyreleased(key) in another lua file and require it in main.lua .
But when i do this, the love.keyreleased(key) of main.lua become unuseable.
Have any idea to solve this problem? I need some help.
How to use function love.keyreleased(key) in another lua file
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- amightydish
- Prole
- Posts: 11
- Joined: Fri May 12, 2017 5:18 pm
Re: How to use function love.keyreleased(key) in another lua file
If you implement the function in two places, they will override each other. The last one defined will be the one used.
Why don't you just have the keyreleased function in main and then call your own function, e.g. a submodule.mykeyreleased(key) from it?
Here an example
mystuff.lua
main.lua
I'm typing this on the phone so can't test it, but I hope you get the idea.
Why don't you just have the keyreleased function in main and then call your own function, e.g. a submodule.mykeyreleased(key) from it?
Here an example
mystuff.lua
Code: Select all
function my_keyhandler(key)
print("key released:", key)
end
main.lua
Code: Select all
require("mystuff")
function love.keyreleased(key)
my_keyhandler(key)
end
I'm typing this on the phone so can't test it, but I hope you get the idea.
Re: How to use function love.keyreleased(key) in another lua file
thank u!You are really friendly. I know how to do this from your codes.
If i want to use it in three lua file,should i have three different functions in different lua file to use it?
eg:
function my_keyhandlerone(key)
print("key released:", key)
end
function my_keyhandlertwo(key)
print("key released:", key)
end
function my_keyhandlerthree(key)
print("key released:", key)
end
I am not good at lua.Please tell me about how to use it easily.
If i want to use it in three lua file,should i have three different functions in different lua file to use it?
eg:
function my_keyhandlerone(key)
print("key released:", key)
end
function my_keyhandlertwo(key)
print("key released:", key)
end
function my_keyhandlerthree(key)
print("key released:", key)
end
I am not good at lua.Please tell me about how to use it easily.
Re: How to use function love.keyreleased(key) in another lua file
Do you mean use the same function in multiple files? You could:
Also when including code on a forum post, please wrap it in a code tag. Makes it easier for anyone to help you.
- Require the file once, and have that file create global variables.
- Require the file once, and return as a global variable.
- Require the file in every other file that needs it, and return a local variable.
Also when including code on a forum post, please wrap it in a code tag. Makes it easier for anyone to help you.
Code: Select all
Re: How to use function love.keyreleased(key) in another lua file
Thanks your help.I have understood it.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests