smbx communitypge projectirc.cat.bio

happy birthday talkhaus!!!

Lua help thread

If you lost something come look for it here
User avatar
Hoeloe
One of them Lua people
Posts: 824
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 1 year ago

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.
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.

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.
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

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:

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(0, 0, 5);
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.

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

acrowdofpeople wrote:Is that so? That doesn't match up to my experience, but I'll take your word for it.
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.

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).
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

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.

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 3);
multipoints.addLuaCheckpoint(-99942, -100070, 5);
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...

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

acrowdofpeople wrote: 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);
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...
Using regular SMBX midpoints with multipoints isn't advised, but two multipoints checkpoints shouldn't break anything. Make sure you reset the level before testing again, otherwise things will get confused.

If it still doesn't work, then I could take a look at the level and see if I can work it out. You do want to make sure you have the most recent version of multipoints, though, because I think the one included in LunaLua is out of date.
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

Here's a test version of the level with the two midpoints from multipoints.

By "reset the level," you mean close out after removing the smbx midpoint and load it up again, right?

S1eth
Posts: 285
Joined: 2 years ago

Re: Lua help thread

Postby S1eth » 1 year ago

acrowdofpeople wrote:Here's a test version of the level with the two midpoints from multipoints.

By "reset the level," you mean close out after removing the smbx midpoint and load it up again, right?
In the SMBX editor: Test Level --> Reset Level (F8)
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

Okay, tried it... midpoints still aren't working.

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

Yeah. It works fine for me. Make sure you have the latest version of LunaLua and multipoints.
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

I thought I did. I downloaded the most recent version of multipoints from the multipoints page and installed it after downloading the most recent version of Lua from the Lua page and installing that over the one in the devkit...

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

acrowdofpeople wrote:I thought I did. I downloaded the most recent version of multipoints from the multipoints page and installed it after downloading the most recent version of Lua from the Lua page and installing that over the one in the devkit...
If you open your multipoints.lua file, what's the version number at the top of the file?
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

2.2.2
Edit: I somehow missed the actual lib file, which was just floating around... now it's 3.0. I'll retest.
Last edited by acrowdofpeople on 25 Jul 2015, 01:14, edited 1 time in total.

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

acrowdofpeople wrote:2.2.2
The current most recent version should be 3.0.0. Let me check the download.

EDIT: Looks like you've downloaded the version for LunaLua v0.6 and lower. Try the other one.
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

Looks like it's working, I just need to fine-tune the coordinates now. Thanks!

User avatar
Dog In Da Grass
Perro de los Muertos
Posts: 434
Joined: 4 years ago
First name: Dog
Pronouns: that dog
Location: somewhere between the sacred silence and sleep

Re: Lua help thread

Postby Dog In Da Grass » 1 year ago

Is there any witchcraft or science I can do to make the hud disappear?
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

So I'm trying to have lua trigger a SMBX event for me.

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 2, -159696, -160241);
multipoints.addLuaCheckpoint(-99942, -100070, 2, -159696, -160241, "endboss");
function endboss
triggerEvent("finalbosswarp")
end
With this code, when I load up the level, I get an error: '(' expected near 'triggerEvent'
What did I break this time?

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

acrowdofpeople wrote:So I'm trying to have lua trigger a SMBX event for me.

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 2, -159696, -160241);
multipoints.addLuaCheckpoint(-99942, -100070, 2, -159696, -160241, "endboss");
function endboss
triggerEvent("finalbosswarp")
end
With this code, when I load up the level, I get an error: '(' expected near 'triggerEvent'
What did I break this time?
Functions can't just have names, they need a list of arguments when you define it. A list of arguments is denoted by a pair of brackets, with each argument inside separated by commas. For example, a function with two arguments might be defined:

Code: Select all

function myFunc(arg1, arg2)
Which reflects the way you would call the function:

Code: Select all

myFunc(a,b)
For a function with no arguments, just leave the argument list empty:

Code: Select all

function myFunc()
Which again reflects how you call it:

Code: Select all

myFunc()
I suggest reading the tutorials on the LunaLua wiki. They cover things like this.
Image
Image
Image
Image

User avatar
acrowdofpeople
Posts: 47
Joined: 2 years ago

Re: Lua help thread

Postby acrowdofpeople » 1 year ago

The tutorial was where I got the idea to trigger an event off of this.
EDIT: I'm apparently having a basic conceptual misunderstanding of what I'm trying to do here. I'll try this again once I've mastered the tutorial material. Thank you.

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 2 years ago

Re: Lua help thread

Postby Kevsoft » 1 year ago

Dog In Da Grass wrote:Is there any witchcraft or science I can do to make the hud disappear?

Code: Select all

hud(false)

User avatar
HatKid
Posts: 111
Joined: 2 years ago
Pronouns: she/her

Re: Lua help thread

Postby HatKid » 1 year ago

Is there any way I could make the background scroll really fast?
Thanks in advance.

User avatar
Ivy
Posts: 1961
Joined: 3 years ago
Contact:

Re: Lua help thread

Postby Ivy » 1 year ago

HatKid wrote:Is there any way I could make the background scroll really fast?
Thanks in advance.
That would be interesting; like that one level in SMW?
3DS FC: 2793-0650-7690 | Switch: SW-2766-9108-9399 | Steam: ivysaur1996 (that ivy guy)
Many thanks to GlitchedGhost and Rockythechao for the amazing paper Demo animation!

User avatar
HatKid
Posts: 111
Joined: 2 years ago
Pronouns: she/her

Re: Lua help thread

Postby HatKid » 1 year ago

Ivy wrote:
HatKid wrote:Is there any way I could make the background scroll really fast?
Thanks in advance.
That would be interesting; like that one level in SMW?
Yes, like that one level .

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

Re: Lua help thread

Postby 7NameSam » 1 year ago

How do I make a layer move back and forth using LUA?
Image

S1eth
Posts: 285
Joined: 2 years ago

Re: Lua help thread

Postby S1eth » 1 year ago

7NameSam wrote:How do I make a layer move back and forth using LUA?

Code: Select all

local myLayer = findlayer("TheNameYouGaveYourLayerInSMBX");

myLayer.speedX = someNumber; 
myLayer.speedY = someNumber;
You may want to put this into some if block, that uses an incremental counter for each frame, and reset it when the event happens (or use modulo).

Set to speed to e.g. +2 to make it move to the right, and another function to set the speed to -2 to make it move back.
For example, set it to move right at i==0, to move left at i==200, set i=0 at 400.
Image

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

Re: Lua help thread

Postby Hoeloe » 1 year ago

S1eth wrote:
7NameSam wrote:How do I make a layer move back and forth using LUA?

Code: Select all

local myLayer = findlayer("TheNameYouGaveYourLayerInSMBX");

myLayer.speedX = someNumber; 
myLayer.speedY = someNumber;
You may want to put this into some if block, that uses an incremental counter for each frame, and reset it when the event happens (or use modulo).

Set to speed to e.g. +2 to make it move to the right, and another function to set the speed to -2 to make it move back.
For example, set it to move right at i==0, to move left at i==200, set i=0 at 400.
Alternatively, you can use the eventu library to do most of the scheduling stuff for you.
Image
Image
Image
Image


Return to “Magl X : the Lost Levels”

Who is online

Users browsing this forum: No registered users and 1 guest

cron