[Vala] Closure inside a closure and variable access



This is probably a no brainer but thought it was worth posting.

        state.on_score = () => {
            // Reset the ball
            ball.reset_location (engine);
            ball.pause ();

            var c = new Circle();
            c.x = engine.width / 2;
            c.y = engine.height / 2;
            c.radius = 34.00;
            engine.sprites.add (c);

            engine.add_timer(() => {
                ball.unpause ();
                engine.sprites.remove (c); //<-- CRASH
            }, 3000);
        };


In Vala is it correct to assume that anything defined inside an
anonymous function is not accessible anywhere else, even inside
another anonymous function that's inside itself? For now I ended up
moving the object "c" outside of them both and access was fine. I also
tried tossing around owned and unowned but same results. Is there
maybe a flag I can use to catch this sort of issue?

-- 
Joseph Montanez
Web Developer
Gorilla3D
Design, Develop, Deploy



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]