anothercurrency.lua - Count anything

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

anothercurrency.lua - Count anything

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

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)

The Toad Master BUP
Goomba
Goomba
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!

BlueInkling
Goomba
Goomba
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:
https://imgur.com/a/z9sAF5h
https://imgur.com/a/v6V1uxN

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: anothercurrency.lua - Count anything

Postby Emral » Sun Feb 14, 2021 5:00 pm

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.

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: anothercurrency.lua - Count anything

Postby Wiimeiser » 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...

Murphmario
2025 Egg Hunter
2025 Egg Hunter
Posts: 2389
Joined: Fri Dec 20, 2013 7:07 pm
Pronouns: he/him

Re: anothercurrency.lua - Count anything

Postby Murphmario » Mon Feb 15, 2021 4:46 am

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.

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 529
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: anothercurrency.lua - Count anything

Postby Marioman2007 » Mon Feb 15, 2021 10:11 am

Is there a way to change the font?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: anothercurrency.lua - Count anything

Postby Emral » Mon Feb 15, 2021 11:07 am

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)

Mal8rk
Snifit
Snifit
Posts: 216
Joined: Mon Oct 25, 2021 11:04 pm
Flair: English Speaking Spanish Speaker
Pronouns: He/Him
Contact:

Re: anothercurrency.lua - Count anything

Postby Mal8rk » Tue Oct 11, 2022 11:08 am

Is there a way to change the Y/X position of your currency?

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 529
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: anothercurrency.lua - Count anything

Postby Marioman2007 » 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

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: anothercurrency.lua - Count anything

Postby Emral » Tue Oct 11, 2022 11:23 pm

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.

Wooliestplate89
Koopa
Koopa
Posts: 17
Joined: Sun Aug 15, 2021 12:25 am
Flair: Red sus, oh wait i'm red...
Pronouns: he/him
Contact:

Re: anothercurrency.lua - Count anything

Postby Wooliestplate89 » Tue Oct 25, 2022 8:03 am

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].


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari