Collecting all Star Coins on a layer isn't making my Star layer appear

Need help with any SMBX game-related issues? Ask your questions here.
User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Sat Nov 09, 2019 12:53 am

One of the basic mechanics in my episode is to have the player collect 5 star coins in a level in order to get the star to appear in a certain spot. In my current level, I've been testing it to make sure that collecting all 5 star coins is possible & that the star appears like it's supposed to, but it's not. Event wise, this is pretty simple. I have all 5 star coins on a 'Star Coins' layer, with each one set with it's Star Coin ID & the option that when all objects on that layer are gone, the 'Star' layer would show. The event itself is also pretty basic. Collecting all 5 Star Coins should trigger the event, which in turn should show the star layer, but it won't.

When I used cheat codes to make the test playing easier (the level is HARD), I noticed that the star did appear, but when I wasn't using cheat codes & collected all 5 star coins (which required many tries), the star wasn't there. The reason I used the cheat codes was to confirm a suspicion I had about whether Star Coins are still considered to be collected after restarting at a checkpoint, in which case, any star coins collected before reaching a checkpoint are saved, but ones you collect afterward before you die are not. But when I collected the 5th & final one, it made a notification sound that normally happens when you collect all the star coins from a level.

So is this some sort of bug or something? How can I fix this issue?
Need serious help with Lua based features :(

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Sat Nov 09, 2019 10:27 pm

Update: I've posted this on Wohlstand's site as well & tested a level he gave me (which I had to modify) & with it, I was able to confirm my suspicion on how star coins work when placed on a layer.



As you can plainly see, if you put all your star coins on a layer, collect some of them & reach a checkpoint & then die & restart from there, the game will show that it saved the star coins that you've collected so far, but for the sake of collecting everything on that layer, they don't count & you'll have to recollect them as well. This means you have to collect all the star coins in 1 try to make the star layer appear. This is a huge problem for those who want to hide away their stars by having to collect star coins in a level.

What I don't understand is how nobody noticed this before & said anything about it.
Need serious help with Lua based features :(

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Mon Feb 17, 2020 7:39 am

This issue was never resolved & I still need help with this
Need serious help with Lua based features :(

User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1226
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Hoeloe » Mon Feb 17, 2020 7:59 am

I believe it was explained before that this isn't a bug. These star coins behave like literally every other NPC in the engine, and the consistency of it means this won't be changed.

You can still achieve this effect through Lua, since you can load "npcs/ai/starcoin", and then check startcoin.count() against starcoin.getLevelCollected().

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Mon Feb 17, 2020 9:03 pm

Yeah, but I don't know how to set that up though
Need serious help with Lua based features :(

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Sat Mar 07, 2020 2:28 am

Still waiting for that Lua setup
Need serious help with Lua based features :(

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Wed May 13, 2020 6:43 pm

This problem still hasn't been resolved. Still need that setup...
Need serious help with Lua based features :(

User avatar
CJ_RLushi
Bit
Bit
Posts: 145
Joined: Wed Dec 25, 2019 11:39 pm
Flair: Intention is what matters
Current Project: Another Super Mario Bros. 3 Remake [SMBX2]

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby CJ_RLushi » Wed May 13, 2020 10:46 pm

Hoeloe of told you how to do it, just do that check with those two starcoin.count() and starcoin.getLevelCollected(), then if thats true just use that just do a triggerEvent("EventThatShowsYourLayer") or just getting the layer from LUA using local local something = Layer.get("thelayerofyourstar") and then showing the layer using the something:show(true/false smoke effect) function

I guess the comparison should be if starcoin.getLevelCollected() >= starcoin.count() or something like that

Added in 1 minute 24 seconds:
PD: Oh and of course starcoin is a library just like how hoeloe told you, just load it using local starcoin = require("npcs/ai/starcoin"), which loads the libary and stores it into the starcoin variable
My episode lol:
Image

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Thu May 14, 2020 5:32 am

You don't seem to realize that I don't know how to use Lua & therefore don't know how to set that up.
Need serious help with Lua based features :(

User avatar
CJ_RLushi
Bit
Bit
Posts: 145
Joined: Wed Dec 25, 2019 11:39 pm
Flair: Intention is what matters
Current Project: Another Super Mario Bros. 3 Remake [SMBX2]

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby CJ_RLushi » Thu May 14, 2020 7:11 pm

Okay so i'll give you a code but please also read the explanation i'm going to give to it.

Code: Select all

local starcoin = require("npcs/ai/starcoin")

function onTick()
    if starcoin.getLevelCollected(Level.filename()) >= starcoin.count() then
        triggerEvent("starAppear")
    end
end
Explanation time
So this is pretty easy code, and this should be in a luna.lua code, either in your level or episode folder.
the first line of code, the local starcoin thing, well, this is just defining a variable, you can define variables just by typing any letter, but by putting local we'll create a local variable, which is only accesible in the place it was created, in this case by defining it only in the code file is accesible only in this code, and after defining the variable and giving it the name starcoin, we do require("npcs/ai/starcoin"), which loads the library starcoin in npcs/ai, and stores it inside the variable starcoin

The next line has function onTick() which is a function that we're defining, and functions are pretty easy, they're chunks of code that we can store to reutilize later just by calling the function, in the case of function onTick, it's a function that if its defined then it's called every frame while the game is not paused

the next line is the IF one, and it's pretty simple, when you put if you re asking a question to the program, in this case is if starcoin.getlevelcollected is greater or equial (>=) than starcoin.count(), we'll talk about then later, so, after comparing them if the program returns yes to that question then the next line of code is going to execute, and we let know the program we finished asking with THEN.

Now to talk about getlevelcollected and starcoin.count, so, these are functions of the starcoin library, that currently is stored in the variable starcoin, so those functions return the amount of starcoins we have collected and the amount of starcoins that are in the level, we know these are functions due to the (), that defines that this is a function and not a variable, but also, functions come with variables than can be defined in their (), and we can modify that variable when we call the variable using again the (), for example in getlevelcollected we need to indicate to the program which level are we trying to access, so we pass to the argument the function Level.filename(), that returns the filename of the current level.

Then the rest is just easy, we have triggerEvent("starAppear"), which just is a simple function that triggers an event with the name we pass to it in the format of a string, a type of variable that stores code, defined with ", in this case is starAppear but you can change it if you want.

And then end, which is a command to indicate to the program that we finished with something, so with the first end we're indicating to the program that only the code before it matters to the if, for, or function that we defined, everything of that kind should have an END after you ended defining the code you want to run in that, and of course the other end just closes the function.
My episode lol:
Image

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Fri May 15, 2020 4:10 am

Well it works, although most of those explanations went right over my head, hence why I'm not any good at programming.
There is one flaw though. Whenever I collect the last Star Coin, the level suddenly starts to lag really badly.
Need serious help with Lua based features :(

User avatar
CJ_RLushi
Bit
Bit
Posts: 145
Joined: Wed Dec 25, 2019 11:39 pm
Flair: Intention is what matters
Current Project: Another Super Mario Bros. 3 Remake [SMBX2]

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby CJ_RLushi » Fri May 15, 2020 1:54 pm

Oh I can sort of see why that is happening, we{re running the event always, not only just one time

Added in 19 seconds:
Ill take a look at it later, im currently doing homework
My episode lol:
Image

User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1226
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Hoeloe » Fri May 15, 2020 2:22 pm

Animebryan wrote:
Fri May 15, 2020 4:10 am
hence why I'm not any good at programming.
Honestly, with the amount of time you've sat here waiting for someone to write your code for you, you could have learned how to do it yourself. You're "not any good at programming" because you haven't made any attempt to actually do it. No-one understands code immediately, you have to actually make some effort to learn how it works. I would recommend some basic Lua tutorials to get started, such as this one:

https://www.tutorialspoint.com/lua/

As for your specific problem, introducing a second variable will do the trick, which can be used to check if the event has already been executed. In this case you'd want a boolean variable (that is, a "yes or no" value, signified by "true" and "false"), and assign it to false initially. In your conditional "if" statement, you can use the "and" keyword to check for multiple conditions (there is also "or", but that's not what you need in this case), so you should also check the value of this variable is false. Then, when the condition executes and your event is triggered, you can set that variable to true, thereby preventing the condition from completing again.

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Sat May 16, 2020 3:19 am

Hoeloe wrote:
Fri May 15, 2020 2:22 pm
Animebryan wrote:
Fri May 15, 2020 4:10 am
hence why I'm not any good at programming.
Honestly, with the amount of time you've sat here waiting for someone to write your code for you, you could have learned how to do it yourself. You're "not any good at programming" because you haven't made any attempt to actually do it. No-one understands code immediately, you have to actually make some effort to learn how it works. I would recommend some basic Lua tutorials to get started, such as this one:

https://www.tutorialspoint.com/lua/

As for your specific problem, introducing a second variable will do the trick, which can be used to check if the event has already been executed. In this case you'd want a boolean variable (that is, a "yes or no" value, signified by "true" and "false"), and assign it to false initially. In your conditional "if" statement, you can use the "and" keyword to check for multiple conditions (there is also "or", but that's not what you need in this case), so you should also check the value of this variable is false. Then, when the condition executes and your event is triggered, you can set that variable to true, thereby preventing the condition from completing again.
Need serious help with Lua based features :(

User avatar
Taycamgame
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 1370
Joined: Mon Jun 19, 2017 11:35 am
Flair: Stargard
Current Project: Mario's Kingdom Adventure
Chat Username: Taycamgame
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Taycamgame » Sat May 16, 2020 6:27 am

Code: Select all

local starcoin = require("npcs/ai/starcoin")
local collected = false

function onTick()
    if starcoin.getLevelCollected(Level.filename()) >= starcoin.count() and not collected then
        triggerEvent("starAppear")
        collected = true
    end
end
This should make it so that the triggerEvent line only ever runs once.
Official Level Reviewer (My Gold Yoshi Egg rank replaced the level reviewer icon, but i am still a level reviewer).
Image
Image
Image
Image
Check out the World Map Service that i host:
viewtopic.php?p=316733#p316733
Check out the projects i support:
Spoiler: show
ImageImage
Image
Image
Quotes: show
xDestroy wrote:
Wellington Games wrote:Taycamgame, I know how to take screenshots in the SMBX.
https://nsmbx.proboards.com/
------
Tower Mario Bros.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8568
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Enjl » Sat May 16, 2020 6:31 am

In response to the video: The video talks about the profession of programming, not the act of coding.
The former is a specialized profession, like being an author.
The latter is a skill, like reading and writing sentences.
Like how being an author requires reading comprehension, programming requires coding. However, me being able to type sentences doesn't make me an author or remotely interested in writing novels. Being able to do addition and subtraction doesn't make someone a mathematician, either. Coding is the same for programming.

Coding has a lot of overlap with general logic-based understanding. Most of coding is chaining together logic statements "if x is the case, then y should happen" and such. Please do yourself a favour and analyze the difference between Taycam's code and CJ's code. If you have any questions about why the changes made lead to this result, I'm happy to answer them for you.
The ABC of Creation
________________________________________________________
Image

User avatar
Animebryan
Blooper
Blooper
Posts: 186
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Current Project: Star of Darkness
Contact:

Re: Collecting all Star Coins on a layer isn't making my Star layer appear

Postby Animebryan » Sun May 17, 2020 12:37 pm

Taycamgame wrote:
Sat May 16, 2020 6:27 am

Code: Select all

local starcoin = require("npcs/ai/starcoin")
local collected = false

function onTick()
    if starcoin.getLevelCollected(Level.filename()) >= starcoin.count() and not collected then
        triggerEvent("starAppear")
        collected = true
    end
end
This should make it so that the triggerEvent line only ever runs once.
Thank you!
Need serious help with Lua based features :(


Return to “Help and Support”

Who is online

Users browsing this forum: SemrushBot [Bot] and 10 guests