Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat Jan 12, 2019 6:23 pm

The NPC array index is used by vanilla SMBX. Basically the way SMBX handles NPCs is by shoving them all into a large array. The index into that array is stored in the NPC, and that index is how many things in the core game reference NPCs. The issue with it is that the array is quite commonly reshuffled, so that index is often invalidated. This means that storing NPCs over time can often mean the indices end up pointing to the wrong place (which is how those fun bugs work that make Mario hold nothing and such). The way pnpc works is by creating permanent references to NPCs, so that even if the array reshuffles, references to them are still valid, completely bypassing the issues with the array index referencing system used in most places.

fern
Swooper
Swooper
Posts: 56
Joined: Sat Dec 02, 2017 8:59 pm

Re: Need help with lua? - LunaLua General Help

Postby fern » Sun Jan 13, 2019 4:32 am

Is there a way to bypass the NPC's speedX limit? I'm trying to make enemies hit bounce back. SpeedY works as intended but changing it's speedX simply reverses the NPC's direction as it continues to walk at the same speed.

Quantumenace
Ripper II
Ripper II
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Sun Jan 13, 2019 12:37 pm

Hoeloe wrote:
Sat Jan 12, 2019 6:23 pm
The NPC array index is used by vanilla SMBX. Basically the way SMBX handles NPCs is by shoving them all into a large array. The index into that array is stored in the NPC, and that index is how many things in the core game reference NPCs. The issue with it is that the array is quite commonly reshuffled, so that index is often invalidated. This means that storing NPCs over time can often mean the indices end up pointing to the wrong place (which is how those fun bugs work that make Mario hold nothing and such). The way pnpc works is by creating permanent references to NPCs, so that even if the array reshuffles, references to them are still valid, completely bypassing the issues with the array index referencing system used in most places.

Yes, but offset 0xE6 isn't used by vanilla SMBX and is not one of these references by default. Line 11 of pnpc:

Code: Select all

local ID_FIELD = 0xE6 -- (Presumably) padding before animation timer. Different from the padding location cinematX uses
fern wrote: Is there a way to bypass the NPC's speedX limit? I'm trying to make enemies hit bounce back. SpeedY works as intended but changing it's speedX simply reverses the NPC's direction as it continues to walk at the same speed.
Unfortunately most NPCs that walk around overwrite any x speed you give them before they do their physics every tick. You might have to store a temporary knockback speed on them with pnpc and adjust their position by that amount every tick, but then you get into stuff like block collisions.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Jan 15, 2019 12:45 pm

Quantumenace wrote:
Sun Jan 13, 2019 12:37 pm
Yes, but offset 0xE6 isn't used by vanilla SMBX and is not one of these references by default. Line 11 of pnpc:

Code: Select all

local ID_FIELD = 0xE6 -- (Presumably) padding before animation timer. Different from the padding location cinematX uses
Ah sorry I misread your post. The wiki is full of inaccurate and outdated information, we're hoping to change that over time.

Westretroman
Eerie
Eerie
Posts: 704
Joined: Tue Mar 29, 2016 6:50 pm

Re: Need help with lua? - LunaLua General Help

Postby Westretroman » Sat Jan 19, 2019 11:02 am

I have a question, whenever I use OnKeyboardPress, and press a key, every other key on the keyboard activates the event rather than the one I set it to.

Example: OnKeyboardPress(VK_10)
Any one know a fix for this?

The Dwarven Digger
Lakitu
Lakitu
Posts: 484
Joined: Sun Oct 30, 2016 11:17 am
Pronouns: they/them

Re: Need help with lua? - LunaLua General Help

Postby The Dwarven Digger » Sat Jan 19, 2019 11:09 am

function OnKeyboardPress(key)
if key == VK_10 then
-- Do stuff here
end
end

You can replace VK_10 with whatever key code you want. If you need to check multiple keys, add more if statements in the same function. Hope this helps.
I wish I could indent but code tags are broken

Westretroman
Eerie
Eerie
Posts: 704
Joined: Tue Mar 29, 2016 6:50 pm

Re: Need help with lua? - LunaLua General Help

Postby Westretroman » Sat Jan 19, 2019 11:40 am

The Dwarven Digger wrote:
Sat Jan 19, 2019 11:09 am
function OnKeyboardPress(key)
if key == VK_10 then
-- Do stuff here
end
end

You can replace VK_10 with whatever key code you want. If you need to check multiple keys, add more if statements in the same function. Hope this helps.
I wish I could indent but code tags are broken
Thank you!

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9707
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat Jan 19, 2019 1:06 pm

When using onKeyboardPress keep in mind that you don't know the control config of the people you're designing for. For all you know they could use that button for "jump". Or they could be using a controller and need to lean over to the keyboard to hit your button. Tricky stuff.

Westretroman
Eerie
Eerie
Posts: 704
Joined: Tue Mar 29, 2016 6:50 pm

Re: Need help with lua? - LunaLua General Help

Postby Westretroman » Mon Jan 21, 2019 12:21 am

Enjl wrote:
Sat Jan 19, 2019 1:06 pm
When using onKeyboardPress keep in mind that you don't know the control config of the people you're designing for. For all you know they could use that button for "jump". Or they could be using a controller and need to lean over to the keyboard to hit your button. Tricky stuff.
I'll keep that in mind, thanks!

LGLMAKING
Ripper II
Ripper II
Posts: 341
Joined: Mon Jun 18, 2018 7:28 am
Flair: H E X
Pronouns: ask for pronouns

Re: Need help with lua? - LunaLua General Help

Postby LGLMAKING » Wed Jan 23, 2019 12:35 pm

I would like to ask a trivial question. Can you program with mouse movement and selection in game?

PixelPest
Raccoon Mario
Raccoon Mario
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Wed Jan 23, 2019 12:45 pm

LGLMAKING wrote:
Wed Jan 23, 2019 12:35 pm
I would like to ask a trivial question. Can you program with mouse movement and selection in game?
Yes. There's a library called click.lua (you can find it on the PGE wiki and possibly here) that helps manage it

LGLMAKING
Ripper II
Ripper II
Posts: 341
Joined: Mon Jun 18, 2018 7:28 am
Flair: H E X
Pronouns: ask for pronouns

Re: Need help with lua? - LunaLua General Help

Postby LGLMAKING » Thu Jan 24, 2019 1:22 am

PixelPest wrote:
Wed Jan 23, 2019 12:45 pm
LGLMAKING wrote:
Wed Jan 23, 2019 12:35 pm
I would like to ask a trivial question. Can you program with mouse movement and selection in game?
Yes. There's a library called click.lua (you can find it on the PGE wiki and possibly here) that helps manage it
Thanks for the information!

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

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Thu Jan 24, 2019 5:26 pm

I've been trying to get textblox to work for better text boxes and behavior. I didn't like some sounds so I tried editing them in this manner.
Image
However the text bleeds into the borders like so when I do this.
Image
Is there a setting I'm missing (or shouldn't be there) or is there a different way of going about this? I wanted to have it where all textbox's in all levels did this so it's in a lunaworld.lua file.
I've never done textblox before so apologies for the noobness.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Thu Jan 24, 2019 5:33 pm

I'd be wary of textblox. It does have the issue that it may just straight up crash the game. It's also fairly bloated and awkward. Fortunately, there's a cleaner replacement in Beta 4. I'm not sure how to fix the issue you're seeing there, though.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9707
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Jan 25, 2019 1:13 am

The crash hoeloe mentions only happens if textblox replaces default message boxes. If you don't do that but instead just handle the message boxes yourself, you're safe.
In any case, try setting marginX and marginY https://wohlsoft.ru/pgewiki/Textblox.lua

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Fri Jan 25, 2019 10:16 am

Enjl wrote:
Fri Jan 25, 2019 1:13 am
The crash hoeloe mentions only happens if textblox replaces default message boxes. If you don't do that but instead just handle the message boxes yourself, you're safe.
That's not actually true I believe. I believe it comes from the parser step that deals with text wrapping, which can get stuck in a very long, if not infinite, loop. It's not "replacing default message boxes" that's the issue, it's "working with text wrapping".

The Dwarven Digger
Lakitu
Lakitu
Posts: 484
Joined: Sun Oct 30, 2016 11:17 am
Pronouns: they/them

Re: Need help with lua? - LunaLua General Help

Postby The Dwarven Digger » Fri Jan 25, 2019 1:08 pm

I've tried textblox in a project and I can't get the wrapping to function. Changing autosizeRatio seems to do something, but appears to work slightly differently for different fonts. Also, the PGE Wiki documentation is wrong in that marginX and marginY should actually be xMargin and yMargin instead. I can paste the code I'm trying to use here if you want.
Spoiler: show
dispBlock = textblox.Block(400, 540, text,{
pauseGame = true,
--boxType = textblox.BOXTYPE_WORDBUBBLE,
font = textblox.defaultSpritefont[3][2],
borderTable = {
thick = 16,
ulImg = cornerImg,
uImg = tEdge,
urImg = cornerImg,
rImg = rEdge,
drImg = cornerImg,
dImg = bEdge,
dlImg = cornerImg,
lImg = lEdge
},
width = 600,
height = 100,
autosizeRatio = (600)/(100),
speed = textSpeed,
boxColor = 0xFFFFFFFF,
boxTex = fillImg,
bind = textblox.BIND_SCREEN,
boxAnchorX = textblox.HALIGN_MID,
boxAnchorY = textblox.VALIGN_TOP,
xMargin = 4,
yMargin = 12,
inputClose = true,
autoTime = true,
midMarkDelay = delay,
endMarkDelay = delay*2,
finishDelay = delay*2
})
(Also how did Daring Tombstone get code to work? Is it a screenshot?)

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9707
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Jan 25, 2019 4:37 pm

Hoeloe wrote:
Fri Jan 25, 2019 10:16 am
Enjl wrote:
Fri Jan 25, 2019 1:13 am
The crash hoeloe mentions only happens if textblox replaces default message boxes. If you don't do that but instead just handle the message boxes yourself, you're safe.
That's not actually true I believe. I believe it comes from the parser step that deals with text wrapping, which can get stuck in a very long, if not infinite, loop. It's not "replacing default message boxes" that's the issue, it's "working with text wrapping".
I would be more open to believing your hypothesis if I had ever found myself in a situation within the past 2 years of using textblox where this bug happened... My setup is simply calling "everyMessage:resetText(newMessage)" after some filtering shenanigans in onMessageBox that cancel the original event and remove a substring of the message.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Fri Jan 25, 2019 5:16 pm

I determined that to be the likely cause after extensive debugging before textplus was really considered. There is a possibility the cause is elsewhere, as I don't remember the specifics, but I do remember doing a lot of debugging and discovering that it seemed to come from wrapping. Not to mention there are specific examples I can give of textblox causing that same issue without using its built in message box replacement, since A2XT2 has always used its own system.

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

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Fri Jan 25, 2019 5:45 pm

The marginx and marginy was my problem. It is caused by misinformation and is actually supposed to be xMargin and yMargin. The words no longer bleed into the borders now. I will be wary when using textblox. Are the crashes just random or are they consistent?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari