Two questions about lua

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

AlanLive2020
Buster Beetle
Buster Beetle
Posts: 98
Joined: Fri Nov 27, 2020 8:15 am
Flair: The guy with no social skills or self-esteem :')

Two questions about lua

Postby AlanLive2020 » Fri Apr 08, 2022 9:13 pm

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.

BlueStaggo
Koopa
Koopa
Posts: 19
Joined: Sat Feb 20, 2021 8:18 am
Pronouns: he/him
Contact:

Re: Two questions about lua

Postby BlueStaggo » 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).

AlanLive2020
Buster Beetle
Buster Beetle
Posts: 98
Joined: Fri Nov 27, 2020 8:15 am
Flair: The guy with no social skills or self-esteem :')

Re: Two questions about lua

Postby AlanLive2020 » Sat Apr 09, 2022 12:31 pm

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?

BlueStaggo
Koopa
Koopa
Posts: 19
Joined: Sat Feb 20, 2021 8:18 am
Pronouns: he/him
Contact:

Re: Two questions about lua

Postby BlueStaggo » Sun Apr 10, 2022 7:18 am

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.

AlanLive2020
Buster Beetle
Buster Beetle
Posts: 98
Joined: Fri Nov 27, 2020 8:15 am
Flair: The guy with no social skills or self-esteem :')

Re: Two questions about lua

Postby AlanLive2020 » Sun Apr 10, 2022 7:35 am

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

deice
Rocky Wrench
Rocky Wrench
Posts: 638
Joined: Fri Jul 23, 2021 7:35 am

Re: Two questions about lua

Postby deice » Sun Apr 10, 2022 2:51 pm

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.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari