Page 1 of 1

Two questions about lua

Posted: Fri Apr 08, 2022 9:13 pm
by AlanLive2020
Sorry for asking so many questions, but

1. How do you pick up raw inputs from a keyboard/controller?

2. How do you make an if statement true if a specific star coin id is obtained in a level? I already know how to get star coin amounts from a level, but not a specific id. I want to make a menu with a list of the star coins collected, and its probably the only thing i need to know to make it.

Thanks in advance.

Re: Two questions about lua

Posted: Sat Apr 09, 2022 6:54 am
by BlueStaggo
1. You can use the onKeyboardPress(key) event or Misc.GetKeyState(key).
2. You can do this:

Code: Select all

local starcoin = require("npcs/ai/starcoin") 
starcoin.getLevelList()
and this is how to run some code if the first star coin has been collected:

Code: Select all

if starcoin[1] then
    -- Do something
end
Here's one more piece of advice: you should look at https://docs.codehaus.moe for documentation and also look at other people's libraries (I didn't know about star coins until I looked at Minimalist HUD).

Re: Two questions about lua

Posted: Sat Apr 09, 2022 12:31 pm
by AlanLive2020
BlueStag wrote:
Sat Apr 09, 2022 6:54 am
1. You can use the onKeyboardPress(key) event or Misc.GetKeyState(key).
2. You can do this:

Code: Select all

local starcoin = require("npcs/ai/starcoin") 
starcoin.getLevelList()
and this is how to run some code if the first star coin has been collected:

Code: Select all

if starcoin[1] then
    -- Do something
end
Here's one more piece of advice: you should look at https://docs.codehaus.moe for documentation and also look at other people's libraries (I didn't know about star coins until I looked at Minimalist HUD).
Thanks. Is there a way to do this with an xbox/ps4/switch controllers?

Added in 1 hour 17 minutes 30 seconds:
Ok so i tried it and i get an overwriten handler warning for some reason.Also im guessing it's useed as a function?

Re: Two questions about lua

Posted: Sun Apr 10, 2022 7:18 am
by BlueStaggo
AlanLive2020 wrote:
Sat Apr 09, 2022 1:48 pm
Thanks. Is there a way to do this with an xbox/ps4/switch controllers?
I don't think it's possible, but you should try looking at this.

Re: Two questions about lua

Posted: Sun Apr 10, 2022 7:35 am
by AlanLive2020
Hey uhh, i keep getting an overwriten handler execption or it doesn't work. Can anyone provide me with an example to returns true if control is pressed?

Edit: After a lot of trial and error I finally got it to work

Re: Two questions about lua

Posted: Sun Apr 10, 2022 2:51 pm
by deice
AlanLive2020 wrote:
Sat Apr 09, 2022 1:48 pm
Thanks. Is there a way to do this with an xbox/ps4/switch controllers?
there is the "onControllerButtonPress" event but i'm not sure if it triggers while the game is paused, and to my knowledge there's no other way to handle controller input through lua.