Slopes.lua

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Slopes.lua

Postby TDK » Sun Jul 02, 2017 9:35 am

With this API, you can have a more dynamic slope physics.

How to use:
1. First put everything provided into your level folder.
2. Make a lunadll.lua file and type this in the lunadll.lua file:

Code: Select all

local slopes = API.load("slopes")
A. Activate steep slope physics:
On default the steep slopes will not have the correct physics, so you have to type this in the lunadll.lua file:

Code: Select all

slopes.steep = {list of block-id of all the steep slopes in your level}
For example if you're using block-305 and block-307 as steep slopes, you would have to type:

Code: Select all

slopes.steep = {305,307}
B. If you want to revert back to original SMBX slope physics, just type:

Code: Select all

slope.physics = false
C. To make jump through slopes, just type:

Code: Select all

slopes.jump_through ={list of block-id of all the jump through slopes}
For example if you're using block-299 and block-300 as jump through slopes, you would have to type:

Code: Select all

slopes.jump_through ={299,300}[
You need to have the slope graphics in your level folder and it must be .png.
Note that npc-92.txt is required for jump through slopes. Also that this only works for slopes at 45° slopes.

Don't have too many jump-through slopes as each slope uses quite a lot of NPC slots which can cause issues if there's too many jump-through slopes.
(Please note that due to how SMBX work jump-through slopes going at / direction are buggier than \ direction, when NPCs are on top of it)

D. To make slopes slippery, type:

Code: Select all

slopes.slippery = {list of block-id of any slippery slopes}
If you find any bugs please comment.

Here's a level that uses this.


Download and enjoy:
https://www.dropbox.com/s/6q8tb70yq6bn4 ... s.zip?dl=0
Alternative download link: https://www.mediafire.com/?mb3plo2zi5r9m7m
Last edited by TDK on Sat Mar 23, 2019 5:54 pm, edited 18 times in total.

Mr Boboo
Spike
Spike
Posts: 267
Joined: Sat Jan 04, 2014 8:43 am
Flair: The Wicked Pissah

Re: Slopes API

Postby Mr Boboo » Thu Jul 13, 2017 10:19 pm

So I put this in my level and followed all the instructions, and uhhhhhh
Spoiler: show
Image
Also the slopes couldn't even be jumped through. Am I doing something wrong or is this an issue with the code?
EDIT: I added the .txt file to the level, but now when I try to load it PGE just crashes.

TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Slopes API

Postby TDK » Fri Jul 14, 2017 5:41 am

Mr Boboo wrote:So I put this in my level and followed all the instructions, and uhhhhhh
Spoiler: show
Image
Also the slopes couldn't even be jumped through. Am I doing something wrong or is this an issue with the code?
EDIT: I added the .txt file to the level, but now when I try to load it PGE just crashes.
I would recommend updating PGE, as I've noticed that this crashes Beta 3's PGE: http://wohlsoft.ru/forum/viewtopic.php?f=11&t=1977.

As for the jump-through slopes, did you place only the BGO (and not the blocks) ?
Also slightly updated version: https://www.dropbox.com/s/buuyzqw68he3n ... s.zip?dl=0
Last edited by TDK on Fri Jul 14, 2017 3:45 pm, edited 2 times in total.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Slopes API

Postby Hoeloe » Fri Jul 14, 2017 5:58 am

Might be a better idea, by the way, to set this up so the user places the blocks, not a BGO, and draw the block with Lua. That way you will only need to place the block down and reference it in the API, and it'd just work - no need to use a BGO as well.

TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Slopes API

Postby TDK » Fri Jul 14, 2017 6:06 am

Hoeloe wrote:Might be a better idea, by the way, to set this up so the user places the blocks, not a BGO, and draw the block with Lua. That way you will only need to place the block down and reference it in the API, and it'd just work - no need to use a BGO as well.
I guess I should have done that instead, never thought about doing that way.

Here's the improved version: https://www.dropbox.com/s/h2bb86js0wciq ... s.zip?dl=0

Mr Boboo
Spike
Spike
Posts: 267
Joined: Sat Jan 04, 2014 8:43 am
Flair: The Wicked Pissah

Re: Slopes API

Postby Mr Boboo » Fri Jul 14, 2017 10:26 pm

Ok so I managed to get the API working (turns out I need a slope layer) and it works great! The only thing is that sometimes enemies will clip through a jump-through slope when they're supposed to go up. The player can also sometimes clip through it by ducking.

TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Slopes API

Postby TDK » Sat Jul 15, 2017 4:39 pm

Mr Boboo wrote:Ok so I managed to get the API working (turns out I need a slope layer) and it works great! The only thing is that sometimes enemies will clip through a jump-through slope when they're supposed to go up. The player can also sometimes clip through it by ducking.
Thanks for noting that. I found out how to fix the ducking issue, but not the enemies clipping through the slope. I'll release another update once I fix that.

Mr Boboo
Spike
Spike
Posts: 267
Joined: Sat Jan 04, 2014 8:43 am
Flair: The Wicked Pissah

Re: Slopes API

Postby Mr Boboo » Mon Jul 17, 2017 12:14 pm

Okay, everything works fine now but for whatever reason my level crashes if I have more than 5 jump-through slopes in it.

TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Slopes API

Postby TDK » Mon Jul 17, 2017 5:32 pm

New update:
https://www.dropbox.com/s/6q8tb70yq6bn4 ... s.zip?dl=0

This version should minimize the clipping issue.
Also note that this version uses a new technique for jump through slopes, which is explained in the OP.

SMB3
Rex
Rex
Posts: 32
Joined: Thu May 22, 2014 8:12 pm

Re: Slopes API

Postby SMB3 » Sat Sep 23, 2017 10:52 pm

So I'm trying to make blocks 326 and 327 (up-left and up-right blue slopes from SMB1) into jump-through slopes, and I'm getting an error:
Spoiler: show
Image
As far as I can tell, nothing is wrong with my lunadll file, which simply contains this:

Code: Select all

local slopes = API.load("slopes")
slopes.jump_through = {326, 327}
It used to also contain

Code: Select all

slopes.jumped_through = true
but that had no effect.
I tried debugging this by going into slopes.lua, but the farthest I got was this:

Code: Select all

function slopes.onTick()
	for k,v in pairs(NPC.get(1,0)) do
		Text.print(v.direction,0,0)
	end
	for k,v in pairs(slopes.position) do
		Graphics.drawImageToSceneWP(Graphics.loadImage("block-"..tostring(v[3])..".png"),v[1],v[2],-95)
	end
This is the only instance of drawImageToSceneWP in the file as far as I can tell. I have no experience with lua, so I don't know how to trace it back any further than that (or what mainV2.lua is). Any ideas? Sorry if I'm missing something obvious... I'm very tired :(

TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Slopes API

Postby TDK » Mon Sep 25, 2017 4:20 pm

SMB3 wrote:So I'm trying to make blocks 326 and 327 (up-left and up-right blue slopes from SMB1) into jump-through slopes, and I'm getting an error:
Spoiler: show
Image
As far as I can tell, nothing is wrong with my lunadll file, which simply contains this:

Code: Select all

local slopes = API.load("slopes")
slopes.jump_through = {326, 327}
It used to also contain

Code: Select all

slopes.jumped_through = true
but that had no effect.
I tried debugging this by going into slopes.lua, but the farthest I got was this:

Code: Select all

function slopes.onTick()
	for k,v in pairs(NPC.get(1,0)) do
		Text.print(v.direction,0,0)
	end
	for k,v in pairs(slopes.position) do
		Graphics.drawImageToSceneWP(Graphics.loadImage("block-"..tostring(v[3])..".png"),v[1],v[2],-95)
	end
This is the only instance of drawImageToSceneWP in the file as far as I can tell. I have no experience with lua, so I don't know how to trace it back any further than that (or what mainV2.lua is). Any ideas? Sorry if I'm missing something obvious... I'm very tired :(
Thanks for telling me about the error.
Can you give me a download link of your level?

PixelPest
Raccoon Mario
Raccoon Mario
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Slopes API

Postby PixelPest » Mon Sep 25, 2017 4:25 pm

SMB3 wrote:
Are you using .gif files for the graphics of these? That would cause the error

SMB3
Rex
Rex
Posts: 32
Joined: Thu May 22, 2014 8:12 pm

Re: Slopes API

Postby SMB3 » Mon Sep 25, 2017 11:54 pm

TheDinoKing wrote: Thanks for telling me about the error.
Can you give me a download link of your level?
Here you are: https://www.dropbox.com/s/irx66jsltqvoo ... r.zip?dl=0
There are custom graphics involved, but not on 326 and 327 (yet), and the error only occurs while they are placed in the level. Be aware that there are platforms in front of the roof of the house (they're invisible). Thanks for your help! I can see awesome things with this API!
PixelPest wrote:Are you using .gif files for the graphics of these? That would cause the error
For the graphics of what, the turnips? You're addressing Dino, right?

TDK
Foo
Foo
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Slopes API

Postby TDK » Tue Sep 26, 2017 8:18 am

SMB3 wrote:
TheDinoKing wrote: Thanks for telling me about the error.
Can you give me a download link of your level?
Here you are: https://www.dropbox.com/s/irx66jsltqvoo ... r.zip?dl=0
There are custom graphics involved, but not on 326 and 327 (yet), and the error only occurs while they are placed in the level. Be aware that there are platforms in front of the roof of the house (they're invisible). Thanks for your help! I can see awesome things with this API!
PixelPest wrote:Are you using .gif files for the graphics of these? That would cause the error
For the graphics of what, the turnips? You're addressing Dino, right?
He's addressing you, because you need to use .png graphics for it to work.

To fix your error:
- You need to put slopes.lua into your level's folder. (Make sure you have the latest version, check the OP.)
- Also put the .png version of the block-326 and 327 graphics in the level's folder as well. (You can use GIFs2PNG to convert the graphics to .png, it's in the PGE folder.)
- The slopes must be in the default layer.

I would warn you that the jump through slopes are somewhat buggy so don't use it too much.

SMB3
Rex
Rex
Posts: 32
Joined: Thu May 22, 2014 8:12 pm

Re: Slopes API

Postby SMB3 » Tue Sep 26, 2017 9:19 pm

Hmm, that did fix the issue. The blocks have a black background behind them as though the mask were solid black, but they seem to function right now. I'm still kind of confused though:
  • Why do the graphics need to be inside my level's folder? Is there a reason they can't be read directly from SMBX's graphics directory?
  • On a related note, why do they need to be in PNG format? (Is this why it can't read straight from the graphics directory?) All SMBX graphics I've used or made have been done with gifs for as long as I can remember, and they're what the base game uses.
  • The slopes.lua file doesn't need to be in the level directory for my lunadll.lua file to access it (it works from inside the LuaScriptsLib folder). Wouldn't it make more sense to distribute one copy of slopes.lua along with the entire episode if I intend to use it in more than one place, or barring that, just remind players that "lunalua files x y and z are required for this episode, go download them" instead?
I've never worked with Lua and don't have any professional experience with any language, so I'm guessing there are good answers for these. These just seem like some odd requirements. It works now, though; thanks for your help!

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Slopes API

Postby The0x539 » Tue Sep 26, 2017 11:47 pm

SMB3 wrote:Why do the graphics need to be inside my level's folder? Is there a reason they can't be read directly from SMBX's graphics directory?
Because nobody else is going to have those graphics in their graphics folder.
SMB3 wrote:On a related note, why do they need to be in PNG format? (Is this why it can't read straight from the graphics directory?)
Because Graphics.drawImage only works with PNG images. Yes.
SMB3 wrote:All SMBX graphics I've used or made have been done with gifs for as long as I can remember, and they're what the base game uses.
False as of 2.0 Beta 4.
SMB3 wrote:The slopes.lua file doesn't need to be in the level directory for my lunadll.lua file to access it (it works from inside the LuaScriptsLib folder). Wouldn't it make more sense to distribute one copy of slopes.lua along with the entire episode if I intend to use it in more than one place, or barring that, just remind players that "lunalua files x y and z are required for this episode, go download them" instead?
Package it with the episode, why would you make people download two things from two places to play one thing, without a dependency-resolving package manager?

SMB3
Rex
Rex
Posts: 32
Joined: Thu May 22, 2014 8:12 pm

Re: Slopes API

Postby SMB3 » Wed Sep 27, 2017 12:17 am

The0x539 wrote:
SMB3 wrote: All SMBX graphics I've used or made have been done with gifs for as long as I can remember, and they're what the base game uses.
False as of 2.0 Beta 4.
I thought Beta 4 wasn't out yet? Quick Google search suggests it's still beta 3 (Klonoa/Juni/Uncle Broadsword still in the changelog on Horikawa's site, the download post on these forums still has Beta 3 in the title). I take it Beta 4 will convert everything to PNGs for drawImage's ease of use, then?
The0x539 wrote:Package it with the episode, why would you make people download two things from two places to play one thing, without a dependency-resolving package manager?
That was my first suggestion - include one copy of the lua file(s) with the episode and tell them, via readme and OP, to put it/them in LuaScriptsLib. That just seems more sensible to me than repeatedly including copies of the same file. The second suggestion would be a last resort in a case where someone didn't want you to redistribute their lua file (which would be silly and unlikely, but possible).

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Slopes API

Postby The0x539 » Wed Sep 27, 2017 2:10 am

SMB3 wrote:
The0x539 wrote:
SMB3 wrote: All SMBX graphics I've used or made have been done with gifs for as long as I can remember, and they're what the base game uses.
False as of 2.0 Beta 4.
I thought Beta 4 wasn't out yet? Quick Google search suggests it's still beta 3 (Klonoa/Juni/Uncle Broadsword still in the changelog on Horikawa's site, the download post on these forums still has Beta 3 in the title). I take it Beta 4 will convert everything to PNGs for drawImage's ease of use, then?
For everything's ease of use. SMBX only ever used GIFs at all due to poor programming ability on Redigit's part.
SMB3 wrote:
The0x539 wrote:Package it with the episode, why would you make people download two things from two places to play one thing, without a dependency-resolving package manager?
That was my first suggestion - include one copy of the lua file(s) with the episode and tell them, via readme and OP, to put it/them in LuaScriptsLib. That just seems more sensible to me than repeatedly including copies of the same file. The second suggestion would be a last resort in a case where someone didn't want you to redistribute their lua file (which would be silly and unlikely, but possible).
API.load searches first in the level folder, then in the episode folder, then in LuaScriptsLib. If you have an API you're loading in multiple levels' code, stick it in the episode folder. If you have level Lua you want to run in every level, stick it in lunaworld.lua in the episode folder rather than in lunadll.lua in the level folder.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari