[SOLVED] Collectibles (Star coin-esqe) system

I didn’t spot the other mistake - put the change scene after the global variables are reset. Anything after the change scene won’t be processed or run.

I’m sorry, but it still isn’t working. Is this even feasible in GDevelop?

So, what is it doing? Can you create another gif and a screenshot of the events, as that was really helpful last time?

It is quite feasible in GDevelop. Chances are that’s it’s just something that’s easily overlooked or missed.

Sorry about that. Here’s the code:


As for what it does, nothing changed.

That change scene is at the wrong level. It gets actioned after the first variable is reset, so the other variables are never touched. Drag the change scene event to the left so it’s the last sub-event of the x key pressed event (so 3 levels to the left).

So it looks like:

Okay, I made the change to my code. However, nothing changed. It’s still having the same problem.

Your line that resets the variable has Global.VariableString(idLoop). There should be no dot between Golbal and Variable.

It will work - I’ve made a test project myself and that works fine. If it doesn’t work for you, then there’s a mistake in the events.
.

I didn’t see that error there. Thanks for pointing that out.
It still doesn’t work for me. I’m just getting the exact same outcome.
deleteissue
(When the scene becomes jittery and the player resets his position, that’s me mashing x)

The action that decreases levelId is also at the wrong level/indentation. It needs to be left one, so it’s level with the second while clause.

Like this?


It still didn’t fix the problem

Like I said, I have it working, so there’s something wrong elsewhere.

You’re going to have to do some debugging. Here are some steps on what you could do, to confirm what parts work.

First, I suggest you move the change scene event to when another key is pressed. This will separate the resetting of the values from the changing scene and reloading the values.

Then, run the game in debug mode.

On the debug screen click the refresh button.
Then select global variables.
Take note of the values of the variables.

In the game, collect a few of your collectables.
Click the refresh button on the debug screen.
Confirm the variable values for the objects collected have changed.

Press the x button.
Click the refresh button on the debug screen.
Confirm the variable values have been reset.

Press the button that changes the scene.
Click the refresh button on the debug screen.
Confirm the variable values have been loaded.

If, at any part of the debugging process, you don’t get the results you expect, you have a better idea of where it’s going wrong. Then you start looking into that part.

I already know how to use the debugger. Here are the results:
image
When I press x, levelLoop and idLoop appear, but they never increment. They’re always 0. Also, the children don’t revert back to 0 either. This is also the case when changing scenes (Now mapped to z).

levelLoop and idLoop will be 0 because you’re capturing them after they’ve been decreased in the while loops.

Can you add some extra actions as follows (highlighted in yellow)? Then run the debugger again and view the global variables after pressing the x key. levelLoopTest should be 2 and idLoopTest should be 3.

Okay, I put the extra variables and ran the debugger. levelLoopTest is 2 (Representing the two levels), and idLoopTest is 3 (Representing the 3 collectibles in each level), just like you said it would.

What’s strange is that despite being the exact same action, levelLoop still returns 0, while levelLoopTest returns the value I was looking for.

Am I on the right track?

Not really, as I explained:

Ok, next thing is to check that the storage is being cleared. You can do this by running the game and selecting view > developer tools. From the window that pops up on the right hand side, select Applications, and under storage select Local Storage > file://. There should be a key GDJS_StatsBar.

As you collect the collectables, you should see the value of the GDJS_StatusBar change. If you press x in the game, you should see it clear out.

Does this happen?

Yes, the value clears out. However, when testing, I collected 2 collectibles, cleared out the value, and then collected the third one. Upon doing this, the values showed back up, and instead of being 0, they were all 1.
DeleteDataProblem
It appears that this might be the problem. While the data is clearing out, the data is still stored and referred back to once a collectible is grabbed again. Something is preventing the data from being COMPLETELY wiped clean.

Yeah, it’s because the global variable isn’t clearing out. When you collect the 3rd item, it saves all of collectiblesObtained to storage.

Can you copy the x key pressed event (just highlight the box) and paste the JSON into this thread? I’ll see what’s going when I add it to my project

{“000kind”:“GDEVELOP_EventsAndInstructions_CLIPBOARD_KIND-jsBdHbLy912y8Rc”,“content”:{“eventsList”:[{“disabled”:false,“folded”:false,“type”:“BuiltinCommonInstructions::Standard”,“conditions”:[{“type”:{“inverted”:false,“value”:“KeyReleased”},“parameters”:["",“x”],“subInstructions”:[]}],“actions”:[{“type”:{“inverted”:false,“value”:“DeleteGroupFichier”},“parameters”:["“StatusBar”","“CollectiblesStructure”"],“subInstructions”:[]},{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“levelLoop”,"=",“GlobalVariableChildCount(collectiblesObtained)”],“subInstructions”:[]},{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“levelLoopTest”,"=",“GlobalVariableChildCount(collectiblesObtained)”],“subInstructions”:[]},{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“idLoopTest”,"=",“GlobalVariableChildCount(collectiblesObtained[“level1”])”],“subInstructions”:[]}],“events”:[{“disabled”:false,“folded”:false,“infiniteLoopWarning”:true,“type”:“BuiltinCommonInstructions::While”,“whileConditions”:[{“type”:{“inverted”:false,“value”:“VarGlobal”},“parameters”:[“levelLoop”,">",“0”],“subInstructions”:[]}],“conditions”:[],“actions”:[{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“idLoop”,"=",“GlobalVariableChildCount(collectiblesObtained[“level” + GlobalVariableString(levelLoop)])”],“subInstructions”:[]}],“events”:[{“disabled”:false,“folded”:false,“infiniteLoopWarning”:true,“type”:“BuiltinCommonInstructions::While”,“whileConditions”:[{“type”:{“inverted”:false,“value”:“VarGlobal”},“parameters”:[“idLoop”,">",“0”],“subInstructions”:[]}],“conditions”:[],“actions”:[{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“collectiblesObtained[“level” + GlobalVariableString(levelLoop)][GlobalVariableString(idLoop)]”,"=",“0”],“subInstructions”:[]},{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“idLoop”,"-",“1”],“subInstructions”:[]}],“events”:[]},{“disabled”:false,“folded”:false,“type”:“BuiltinCommonInstructions::Standard”,“conditions”:[],“actions”:[{“type”:{“inverted”:false,“value”:“ModVarGlobal”},“parameters”:[“levelLoop”,"-",“1”],“subInstructions”:[]}],“events”:[]}]}]}],“eventsCount”:1,“actionsList”:[],“actionsCount”:0,“conditionsList”:[],“conditionsCount”:0}}

I added that to my own test project, and it cleared out the variables. So, somewhere else in your events you are repopulating collectiblesObtained. It doesn’t happen by magic. I suspect it’ll all work Ok if you add the Change Scene action back as the last sub-event of the x is pressed event, because I think the scene will reload before the global variable can be repopulated.

However, there’s an incorrect event (or events) that you should investigate and correct.

I did a bit of investigating, and the only other event that I was able to find that declares the collectiblesObtained variable is the event where the player collects a collectible:


Otherwise, none of the other events have actions that redeclare the variable.