Yes, works like a charm. Thank you!Rednaxela wrote:Try this one out then: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 glueNote, this only works with LunaLUA versions >= 0.7, as that's what added onInputUpdateCode: 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
Lua help thread
Re: Lua help thread
Re: Lua help thread
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.
- Rednaxela
- Maker of Shenanigans
- Posts: 897
- Joined: 10 years ago
- Pronouns: they/them
- https://rednaxela.talkhaus.com
Re: Lua help thread
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
Re: Lua help thread
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.Rednaxela wrote:(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)Code: Select all
mem(0x00B2C8AE, FIELD_WORD, 0) -- Disable mem(0x00B2C8AE, FIELD_WORD, -1) -- Enable
- KayhemMaus
- I keep breaking my face on SMBX
- Posts: 325
- Joined: 11 years ago
- First name: KM
- Pronouns: they/them/their
- Location: England
Re: Lua help thread
Ok, so I'm struggling with something as a first time LUA user. This function:
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?
Code: Select all
function onLoadSection2(int playerIndex)
Text.showMessageBox(Test)
end
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?
I love it
Re: Lua help thread
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.KayhemMaus wrote:Ok, so I'm struggling with something as a first time LUA user. This function:
gives me an error which says:Code: Select all
function onLoadSection2(int playerIndex) Text.showMessageBox(Test) end
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?
- KayhemMaus
- I keep breaking my face on SMBX
- Posts: 325
- Joined: 11 years ago
- First name: KM
- Pronouns: they/them/their
- Location: England
Re: Lua help thread
... 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~Hoeloe wrote: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.KayhemMaus wrote:Ok, so I'm struggling with something as a first time LUA user. This function:
gives me an error which says:Code: Select all
function onLoadSection2(int playerIndex) Text.showMessageBox(Test) end
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?
I love it
Re: Lua help thread
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.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~
Also, strings should be inside "". When you say:
Code: Select all
Text.showMessageBox(Test)
If you change that to this, however:
Code: Select all
Text.showMessageBox("Test")
- Reecer7
- Crack is fun and nice and a good time!
- Posts: 449
- Joined: 8 years ago
- Pronouns: he/him/his
- https://cro-iba.talkhaus.com/
Re: Lua help thread
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.
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?
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
call me reecer6, not reecer7, please! gotta maintain that same internet brand. actually i'm cro-iba now, it's cooler
strange bluebird website (check it out for my art!)
strange bluebird website (check it out for my art!)
Re: Lua help thread
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.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.
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?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
- Reecer7
- Crack is fun and nice and a good time!
- Posts: 449
- Joined: 8 years ago
- Pronouns: he/him/his
- https://cro-iba.talkhaus.com/
Re: Lua help thread
...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.)
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. actually i'm cro-iba now, it's cooler
strange bluebird website (check it out for my art!)
strange bluebird website (check it out for my art!)
Re: Lua help thread
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".
"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".
- Reecer7
- Crack is fun and nice and a good time!
- Posts: 449
- Joined: 8 years ago
- Pronouns: he/him/his
- https://cro-iba.talkhaus.com/
Re: Lua help thread
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. actually i'm cro-iba now, it's cooler
strange bluebird website (check it out for my art!)
strange bluebird website (check it out for my art!)
Re: Lua help thread
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.
Click the [ + ] and add a new event, give it a name. Set the "Talk" from "None" to the newly created event.
- Reecer7
- Crack is fun and nice and a good time!
- Posts: 449
- Joined: 8 years ago
- Pronouns: he/him/his
- https://cro-iba.talkhaus.com/
Re: Lua help thread
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. actually i'm cro-iba now, it's cooler
strange bluebird website (check it out for my art!)
strange bluebird website (check it out for my art!)
Re: Lua help thread
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?
*EDIT* Also, blocks. Can I turn a block into a different block using an event?
Re: Lua help thread
You can set the ID of the NPC to something else, which should change it to a different NPC.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?
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.
Re: Lua help thread
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...
-
- Posts: 54
- Joined: 9 years ago
Re: Lua help thread
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:
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.
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
Re: Lua help thread
So one of two things is happening here.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.
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.
-
- Posts: 54
- Joined: 9 years ago
Re: Lua help thread
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.
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.
Re: Lua help thread
Ah. This is possibly because you're trying to do things across different plays. Once you exit the level, either by dying or finishing it, the Lua environment is reset. Every time you spawn, whether on the midpoint or not, you need to consider your code as executing for the first time. Data isn't retained between plays.acrowdofpeople wrote: 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.
I suggest, if what you're looking to do is essentially create a second checkpoint type thing, you look into the multipoints library, which is designed to manage this kind of eventuality. The default system just creates a checkpoint exactly like a SMBX midpoint, but it does allow further customisation if you have a look at the documentation on the wiki.
-
- Posts: 54
- Joined: 9 years ago
Re: Lua help thread
Is that so? That doesn't match up to my experience, but I'll take your word for it.
So I just use the multipoints library to straight up make a new midpoint?
EDIT: So I put a midpoint in section 6 using the code:
This spawns me in the area I want to be spawned in, but then I die instantly. How do I find (x,y) coordinates?[/s] Found it.
So I just use the multipoints library to straight up make a new midpoint?
EDIT: So I put a midpoint in section 6 using the code:
Code: Select all
multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(0, 0, 5);
Re: Lua help thread
Is it possible that by appearing on the midpoint you were instantly setting the variable to 1? That would explain why you were unable to reset it.acrowdofpeople wrote:Is that so? That doesn't match up to my experience, but I'll take your word for it.
It's hard to find exactly why the variable wouldn't change after you'd hit the midpoint without looking at the level file directly, but regardless, it is definitely the case that the Lua environment is reset. No variables are stored between plays of the level unless you use the Data class (or encrypt.dll). If you think about it, it doesn't make sense for the data to be carried across plays because that would cause all sorts of problems, and make it much less predictable. And also cause a lot of memory leaks as it tries to keep hold of data you're no longer using (for example, on the world map).
-
- Posts: 54
- Joined: 9 years ago
Re: Lua help thread
No, because the midpoint didn't do anything to set the variable - the variable being set to 1 was triggered (or not, depending on how I had it coded) by entering a very different room from the midpoint.
Regardless, thanks to the multipoints function, it's working exactly the way I want it to. Thank you.
If you're curious to see it directly in action, I can set it back up and send you the level file.
EDIT: I broke multipoints somehow. When I use it to provide a second midpoint, the SMBX-provided one breaks, so I removed the first one and tried to use multipoints to add the first one back - only to break the midpoint I had added originally.
The last line was the one that originally worked, so I tried using the second line to replace the SMBX midpoint... which caused the third line to break somehow and now there are no midpoints. I'll just provide a shortcut through the midpoint room to the boss...
Regardless, thanks to the multipoints function, it's working exactly the way I want it to. Thank you.
If you're curious to see it directly in action, I can set it back up and send you the level file.
EDIT: I broke multipoints somehow. When I use it to provide a second midpoint, the SMBX-provided one breaks, so I removed the first one and tried to use multipoints to add the first one back - only to break the midpoint I had added originally.
Code: Select all
multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 3);
multipoints.addLuaCheckpoint(-99942, -100070, 5);