Events with lunalua

Need help with any SMBX game-related issues? Ask your questions here.
User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Events with lunalua

Postby KnuckleChuckle » Wed Jan 15, 2020 7:04 pm

Another quick question on here. Is it possible to activate a lunalua script with events?

User avatar
FireyPaperMario
Peach
Peach
Posts: 5977
Joined: Sat Sep 27, 2014 1:39 pm
Flair: 90's kid born in late 1993 ^_^
Contact:

Re: Events with lunalua

Postby FireyPaperMario » Wed Jan 15, 2020 7:19 pm

It is 100% possible to active events using Lunalua! But can you explain what events you were thinking of?
Image
(Coming soon in 84 days from today: Sega Mega Drive GFX pack)
Mario RPG goals (62% of the goals completed)
My Pixiv
I'm autistic & have ADHD

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Wed Jan 15, 2020 8:20 pm

So i'm trying to activate a code that lets the player switch characters by the push of a button, and its supposed to activate once you talk to peach, because then talking to her would activate the event.

User avatar
8lue Storm
Volcano Lotus
Volcano Lotus
Posts: 547
Joined: Thu Jan 18, 2018 9:53 am
Flair: its pronounced bluestorm

Re: Events with lunalua

Postby 8lue Storm » Wed Jan 15, 2020 9:18 pm

KnuckleChuckle wrote:
Wed Jan 15, 2020 8:20 pm
So i'm trying to activate a code that lets the player switch characters by the push of a button, and its supposed to activate once you talk to peach, because then talking to her would activate the event.
Wait, so you gain the ability of switching characters after talking to Peach or do you switch characters right after talking to Peach?
Image

i never performed a shelljump and it's sad I did a grand total of 4 shelljumps in my life!

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Wed Jan 15, 2020 9:25 pm

You gain the ability

User avatar
Daring Tombstone
Bit
Bit
Posts: 142
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Events with lunalua

Postby Daring Tombstone » Thu Jan 16, 2020 12:17 am

Assuming this what you're asking here's an example.

Image

Nevermind I'm a special kind of stupid.
Last edited by Daring Tombstone on Thu Jan 16, 2020 1:57 am, edited 1 time in total.
Happy Dance
Image
Check out my completed episode
Spoiler: show
Image
Check out my halloween level
Spoiler: show
Image

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8738
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Events with lunalua

Postby Enjl » Thu Jan 16, 2020 1:07 am

Daring Tombstone wrote:
Thu Jan 16, 2020 12:17 am
Assuming this what you're asking here's an example.

Image

Pretty simple yeah?
Not quite. The behaviour expected is an unlock, from what I gather. So, instead of putting all the code into onEvent, it would be better to use onEvent to toggle a boolean variable that otherwise gates off the code that runs in other events like onTick (for input checking and logic) and onDraw (if there are any components to draw to the screen).
Image
Setting "canSwitchCharacters" to true in onEvent would be emblematic of the action of "gaining the ability", since it allows the code inside the if statement in other events to execute.

In the spoiler below is a version that permanently sets the variable for the episode, even across levels (MAGLX3 build, PAL build and newer versions only):
Spoiler: show
Image
Ideas are useless if you can't make them real.
Image

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Thu Jan 16, 2020 7:05 pm

hmmm. On event never seems to work for me. I keep getting the error end is expected(to close function at line 1) near <eof>. But when I add end it says <eof> expected near end.

User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1240
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl

Re: Events with lunalua

Postby Hoeloe » Thu Jan 16, 2020 8:14 pm

That suggests you're adding it in completely the wrong place. Copy the format shown above, and if it still doesn't work, post your code here.

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Thu Jan 16, 2020 9:11 pm

SaveData.canSwitchCharacters = false
function onEvent(eventName)
if eventName == "Transformation" then
SaveData.canSwitchCharacters = true
end
end


function onTick()
if SaveData.canSwitchCharacters then
function onKeyboardPress(keycode)
if keycode == 0x31 then
player:transform(CHARACTER_MARIO)
elseif keycode == 0x32 then
player:transform(CHARACTER_PEACH)
elseif keycode == 0x33 then
player:transform(CHARACTER_TOAD)
end
end
end
end

User avatar
Daring Tombstone
Bit
Bit
Posts: 142
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Events with lunalua

Postby Daring Tombstone » Thu Jan 16, 2020 9:31 pm

You can't have a function in a function I don't believe. You would need to end function ontick before starting function onkeyboardpress. But I would see what a lua expert says.
Happy Dance
Image
Check out my completed episode
Spoiler: show
Image
Check out my halloween level
Spoiler: show
Image

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Thu Jan 16, 2020 10:31 pm

Image

User avatar
Daring Tombstone
Bit
Bit
Posts: 142
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Events with lunalua

Postby Daring Tombstone » Fri Jan 17, 2020 12:58 am

Would you need onTick here? Can't we just do something like.

function onKeyBoardPress(keycode)
if SaveData.canSwitchCharacters == true then
if keycode == 0x31 then
player:transform(CHARACTER_MARIO)
elseif keycode == 0x32 then
player:transform(CHARACTER_PEACH)
end
end
end

Or is this not the right way to do this? I'm a lua noob myself. Also in your script if SaveData.canSwitchCharacters needs a double ='s since it's checking the boolean.
Happy Dance
Image
Check out my completed episode
Spoiler: show
Image
Check out my halloween level
Spoiler: show
Image

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8738
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Events with lunalua

Postby Enjl » Fri Jan 17, 2020 1:18 am

OnKeyboardPress is inconvenient because it assumes players never change their control layout. Imagine setting the keys to Q and E just to find out someone plays your level with a controller. Whoops!
But if you really wanna do this, then Daring Tombstone's suggestion is right. In my prior post when I suggested onTick for input checking I assumed you wanted to make use of the inputs SMBX already recognizes.
Ideas are useless if you can't make them real.
Image

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Tue Apr 28, 2020 4:02 pm

My concern isn't really about the whole controller thing since i'd assume most would have a keyboard if they were to access the internet. So if onkeyboard press is inconvenient then what would I use?

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8738
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Events with lunalua

Postby Enjl » Tue Apr 28, 2020 4:12 pm

If you want to rely on keyboard and people not happening to use the keys you use, onKeyboardPress.
If you want to instead use SMBX's internal controls, you check for them in onTick with stuff like if player.keys.[down/up/left/right/altRun/altJump/dropItem/jump/run/pause] == KEYS_[PRESSED/DOWN/UP/UNPRESSED] then (where the options in brackets are the available keys and states). (you will probably have to rethink the input method into some form of menu. Sounds a tad more intiutive than pressing a random key either way.)
That's the two options you have.
Ideas are useless if you can't make them real.
Image

User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1240
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl

Re: Events with lunalua

Postby Hoeloe » Tue Apr 28, 2020 11:52 pm

Enjl wrote:
Tue Apr 28, 2020 4:12 pm
if player.keys.[down/up/left/right/altRun/altJump/dropItem/jump/run/pause] == KEYS_[PRESSED/DOWN/UP/UNPRESSED] then
I do want to stress here that your options should really be:

if player.keys.jump == KEYS_PRESSED then (for "player just pressed the key")

if player.keys.jump == KEYS_RELEASED then (for "player just released the key")

if player.keys.jump then (for "player is holding the key")

if not player.keys.jump then (for "player is not holding the key")


KEYS_UP and KEYS_DOWN are very niche and shouldn't be used in most circumstances.

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Wed Apr 29, 2020 2:51 pm

My apologies if I'm inconveniencing any of you. The whole process to get the the character unlock does not seem to be working.
Image


I had the event activate when you talk to peach, however when I test it for myself nothing happens. I think I'm still doing this wrong

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8738
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Events with lunalua

Postby Enjl » Wed Apr 29, 2020 3:11 pm

Looks like you capitalized onKeyboardPress wrong. The "b" needs to be lowercase: https://wohlsoft.ru/pgewiki/LunaLua_events
Ideas are useless if you can't make them real.
Image

User avatar
KnuckleChuckle
Koopa Troopa
Koopa Troopa
Posts: 22
Joined: Mon Jul 23, 2018 10:06 pm

Re: Events with lunalua

Postby KnuckleChuckle » Wed Apr 29, 2020 3:20 pm

dang you're right. It works perfectly now. Thank you!


Return to “Help and Support”

Who is online

Users browsing this forum: No registered users and 10 guests