Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Dog In Da Grass
Shy Guy
Shy Guy
Posts: 6
Joined: Fri Nov 27, 2015 9:37 pm

Re: Need help with lua? - LunaLua General Help

Postby Dog In Da Grass » Sun Apr 21, 2019 7:50 pm

Enjl wrote:
Sun Apr 21, 2019 7:46 pm
Dog In Da Grass wrote:
Sun Apr 21, 2019 7:03 pm
how do I switch to a custom character?
You can use the character constants: player:transform(CHARACTER_KLONOA)
not quite what I was asking

is it possible to make custom characters? and if I do how do I switch to using them?
unless something like CHARACTER_SONIC would work for a file named sonic

Added in 8 minutes 2 seconds:
It also seems to double everything klonoa does when I have klonoa's lua file in the characcter folder in my level folder, is there any way around this too? This is why I was wanting to make a custom character

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sun Apr 21, 2019 9:27 pm

I don't know if it's possible to create custom characters. I always make my custom characters over one of the main 5.
ImageImageImageImage
ImageImageImageImageImageImage

Dog In Da Grass
Shy Guy
Shy Guy
Posts: 6
Joined: Fri Nov 27, 2015 9:37 pm

Re: Need help with lua? - LunaLua General Help

Postby Dog In Da Grass » Sun Apr 21, 2019 9:31 pm

Okay, good to know, thanks!

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Apr 23, 2019 9:13 am

If you want an entirely custom character, you should make it over one of the base 5. Otherwise you're competing with a bunch of extra Lua and it's just making things hard for yourself. Klonoa, for example, is based on Toad.

BigFrog
Goomba
Goomba
Posts: 3
Joined: Wed Apr 03, 2019 7:11 pm
Flair: she/her
Chat Username: BigFrog

Re: Need help with lua? - LunaLua General Help

Postby BigFrog » Thu Apr 25, 2019 6:32 pm

another dumb question, i'm trying to make it so that collecting a red coin sets a certain value back to 1, but i'm having issues. here's my code

Code: Select all

allNPCs = findnpcs(103,player.section)	
for k,v in pairs (allNPCs) do
	if Counter == 0 and v:mem(0x44,FIELD_BOOL) == true then
		Counter = 1
	end
end
i think the mem thing is the issue but idk which offset to use and i'm brain farting

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Fri Apr 26, 2019 4:09 am

Where did you find that code? The findnpcs function hasn't been used for literally years. NPC.get is what's used these days. Also the PGE wiki has a list of the memory locations and what they do.

BigFrog
Goomba
Goomba
Posts: 3
Joined: Wed Apr 03, 2019 7:11 pm
Flair: she/her
Chat Username: BigFrog

Re: Need help with lua? - LunaLua General Help

Postby BigFrog » Fri Apr 26, 2019 11:56 pm

Hoeloe wrote:
Fri Apr 26, 2019 4:09 am
Where did you find that code? The findnpcs function hasn't been used for literally years. NPC.get is what's used these days. Also the PGE wiki has a list of the memory locations and what they do.
idk the lua file i made a couple years back used it so it could be the problem. this same code still uses onLoop instead of onTick lmao

edit: changed it to NPC.get instead and still don't know what to do. which offset would i use? i figured it out

User avatar
ztarwuff
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Mar 01, 2015 5:08 pm

Re: Need help with lua? - LunaLua General Help

Postby ztarwuff » Sat May 11, 2019 8:41 am

I'm creating a bossfight, and would be very grateful if I could get some help.

I've utilised lineguide.lua to create a fancy movement pattern, placed a moving platform on it, and attached the Mother Brain sprite to it. Now, my Mother Brain sprite is directional. I was thinking of forcing the sprite to face right if the speedX was negative and left if positive. However, when I used the below code to measure the speedX of the platform, it registered as zero. The same was true of the Mother Brain.

Code: Select all

function onTick()
	for index, Bossfish in ipairs(NPC.get(62)) do
		printText(Bossfish:mem(0x98, FIELD_DFLOAT), 24, 24) -- Measure BossFish's X speed (this gave a value of zero)
		printText(Bossfish:mem(0x78, FIELD_DFLOAT), 24, 48) -- Measure BossFish's X position (this bit works fine)
	end
end
First question: Is there a way of working out the SpeedX from the X position?

I'd rather not have a Mother Brain that just floats around in a fancy pattern. I'd like it to drop some projectiles at set intervals. The only problem is that I have no idea how NPC.spawn works. From reading the wiki, my understanding is that NPC.spawn goes in the same position as NPC.get. So I tried:

Code: Select all

function DropFish()
	for index, Deadfish in ipairs (NPC.spawn(30, Bossfish.x, Bossfish.y, 0)) do
	end
end

--Count to 99, then reset to zero
function TimeFunction()
	BossTimer = (BossTimer + 1) % 100
end

--Drop deadfish between 90 and 99
function onTick()
	if BossTimer > 90 then
		Dropfish()
	end
end
It returns a nil value, which, isn't surprising, because the code looks wrong. I'm sure there should be something after the do statement, but I've no idea what.

Any help would be greatly appreciated.

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat May 11, 2019 3:35 pm

In answer to your first question:

You can store the x position of your boss in a variable, which you update at the end of your onTick. Then, you can use boss.x - xposition to get the difference between your boss' position since it last moved. Using this, you can construct a kind of speed value.

As for your second one:

NPC.get is designed to get a list of objects. The whole for k,v in ipairs thing is a structure called a loop, which runs the internal code once for every object in a list. Since NPC.get returns a list, that allows you to run code on every object in that list.

Now, NPC.spawn, on the other hand, does not return a list of NPCs, but a single NPC object. You can assign the result of it to a variable, and then use that variable just as you would the loop variable when iterating inside an NPC.get loop. You don't need any loops to deal with NPC.spawn.

User avatar
ztarwuff
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Mar 01, 2015 5:08 pm

Re: Need help with lua? - LunaLua General Help

Postby ztarwuff » Sun May 12, 2019 10:57 am

Hoeloe wrote:
Sat May 11, 2019 3:35 pm
In answer to your first question:

...

As for your second one:

...
Thanks for the help. Everything works perfectly now. The boss sprite kind of freaks out when you hit it, but I think it works just fine as a hurt animation.

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun May 12, 2019 4:15 pm

Oh also, just noticed you're using printText and WOW that's some old code. You should use Text.print.

User avatar
ztarwuff
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Mar 01, 2015 5:08 pm

Re: Need help with lua? - LunaLua General Help

Postby ztarwuff » Mon May 13, 2019 4:15 am

Hoeloe wrote:
Sun May 12, 2019 4:15 pm
Oh also, just noticed you're using printText and WOW that's some old code. You should use Text.print.
Yeah, I started this project on the last A2XT package and haven't moved over to SMBX2.0 yet. Can't quite remember the reason right now, but something about the beta package is putting me off. I think it's a combination of a completely different graphics set and that the code is different, the latter of which, I wasn't completely aware of when I tried migrating.

I got the printText code from the LunaLua API wiki page on How To: Music and Sounds, because the Text.Print code didn't work for me.

Might look into properly migrating everything over next week.

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Mon May 13, 2019 5:44 am

Umm... if your build is so old that Text.print doesn't work... well, NPC.get and NPC.spawn won't either.

User avatar
ztarwuff
Cheep-Cheep
Cheep-Cheep
Posts: 11
Joined: Sun Mar 01, 2015 5:08 pm

Re: Need help with lua? - LunaLua General Help

Postby ztarwuff » Mon May 13, 2019 5:50 am

Hoeloe wrote:
Mon May 13, 2019 5:44 am
Umm... if your build is so old that Text.print doesn't work... well, NPC.get and NPC.spawn won't either.
No, they work fine, which is the weird thing. Goodness knows what kind of weird build I've got. Probably best if I erase everything and reinstall from scratch.

Draex
Shy Guy
Shy Guy
Posts: 5
Joined: Thu May 16, 2019 11:34 pm
Flair: Flair Text
Chat Username: Draex

Re: Need help with lua? - LunaLua General Help

Postby Draex » Thu May 16, 2019 11:43 pm

I'm trying to make a level that functions much like the "Board the Platforms" minigame from Smash Bros. I have platforms of various sizes that, when touched by the player, I want to change color. The documentation gave pretty clear instructions for how I can accomplish this with individual blocks, but I'm not sure how to go about it if I want the entire platform to change when the player touches it. There's roughly 60 of these platforms. Is there a way for a block to check if one of its neighbors changed color, and if not, what's another way I might go about this?

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Fri May 17, 2019 4:07 am

I'd use NPCs and the player.standingNPC field to check what npc the player is standing on to colour it in.
ImageImageImageImage
ImageImageImageImageImageImage

Draex
Shy Guy
Shy Guy
Posts: 5
Joined: Thu May 16, 2019 11:34 pm
Flair: Flair Text
Chat Username: Draex

Re: Need help with lua? - LunaLua General Help

Postby Draex » Sat May 18, 2019 7:27 pm

So are you suggesting I make NPCs that are varying numbers of tiles long and use those?

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sat May 18, 2019 7:37 pm

Draex wrote:
Sat May 18, 2019 7:27 pm
So are you suggesting I make NPCs that are varying numbers of tiles long and use those?
Yes.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
DrMekar
Ripper II
Ripper II
Posts: 368
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sat May 18, 2019 7:56 pm

The Darkness effect just won't work for me, but I don't know why.
Image
I also changed "DarknessField" to the name of my level, since it's called MyDarknessField in the Handbook, which looks like
somethink that is meant to be replaced.
Image
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 GM

Image

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7619
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sat May 18, 2019 8:02 pm

darknessField is a variable which you can name anything, though if you're familiar with programming I would avoid reserved symbols like ,.-+*/%"' etc...

The field doesn't work cause you set the shader and uniforms to an empty shader. The handbook details the default properties for these fields so if you don't wanna overwrite any you dont need to specify them at all.
ImageImageImageImage
ImageImageImageImageImageImage


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest