Ziplines.lua - Zip across the stage with ease! V1.1

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

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?
Benial
Bot
Bot
Posts: 50
Joined: Thu Dec 15, 2016 4:28 pm
Flair: It's!
Pronouns: He/Him

Ziplines.lua - Zip across the stage with ease! V1.1

Postby Benial » Sun Jan 21, 2018 5:08 pm

Am I one of them there lunar lua cool kids now?
Image
Ziplines! They zip, but without lines! Simply jump into them and until you hit a wall or jump off, you can glide through the air and climb up trees.
Functions
  • Latch on by jumping into zipline. Get off with a jump or Spinjump
  • Breaks when the player gets off or if you hit a wall.
  • Collide with a Zipline Reflector to change your direction
  • Turn on "Don't Move" to make it only move Vertically
  • Turn on "Friendly" to make it only move Horizontally
  • Use the lunadll.lua file to customise how each setting affects speed (See spoiler below)
lunadll.lua formatting guide: show

Put "Ziplines.speeds = {}" in the code.
Enter values as follows into brackets: X with "Don't Move", Y with "Don't Move", X with "Friendly", Y with "Friendly", Default X, Default Y.

Please note it has not been created with nor tested in Multiplayer. Behaviour may become finicky if you have to drag a friend with you.
Changelog: show
1.1: Code cleaned up and optimised better.
Download here, with example level if you need it.
Last edited by Benial on Thu Jan 25, 2018 4:53 pm, edited 1 time in total.

Eri7
Banned
Posts: 1770
Joined: Sat Jan 28, 2017 4:48 pm
Flair: Good Foundation allows for strong Execution
Contact:

Re: Ziplines.lua - Zip across the stage with ease!

Postby Eri7 » Sun Jan 21, 2018 6:14 pm

This looks fantastic , i will sure use it for my project.

OlieGamerTV
Spike
Spike
Posts: 273
Joined: Sun Nov 26, 2017 7:23 am

Re: Ziplines.lua - Zip across the stage with ease!

Postby OlieGamerTV » Sun Jan 21, 2018 6:39 pm

Oh my, that looks so cool! i can see many episodes that could use this.

erkyp3rky
Ninji
Ninji
Posts: 934
Joined: Fri Apr 15, 2016 1:41 am
Flair: formerly theloaflord

Re: Ziplines.lua - Zip across the stage with ease!

Postby erkyp3rky » Sun Jan 21, 2018 6:49 pm

Benial wrote:Am I one of them there lunar lua cool kids now?
Yes.

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

Re: Ziplines.lua - Zip across the stage with ease!

Postby The0x539 » Thu Jan 25, 2018 3:25 pm

Few things about the code, in decreasing order of importance:
Local Variables: show

Code: Select all

v.touching = false
v.colliding = false
v.clipping = false
v.dismount = false
Use local variables for things like this. Declare (and initialize, if appropriate, like here) variables with those names, touching, colliding, etc, and just read them from that. Don't put them in v when you're neither storing them for future ticks (not that that would work, there's another way to do that but it's not important now) or using them as vanilla fields (like working with v.x, which you do).
pairs and ipairs: show

Code: Select all

for k,v in pairs (NPC.get(214,player.section)) do
There are two main functions for iterating over tables. pairs, which you use, is suited for tables like

Code: Select all

t = {[3] = 5, foo = true, ["some other key idk"] = "fizz"}
t[3] is 5, t["foo"] is true, and so on.
Here, pairs is guaranteed to get every entry in the table. However, some tables look more like

Code: Select all

t = {1,false,34,"abc"}
Note how no keys are specified, so the keys are sequential. t[1] is 1, t[2] is false, t[3] is "abc". NPC.get, and all the other "get" functions SMBX has, return tables that look like this. Here, ipairs is more useful. It's guaranteed to go through all of the entries in order, and more importantly it's faster.
Event Naming: show

Code: Select all

registerEvent(Ziplines,"onTick","eachFrame")
Unless you have a reason not to, just name the function onTick. As a bonus, if the function name is the same as the event name, you don't need to use the third argument.
Boolean Expressions: show

Code: Select all

someExpr == true
anotherExpr == false
This is very rarely necessary. You can just put someExpr in whatever, and unless it's false or nil, it will be considered true. Similarly, it's generally better to express (not anotherExpr).
Other Small Nitpicks: show
  • It's Lua or lua, never LUA.
  • I wouldn't recommend capitalizing a Lua API name unless it's meant to be a class in an object-oriented kinda thing, which this isn't.
  • The NPC class has friendly and dontMove fields, which you can use instead of memory offsets 0x46 and 0x48.
  • What's the purpose of colliding = true in onInitAPI?
  • Avoid playSFX, always use Audio.PlaySFX
  • v.direction = -v.direction

Benial
Bot
Bot
Posts: 50
Joined: Thu Dec 15, 2016 4:28 pm
Flair: It's!
Pronouns: He/Him

Re: Ziplines.lua - Zip across the stage with ease!

Postby Benial » Thu Jan 25, 2018 3:58 pm

The0x539 wrote:Few things about the code, in decreasing order of importance:
I expected I'd have to clean this up at some point. I'll get on with that and reupload a cleaner version.
(Wait, I used normal playSFX?)


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari