espace Posted June 15, 2018 Share Posted June 15, 2018 hi, i don't understand why my function f.lock don't works. the first parameter (flag) is not recognized. have you an advice about that ? thanks : f.test_game_over = () => { if (o.paper[0].flag && o.paper[1].flag) { console.log("game_over") //game over for all } } f.check_deep = (obj) => { if (f.checkOverlap(obj, o.sensor)) { //DONT works the first parameter is not obj.flag ...why ? f.lock(obj.flag, f.test_game_over) //THIS WORKS BUT FOR ME IT's THE SAME ? //if (obj.flag == false) { // obj.flag = true // f.test_game_over() //} } } f.lock = (flag, callback) => { if (flag == false) { flag = true; } callback(); } Quote Link to comment Share on other sites More sharing options...
losthope Posted June 15, 2018 Share Posted June 15, 2018 flag is passed by value, flag = true is useless pass obj and check/assign to obj.flag espace 1 Quote Link to comment Share on other sites More sharing options...
espace Posted June 15, 2018 Author Share Posted June 15, 2018 f.test_game_over = () => { if (o.paper[0].flag && o.paper[1].flag) { console.log("game_over") //game over for all } } f.check_deep = (obj) => { if (f.checkOverlap(obj, o.sensor)) { f.lock(obj, f.test_game_over) } } f.lock = (obj, callback) => { if (obj.flag == false) { obj.flag = true; callback(); } } ok thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.