Share and discuss custom LunaLua code and content packs for SMBX2.
|
|
|
|
-
Enjl
- Cute Yoshi Egg

- Posts: 9491
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Orphion Egamalenitar Osmos IV, Esq.
Postby Enjl » 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:
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)
|
|
|
|
|
|
|
|
|
-
BlueInkling
- Goomba

- Posts: 3
- Joined: Mon Jun 10, 2019 11:35 am
- Flair: *Splatted by BlueInkling!*
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
|
|
|
|
|
|
|
|
|
-
Enjl
- Cute Yoshi Egg

- Posts: 9491
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Orphion Egamalenitar Osmos IV, Esq.
Postby Enjl » 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

- Posts: 211
- Joined: Mon Jun 24, 2019 4:36 am
- Flair: What?
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
- Chargin' Chuck

- Posts: 2343
- Joined: Fri Dec 20, 2013 7:07 pm
- Pronouns: he/him
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
- Buster Beetle

- Posts: 401
- Joined: Tue Aug 25, 2020 3:19 am
- Pronouns: He/Him
Postby Marioman2007 » Mon Feb 15, 2021 10:11 am
Is there a way to change the font?
|
|
|
|
|
|
|
|
|
-
Enjl
- Cute Yoshi Egg

- Posts: 9491
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Orphion Egamalenitar Osmos IV, Esq.
Postby Enjl » 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
- Tweeter

- Posts: 154
- Joined: Mon Oct 25, 2021 11:04 pm
- Flair: I like socializing with people online
- Pronouns: He/Him
-
Contact:
Postby Mal8rk » Tue Oct 11, 2022 11:08 am
Is there a way to change the Y/X position of your currency?
|
|
|
|
|
|
|
|
|
-
Marioman2007
- Buster Beetle

- Posts: 401
- Joined: Tue Aug 25, 2020 3:19 am
- Pronouns: He/Him
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
|
|
|
|
|
|
|
|
|
-
Enjl
- Cute Yoshi Egg

- Posts: 9491
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Orphion Egamalenitar Osmos IV, Esq.
Postby Enjl » 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

- Posts: 17
- Joined: Sun Aug 15, 2021 12:25 am
- Flair: Red sus, oh wait i'm red...
- Pronouns: he/him
-
Contact:
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”
Users browsing this forum: No registered users and 5 guests
|