Page 1 of 1

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

Posted: Sat Nov 09, 2019 12:53 am
by Animebryan
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?

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

Posted: Sat Nov 09, 2019 10:27 pm
by Animebryan
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.

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

Posted: Mon Feb 17, 2020 7:39 am
by Animebryan
This issue was never resolved & I still need help with this

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

Posted: Mon Feb 17, 2020 7:59 am
by Hoeloe
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().

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

Posted: Mon Feb 17, 2020 9:03 pm
by Animebryan
Yeah, but I don't know how to set that up though

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

Posted: Sat Mar 07, 2020 2:28 am
by Animebryan
Still waiting for that Lua setup

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

Posted: Wed May 13, 2020 6:43 pm
by Animebryan
This problem still hasn't been resolved. Still need that setup...

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

Posted: Wed May 13, 2020 10:46 pm
by CJ_RLushi
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

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

Posted: Thu May 14, 2020 5:32 am
by Animebryan
You don't seem to realize that I don't know how to use Lua & therefore don't know how to set that up.

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

Posted: Thu May 14, 2020 7:11 pm
by CJ_RLushi
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.

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

Posted: Fri May 15, 2020 4:10 am
by Animebryan
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.

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

Posted: Fri May 15, 2020 1:54 pm
by CJ_RLushi
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

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

Posted: Fri May 15, 2020 2:22 pm
by Hoeloe
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.

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

Posted: Sat May 16, 2020 3:19 am
by Animebryan
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.

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

Posted: Sat May 16, 2020 6:27 am
by Taycamgame

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.

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

Posted: Sat May 16, 2020 6:31 am
by Enjl
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.

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

Posted: Sun May 17, 2020 12:37 pm
by Animebryan
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!