Bug in solar2d ?

Hi,
I read that : “Development is lead by Vlad Shcherban” so if he sees this message, I think there is a bug somewhere that is not in my code. (important : if you try the code, just swipe a square to the right, the other directions are not written yet)
I created a basic match-4 game, and a function like “animSquaresToGoDown()” is called in a gameloop if a boolean is true. The squares go down, then another function creates new squares at the top, etc.
It works fine for at least 50 times, but at one point, the other function that creates new squares is called without being actually called. There is only one way to call this function and it is with a boolean to “true” in the gameloop. I added a “print” whenever I put this boolean to “true”, and it always prints “false”.

So my guess would be that the function is somewhere registered in a list, and for some reason, it gets called when it’s not supposed to.

Here is the github if you want to try : GitHub - Orx5/foret: meilleur code, avec perso et id dans meme tableau
The interesting part starts at 344 : gererChercherCasesADescendre() (in english : “findSquaresToGoDown”)
and it set goFaireDescendre = true (in english : “goDown = true”)

then line 553 :
animPersosVersCasesVides() (in english : “animCharactersToEmptySquares”)
should never be called before line 628 :

function gererGameLoopAnimVersCasesVides()
    if ( goVersCasesVides == true ) then
        animPersosVersCasesVides()
    end
end

and “goVersCasesVides” is “false” when it gets called.

It happens 1 out of at least 50 times.

I’m 99.99999% sure that this is an error in your code. Let’s round it up and make it a 100%.

You may not be properly handling and removing the functions, but this issue is definitely in your code.

yes, I wish :slight_smile:
would you have a look at the code, if it’s not too strange to read and not too time consuming?

You are using global variables, so that may be contributing to the issue here. You are also running your game loop via a timer that is never cancelled, so there’s that as well.

I can’t really give much more help as I don’t have the time to familiarise myself with code that’s written in French. But, after having taken a quick look at your code, I’d say we can safely rule out the possibility that this is caused by a bug in Solar2D.

Here’s a quick excerpt from the docs:

Beginners have a tendency to blame the compiler, the library, or anything other than their own code. Experienced programmers would love to do the same, but they know that, realistically, most problems are their own fault.
Solar2D Documentation — Developer Guides | Basics

A fair bit of programming is about rewriting existing code and figuring out bugs, and this happens to novices and experienced developers alike.

1 Like

Why are you fiddling around with goVersCasesVides true/false? Why not just have animPersosVersCasesVides() fire on line 513?

You’d have to declare animPersosVersCasesVides above genererPersosDansLaScene:
local animPersosVersCasesVides
Then, when you actually write the function, instead of starting it
function animPersosVersCasesVides(), you’d need to write it
animPersosVersCasesVides = function()

1 Like

Because I need the timer to repeat the function, otherwise, it just repeats itself : the goal of the function is to add “+ speed” to the “y” of each square in my “tab” table.

So I changed the timer, 2 timers instead of 1, and I cancel them, and so far so good… I think it works.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.