Page 74 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jan 12, 2019 6:23 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 13, 2019 4:32 am
by fern
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Jan 13, 2019 12:37 pm
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jan 15, 2019 12:45 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jan 19, 2019 11:02 am
by Westretroman
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jan 19, 2019 11:09 am
by The Dwarven Digger
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

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jan 19, 2019 11:40 am
by Westretroman
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!

Re: Need help with lua? - LunaLua General Help

Posted: Sat Jan 19, 2019 1:06 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jan 21, 2019 12:21 am
by Westretroman
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!

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jan 23, 2019 12:35 pm
by LGLMAKING
I would like to ask a trivial question. Can you program with mouse movement and selection in game?

Re: Need help with lua? - LunaLua General Help

Posted: Wed Jan 23, 2019 12:45 pm
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Thu Jan 24, 2019 1:22 am
by LGLMAKING
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!

Re: Need help with lua? - LunaLua General Help

Posted: Thu Jan 24, 2019 5:26 pm
by Daring Tombstone
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Jan 24, 2019 5:33 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 25, 2019 1:13 am
by Emral
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

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 25, 2019 10:16 am
by Hoeloe
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".

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 25, 2019 1:08 pm
by The Dwarven Digger
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?)

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 25, 2019 4:37 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 25, 2019 5:16 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Jan 25, 2019 5:45 pm
by Daring Tombstone
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?