smw centralmario fan games galaxyirc.cat.bio

firefox related css updates (bbcode/shoutbox) - ctrl-f5 if they're still jacked up for you

Lua help thread

If you lost something come look for it here
User avatar
7NameSam
hey
Posts: 207
Joined: 2 years ago
Pronouns: he/him/his

Re: Lua help thread

Postby 7NameSam » 1 year ago

so, I wanna make a level with a potentially awful gimmick
7NameSam wrote:I want to make it so you can't move if you are standing on the ground, How do I do that?
Image

User avatar
Rednaxela
Maker of Shenanigans
Posts: 654
Joined: 3 years ago

Re: Lua help thread

Postby Rednaxela » 1 year ago

7NameSam wrote:so, I wanna make a level with a potentially awful gimmick
7NameSam wrote:I want to make it so you can't move if you are standing on the ground, How do I do that?
So you mean something like

Code: Select all

function onLoop()
	-- If on the ground (0x146), or sloped ground (0x48)...
	if (player:mem(0x146, FIELD_WORD) ~= 0) or (player:mem(0x48, FIELD_WORD) ~= 0) then
		-- Disable horizontal and ducking (0x04)
		player:mem(0x04, FIELD_WORD, -1)
	end
end
?
Currently LPing: Ys Origin

User avatar
7NameSam
hey
Posts: 207
Joined: 2 years ago
Pronouns: he/him/his

Re: Lua help thread

Postby 7NameSam » 1 year ago

Rednaxela wrote:
7NameSam wrote:so, I wanna make a level with a potentially awful gimmick
7NameSam wrote:I want to make it so you can't move if you are standing on the ground, How do I do that?
So you mean something like

Code: Select all

function onLoop()
	-- If on the ground (0x146), or sloped ground (0x48)...
	if (player:mem(0x146, FIELD_WORD) ~= 0) or (player:mem(0x48, FIELD_WORD) ~= 0) then
		-- Disable horizontal and ducking (0x04)
		player:mem(0x04, FIELD_WORD, -1)
	end
end
?
yea, but I want the player to still slide around and stuff
This code makes it feel like the ground is covered in glue
Image

User avatar
Rednaxela
Maker of Shenanigans
Posts: 654
Joined: 3 years ago

Re: Lua help thread

Postby Rednaxela » 1 year ago

7NameSam wrote:yea, but I want the player to still slide around and stuff
This code makes it feel like the ground is covered in glue
Try this one out then:

Code: Select all

-- Run during onInputUpdate, not onLoop
function onInputUpdate()
	-- If on the ground, or a slope...
	if (player:mem(0x146, FIELD_WORD) ~= 0) or (player:mem(0x48, FIELD_WORD) ~= 0) then
		-- Disable left/right controls
		player:mem(0xF6, FIELD_WORD, 0)
		player:mem(0xF8, FIELD_WORD, 0)
	end
end
Note, this only works with LunaLUA versions >= 0.7, as that's what added onInputUpdate
Currently LPing: Ys Origin

User avatar
7NameSam
hey
Posts: 207
Joined: 2 years ago
Pronouns: he/him/his

Re: Lua help thread

Postby 7NameSam » 1 year ago

Rednaxela wrote:
7NameSam wrote:yea, but I want the player to still slide around and stuff
This code makes it feel like the ground is covered in glue
Try this one out then:

Code: Select all

-- Run during onInputUpdate, not onLoop
function onInputUpdate()
	-- If on the ground, or a slope...
	if (player:mem(0x146, FIELD_WORD) ~= 0) or (player:mem(0x48, FIELD_WORD) ~= 0) then
		-- Disable left/right controls
		player:mem(0xF6, FIELD_WORD, 0)
		player:mem(0xF8, FIELD_WORD, 0)
	end
end
Note, this only works with LunaLUA versions >= 0.7, as that's what added onInputUpdate
Yes, works like a charm. Thank you!
Image

Zyglrox Odyssey
Posts: 511
Joined: 4 years ago
Contact:

Re: Lua help thread

Postby Zyglrox Odyssey » 1 year ago

I don't suppose anybody's found the flag or whatever for sonicstooslow? I recall there being a thing somewhere to detect if a cheat's been input but I don't believe I've heard anything of toggling sonicstooslow specifically with lua.
ImageImage
ImageImage
ImageImage
ImageImage

User avatar
Rednaxela
Maker of Shenanigans
Posts: 654
Joined: 3 years ago

Re: Lua help thread

Postby Rednaxela » 1 year ago

Zyglrox Odyssey wrote:I don't suppose anybody's found the flag or whatever for sonicstooslow? I recall there being a thing somewhere to detect if a cheat's been input but I don't believe I've heard anything of toggling sonicstooslow specifically with lua.

Code: Select all

mem(0x00B2C8AE, FIELD_WORD, 0) -- Disable

mem(0x00B2C8AE, FIELD_WORD, -1) -- Enable
(After figuring this out, I found that a couple others had reported this specific one before. Not sure if all the mapping of all toggle-based cheat codes to memory addresses is known... and if it is it's certainly not compiled in one place... maybe I should make a proper complete list of those, heh)
Currently LPing: Ys Origin

Zyglrox Odyssey
Posts: 511
Joined: 4 years ago
Contact:

Re: Lua help thread

Postby Zyglrox Odyssey » 1 year ago

Rednaxela wrote:

Code: Select all

mem(0x00B2C8AE, FIELD_WORD, 0) -- Disable

mem(0x00B2C8AE, FIELD_WORD, -1) -- Enable
(After figuring this out, I found that a couple others had reported this specific one before. Not sure if all the mapping of all toggle-based cheat codes to memory addresses is known... and if it is it's certainly not compiled in one place... maybe I should make a proper complete list of those, heh)
Ohh yes, that does indeed do the thing, thanks. And I don't know offhand what other cheats would even be all that useful to toggle via lunalua but a list would probably still be super neat.
ImageImage
ImageImage
ImageImage
ImageImage

User avatar
KayhemMaus
I keep breaking my face on SMBX
Posts: 273
Joined: 4 years ago
First name: KM
Pronouns: they/them/their
Location: England

Re: Lua help thread

Postby KayhemMaus » 1 year ago

Ok, so I'm struggling with something as a first time LUA user. This function:

Code: Select all

function onLoadSection2(int playerIndex)
	Text.showMessageBox(Test)
end
gives me an error which says:

lvlname\lunadll.lua:1: ')' expected near playerIndex

which I don't understand since it's in there. o.o What on earth am I doing wrong?
HUZZAH! ( VVV Hey, click this if you have an interest in SMBX projects!)
Image

User avatar
Hoeloe
One of them Lua people
Posts: 806
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 1 year ago

KayhemMaus wrote:Ok, so I'm struggling with something as a first time LUA user. This function:

Code: Select all

function onLoadSection2(int playerIndex)
	Text.showMessageBox(Test)
end
gives me an error which says:

lvlname\lunadll.lua:1: ')' expected near playerIndex

which I don't understand since it's in there. o.o What on earth am I doing wrong?
What you're doing wrong is treating Lua like Java (or any number of other languages). Lua isn't a typed language, and "int" isn't a keyword in the Lua lexicon. Remove your type declaration from the function definition.
Image
Image
Image
Image

User avatar
KayhemMaus
I keep breaking my face on SMBX
Posts: 273
Joined: 4 years ago
First name: KM
Pronouns: they/them/their
Location: England

Re: Lua help thread

Postby KayhemMaus » 1 year ago

Hoeloe wrote:
KayhemMaus wrote:Ok, so I'm struggling with something as a first time LUA user. This function:

Code: Select all

function onLoadSection2(int playerIndex)
	Text.showMessageBox(Test)
end
gives me an error which says:

lvlname\lunadll.lua:1: ')' expected near playerIndex

which I don't understand since it's in there. o.o What on earth am I doing wrong?
What you're doing wrong is treating Lua like Java (or any number of other languages). Lua isn't a typed language, and "int" isn't a keyword in the Lua lexicon. Remove your type declaration from the function definition.
... that was in the tutorial I was reading D: So I should keep that in mind then. Now the function itself isn't working but at least I got rid of the error, time for me to investigate/poke around further. Thanks though~
HUZZAH! ( VVV Hey, click this if you have an interest in SMBX projects!)
Image

User avatar
Hoeloe
One of them Lua people
Posts: 806
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 1 year ago

KayhemMaus wrote:... that was in the tutorial I was reading D: So I should keep that in mind then. Now the function itself isn't working but at least I got rid of the error, time for me to investigate/poke around further. Thanks though~
It was likely included to let you know that the value of playerIndex will be an integer, but Lua doesn't like you to declare types, so just put the variable names in future.

Also, strings should be inside "". When you say:

Code: Select all

Text.showMessageBox(Test)
You're asking it to try displaying the value of a variable called "Test", which doesn't exist, so it doesn't work.

If you change that to this, however:

Code: Select all

Text.showMessageBox("Test")
It will display the string "Text".
Image
Image
Image
Image

User avatar
Reecer7
Crack is fun and nice and a good time!
Posts: 151
Joined: 1 year ago
Pronouns: he/him/his

Re: Lua help thread

Postby Reecer7 » 1 year ago

Okay, I'm sure there's some really easy function to do this, but I'm having a lot of trouble figuring out how to have something trigger when you talk to something and a message box appears. Here's what my code basically looks like now, excising some unimportant things nested further in.

Code: Select all

function onEvent(eventNamo)
    for k,v in pairs(findnpcs(110,-1)) do
        if (eventName == v.talkEventName) then
            v:kill();
        end
    end
end
It should just, for every event, see if that event is actually the same event that happens when you talk to a specific dude, and then run the code, but he's definitely not being killed, so something's not right. What's the problem here?
call me reecer6, not reecer7, please! gotta maintain that same internet brand.
I do a lot more things at my tumblr here than I do here! So, check it out, if you think I'm cool!

Zyglrox Odyssey
Posts: 511
Joined: 4 years ago
Contact:

Re: Lua help thread

Postby Zyglrox Odyssey » 1 year ago

Reecer7 wrote:Okay, I'm sure there's some really easy function to do this, but I'm having a lot of trouble figuring out how to have something trigger when you talk to something and a message box appears. Here's what my code basically looks like now, excising some unimportant things nested further in.

Code: Select all

function onEvent(eventNamo)
    for k,v in pairs(findnpcs(110,-1)) do
        if (eventName == v.talkEventName) then
            v:kill();
        end
    end
end
It should just, for every event, see if that event is actually the same event that happens when you talk to a specific dude, and then run the code, but he's definitely not being killed, so something's not right. What's the problem here?
You put "eventNamo" in the function define up at the top, for one thing. Beyond that I'm not sure if -1 works for the section for findnpcs, generally player.section is used.
ImageImage
ImageImage
ImageImage
ImageImage

User avatar
Reecer7
Crack is fun and nice and a good time!
Posts: 151
Joined: 1 year ago
Pronouns: he/him/his

Re: Lua help thread

Postby Reecer7 » 1 year ago

...Whoops. That's a pretty embarrassing error. Is it less embarassing to say that Namo wasn't a typo?

The lua tutorial and the findnpcs() definition both explicitly say to use -1 when one of the qualifications don't matter, so I'd hope that's correct, but regardless of what I put there, it still doesn't seem to be working.

(The file is definitely in the right place, though, so that's not another mistake I made.)
call me reecer6, not reecer7, please! gotta maintain that same internet brand.
I do a lot more things at my tumblr here than I do here! So, check it out, if you think I'm cool!

S1eth
Posts: 285
Joined: 2 years ago

Re: Lua help thread

Postby S1eth » 1 year ago

This "talkEventName" doesn't appear to be an event that is caught by onEvent.

"function onEvent(eventName) eventCounter = eventCounter + 1; end" does nothing if you simply talk to an NPC.

But I guess you could select the NPC, and set a "Talk" Event for it, e.g. "Speech001". And then check in onEvent for an event named "Speech001".
Image

User avatar
Reecer7
Crack is fun and nice and a good time!
Posts: 151
Joined: 1 year ago
Pronouns: he/him/his

Re: Lua help thread

Postby Reecer7 » 1 year ago

You can actually set events for something under its properties other than Level - Start, P-switch - Start, and P-switch - End? If I knew how to do that, I might not've need any help at all (Although actually I'd probably just assume it was meant to name a function you wanted to run). I can't find any way to do that in the pge editor.
call me reecer6, not reecer7, please! gotta maintain that same internet brand.
I do a lot more things at my tumblr here than I do here! So, check it out, if you think I'm cool!

S1eth
Posts: 285
Joined: 2 years ago

Re: Lua help thread

Postby S1eth » 1 year ago

CTRL+E or View --> Events

Click the [ + ] and add a new event, give it a name. Set the "Talk" from "None" to the newly created event.
Image

User avatar
Reecer7
Crack is fun and nice and a good time!
Posts: 151
Joined: 1 year ago
Pronouns: he/him/his

Re: Lua help thread

Postby Reecer7 » 1 year ago

Okay, great, that worked. I really don't know how I managed to overlook that one single button on the UI since I went through every nook and cranny of every other one, but thanks.
call me reecer6, not reecer7, please! gotta maintain that same internet brand.
I do a lot more things at my tumblr here than I do here! So, check it out, if you think I'm cool!

User avatar
7NameSam
hey
Posts: 207
Joined: 2 years ago
Pronouns: he/him/his

Re: Lua help thread

Postby 7NameSam » 1 year ago

I want a NPC to turn into a different NPC when an event is activated, How do I do that?
*EDIT* Also, blocks. Can I turn a block into a different block using an event?
Image

User avatar
Hoeloe
One of them Lua people
Posts: 806
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 1 year ago

7NameSam wrote:I want a NPC to turn into a different NPC when an event is activated, How do I do that?
*EDIT* Also, blocks. Can I turn a block into a different block using an event?
You can set the ID of the NPC to something else, which should change it to a different NPC.

Getting hold of a specific NPC is more difficult. If you know something unique about it, like its position, you can find it by searching all the NPCs in the level and wrapping it with pnpc.

Blocks should be possible to do the same with, more or less, though in that case it may be easier to just use events to show and hide layers.
Image
Image
Image
Image

User avatar
Nimono
Posts: 272
Joined: 3 years ago

Re: Lua help thread

Postby Nimono » 1 year ago

I've never used Lua (or LunaLua, for that matter) before, and I'd like to give it a try and maybe make a level for this, so I have a quick question: what function would I use to activate one of the cheat codes? It's kinda vital to an idea I have...

User avatar
acrowdofpeople
Posts: 47
Joined: 1 year ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

I'm having some problems toggling a variable. It seems that no matter what I do, it changes once and then refuses to be changed back...
Here's what I have right now:

Code: Select all

local smithythwomp=0
function onLoadSection2()
if (smithythwomp==1) then
triggerEvent("finalbosswarp")
triggerEvent("hidestuff")
end
end
function onLoadSection5()
if (smithythwomp==0) then
smithythwomp=1
end
end
function onLoadSection4()
if (smithythwomp==1) then
smithythwomp=0
end
end
Basically, I want the player to be able to warp straight from the midpoint to the boss at the end of the level once they've reached the boss once, but then I want the variable to reset to zero once the level is cleared. But I can't seem to enable it to switch - I can set it up so that the flag gets set, but then I can't turn it off it, or I can turn the flag off, but then I can never turn it back on.

User avatar
Hoeloe
One of them Lua people
Posts: 806
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 1 year ago

acrowdofpeople wrote:I can set it up so that the flag gets set, but then I can't turn it off it, or I can turn the flag off, but then I can never turn it back on.
So one of two things is happening here.

It looks like either a) you're not taking into account that sections are 0-indexed (so onLoadSection0 will run when you load section 1, onLoadSection1 will run when you load section 2, etc.) or b) you're expecting resetting the variable to undo the changes made by the events that you trigger, which won't happen without another event to revert the changes.

The code looks fundamentally fine otherwise, as far as I can see.
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 1 year ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

I've got it indexed properly. I just can't get the flag to change the way I want it to.

I'll go in, hit the midpoint, and if I die, everything's good. The code, as written, doesn't trigger when I enter room 5 (according to the code) or 6 (according to the level editor), the flag isn't changed to a 1, so when I die and restart at the midpoint, the warp to the boss doesn't trigger.

If I change the code up so that the switch is triggered by a specific event (the boss appearing), then the flag will successfully change to a 1, so if I die fighting the boss and start again, a warp to the boss appears near the midpoint, and all is good.

But once I clear the level by going back to room 4 (5 in the editor), if I hit the midpoint and die, then the warp to the boss appears, meaning that the variable wasn't changed back to a 0.

So I can make the flag change to a zero or a one successfully, but I can't seem to get the code to do both.


Return to “Magl X : the Lost Levels”

Who is online

Users browsing this forum: No registered users and 1 guest

cron