Page 1 of 1

anothercurrency.lua - Count anything

Posted: Sun Oct 20, 2019 7:23 am
by Enjl
Download:
https://pastebin.com/ErKyfRGX

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.

Demo:
Spoiler: show
Image
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)
end
myCurrency3:registerLimit(100, doReward)

function onDraw()
myCurrency:draw()
myCurrency2:draw()
myCurrency3:draw()
end
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)

Re: anothercurrency.lua - Count anything

Posted: Fri Jan 03, 2020 2:43 pm
by The Toad Master BUP
You can make shops using this?Cool!