Page 1 of 1
anothercurrency.lua - Count anything
Posted: Sun Oct 20, 2019 7:23 am
by Emral
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:
Code I used for the demo:
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!
Re: anothercurrency.lua - Count anything
Posted: Mon Oct 26, 2020 10:52 am
by BlueInkling
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:
https://imgur.com/a/z9sAF5h
https://imgur.com/a/v6V1uxN
Re: anothercurrency.lua - Count anything
Posted: Sun Feb 14, 2021 5:00 pm
by Emral
BlueInkling wrote: ↑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:
https://imgur.com/a/z9sAF5h
https://imgur.com/a/v6V1uxN
Sorry for the late response. Just now got around to fixing it.
Either redownload the file, or alter line 85 of anothercurrency to set _value rather than value. Silly oversight, there.
Re: anothercurrency.lua - Count anything
Posted: Sun Feb 14, 2021 11:11 pm
by Wiimeiser
I wonder if this could be used to override Rupees... You'd need a lot of overrides for all the hardcoded stuff, though...
Re: anothercurrency.lua - Count anything
Posted: Mon Feb 15, 2021 4:46 am
by Murphmario
Wiimeiser wrote: ↑Sun Feb 14, 2021 11:11 pm
I wonder if this could be used to override Rupees... You'd need a lot of overrides for all the hardcoded stuff, though...
Should be relatively simple to replace the Rupee counter. Just alter the hud to display the amount of currency you have instead of coins/rupees, and just keep the vanilla coin/rupee counter at one.
Re: anothercurrency.lua - Count anything
Posted: Mon Feb 15, 2021 10:11 am
by Marioman2007
Is there a way to change the font?
Re: anothercurrency.lua - Count anything
Posted: Mon Feb 15, 2021 11:07 am
by Emral
marioman2007 wrote: ↑Mon Feb 15, 2021 10:11 am
Is there a way to change the font?
Read the first post and/or the in-file documentation.
Enjl wrote: ↑Sun Oct 20, 2019 7:23 am
- overrideable draw function (you should really override it cause the default is for debugging)
Re: anothercurrency.lua - Count anything
Posted: Tue Oct 11, 2022 11:08 am
by Mal8rk
Is there a way to change the Y/X position of your currency?
Re: anothercurrency.lua - Count anything
Posted: Tue Oct 11, 2022 9:28 pm
by Marioman2007
Mal8rk wrote: ↑Tue Oct 11, 2022 11:08 am
Is there a way to change the Y/X position of your currency?
Code: Select all
local currencyX = 0
local currencyY = 0
function onDraw()
Text.printWP(myCurrency:getMoney(), 1, currencyX, currencyY, 5)
end
Re: anothercurrency.lua - Count anything
Posted: Tue Oct 11, 2022 11:23 pm
by Emral
Marioman2007 wrote: ↑Tue Oct 11, 2022 9:28 pm
Mal8rk wrote: ↑Tue Oct 11, 2022 11:08 am
Is there a way to change the Y/X position of your currency?
Code: Select all
local currencyX = 0
local currencyY = 0
function onDraw()
Text.printWP(myCurrency:getMoney(), 1, currencyX, currencyY, 5)
end
the recommended way is to override the draw function, as noted 3 posts above this one.
Code: Select all
local currencyX = 0
local currencyY = 0
local function drawCurrency(currency)
Text.printWP(currency:getMoney(), 1, currencyX, currencyY, 5)
end
myCurrency.draw = drawCurrency
function onDraw()
myCurrency:draw()
end
benefit being that you can do this in one script and call :draw from another, or easily have different draw functions for different currencies.
Re: anothercurrency.lua - Count anything
Posted: Tue Oct 25, 2022 8:03 am
by Wooliestplate89
No offences but, bro what on earth is that test level! At least make a good looking level to test stuff in, because this looks like [censored].