anothercurrency.lua - Count anything

Share and discuss custom LunaLua code and content packs for SMBX2.
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9015
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

anothercurrency.lua - Count anything

Postby Enjl » Sun Oct 20, 2019 7:23 am


Another repurposed and expanded piece of code. I always wrote this one from scratch for all of my episodes. It's barely 50 lines of actual logic, so it's not much, but it's not such a bad idea to have that boilerplate extracted into something generic.
This library just counts stuff you collected across levels. You have to handle drawing or shops yourself.

Spoiler: show
Code I used for the demo:
Spoiler: show
local anothercurrency = require("anothercurrency")

local myCurrency = anothercurrency.registerCurrency("Default+1up", true)
myCurrency:registerCoin(187, 10)
local myCurrency2 = anothercurrency.registerCurrency("Default", true)
local myCurrency3 = anothercurrency.registerCurrency("1up x2")
myCurrency3:registerCoin(187, 20)

local function doReward()
NPC.spawn(101, player.x, player.y - 150, player.section)
myCurrency3:registerLimit(100, doReward)

function onDraw()
Demo doesn't show all the library can do. There's comments in the code for everything. Additional features include
- comparison of a counter's value with a static value (shop price comparison)
- overrideable draw function (you should really override it cause the default is for debugging)
- being able to manually add/subtract from a counter (shops???)
- it saves reliably whenever smbx saves (SaveData) (make sure all the names are unique)
Ideas are useless if you can't make them real.

All my assets from packs and episodes are free to use for non-Novaverse levels and projects, as long as proper credit is given.

Mirror of all my content and collaborations on IPFS: QmZKzVJAsD6dE2tTHEb58XEmsNLzrW2MVsTtW7HWLAAcCC

The Toad Master BUP
Posts: 2
Joined: Fri Jan 03, 2020 2:23 pm

Re: anothercurrency.lua - Count anything

Postby The Toad Master BUP » Fri Jan 03, 2020 2:43 pm

You can make shops using this?Cool!

User avatar
Posts: 3
Joined: Mon Jun 10, 2019 11:35 am
Flair: *Splatted by BlueInkling!*

Re: anothercurrency.lua - Count anything

Postby BlueInkling » Mon Oct 26, 2020 10:52 am

I was using your anothercurrency.lua file to make a shop system with Dragon Coins as a currency. It's working well, except for the fact that entering a level resets the Dragon Coin counter back to zero. How can I make sure that the Dragon Coin counter gets saved in between levels?

My code:

Return to “LunaLua”

Who is online

Users browsing this forum: MrDoubleA, Rexius55 and 3 guests