bexphones

Members
  • Content count

    16
  • Joined

  • Last visited

  1. Waouh love the way you that you explain !
  2. I did not know that we could write this like that ? args.forEach(fn => fn(data[i])) fn > reserved word for function... Yet one thing more learned thank you.
  3. [WIP][Phaser] Color Stars

    a question ? Would not it be even more fun if the speed was higher from the start...
  4. maybe yet a question how do you do to perform that ? function foreach(tableau,action){ for(var i=0;i<tableau.length;i++){ action(tableau[i]); } } const actions = console.log(this.name) && console.log(this.number) foreach(dalle,actions) and this also ? function test_args(arg1,arg2){ console.log(arg1) console.log(arg2) } test_args("koala","cat") //koala, cat test args("koala") //return only koala without errors
  5. i start with lua langage + after i learn javascript ++ and now définitively i love FP +++
  6. //WHY THIS NOT WORKS ? function hide_enemies(obj,action){ obj.forEach(function(item){ return item.action() }) } //WHY THIS WORKS ? function hide_enemies(obj){ obj.forEach(function(item){ return item.hide() }) } hi again could you explain why it doesn't work for the example 1 ? how must i declare "action" ? if i run hide_enemies(dalle,hide) it return the error item.action is not a function. for obj exist you have true, it's not necessary to invoke him, hide_enemies() works without because we make foreach. Thanks. PS : i'm not yet ready for this : const hide_enemies = (enemies, actionString) => enemies.forEach( (enemy) => enemy[actionString]() ); because i need to console.log sometimes what went wrong and in this case it's difficult.
  7. hi, thanks very much for these explanations. your quick guide for array is easy to understand , thanks again i use an array to stock my objects. var enemy={} next i create the enemy i need for each levels with a prototype and methods. enemy[0]=new _proto_enemy() each level have different number of enemies. level 1 have for example 2 enemies and level2 > 4, etc.... i check if enemy exist in an update method to each levels to apply method on hem like collisions with another object (player), add in the game(game.add.existing(enemy[0]), debug hem. finally to loop trough and apply also method but with other object or methods.
  8. functional programmation error ....

    Ha ok thank you.
  9. hi, i'm happy to play now with short code and modularize them together. What saves time and readability ! But in this case i don't see what it's possible to do with the function foreach. Is it possible to use foreach like this config with a trick in the hide_weapon_internal ? //normal function who works if(dalle_moving[0]){ for (var j = 0; j < dalle_moving.length; j++){ dalle_moving[j].hide() } } //////////////////////////////////////////////////////////////////////////////////// //NOW WITH FUNCTIONAL PROGRAMATION function is_exist(obj){ if(typeof obj != "undefined"){ return true; }else{ return false; } } function foreach(table,action){ for(var i=0;i<table.length;i++){ action(table[i]); } } ////////////////////////////////////////// var hide_enemy=function(obj){ is_exist(obj[0]) && foreach(obj,obj.hide) } hide_enemy(dalle_moving) ////////////////////////////////////////// //obj.hide don't works because i must say action(obj[i].hide()) //is there a trick to do that with the function foreach as she is ? i have the feeling that 's possible ....no?
  10. readable arguments

    Thanks samme and sorry for this delay so now with this technique i could do var config=[arg1,arg2,...] var robots= new Robot(config) i must learn ES6 !
  11. functional programmation error ....

    Wouaw fantastic these links ! i read it quicly and it give me the need to print these to read hem carefully. Thanks a lot. maybe a stupid question, i read in a lot of articles that we need as much as possible use var when we declare a function. however i see that you not. why? what's the reason ? and just to understand and not to bother you :
  12. functional programmation error ....

    this don't work : const add = list => item => list.push(item) var liste=[100,200] var ajout=85 add(liste,ajout) console.log(liste) //100,200 //here it's ok function added (list, item) { list.push(item) // return list // return item } added(liste,ajout) console.log(liste) //100,200,85 but this ok:
  13. functional programmation error ....

    Hi, thanks for these explanation. I'm not confortable with const value. Why do you use this ? On the mozilla documentation i understand not yet very well the benefit of this use. i see that your example is a currying function, no? what is true is that i begin to feel the benefits of the FP, it's cool :). I was scared to always jump between little code to read and understand my code, but it's not the case. Your solution works : var logic_add_intenal=function(obj){ if(obj[0]){ foreach(obj,game.add.existing.bind(game)) } } logic_add_intenal(dalle) i go to the phaser.js to understand and i understand nothing In any case not enough to solve my question myself ! have you good reference to learning FP if never ?
  14. functional programmation error ....

    hi mattstyles Thanks, but always seems to be the same between the 2 functions....honestly i don't see the error. ps: You say that you rarely refer to this, how do you do to work without him ? in my example how do you do to avoid that ...it's interesting for me to learn. Are you working with prototypes ? var co=console.log function foreach(tableau,action){ for(var i=0;i<tableau.length;i++){ action(tableau[i]); } } if(dalle[0]){ for (var i = 0; i < dalle.length; i++){ co("dalle",dalle[i]) co("dalle_game",game) co("dalle_this",this) game.add.existing(dalle[i]) } } var logic_add_intenal=function(obj){ if(obj[0]){ foreach(obj,co) co("obj_game",game) co("dalle_obj",window) foreach(obj,game.add.existing) } } //result : dalle Object { name: "dalle", number: 0, image_body: "dalle", image_drag: "sprite_for_drag", posx: 640, posy: 840, flag: true, type: 0, physicsType: 0, position: Object, 52 de plus… } main.js:1785:5 dalle_game Object { id: 0, config: Object, physicsConfig: undefined, parent: "game", width: 1280, height: 1920, resolution: 1, _width: 1280, _height: 1920, transparent: false, 52 de plus… } main.js:1786:5 Object { name: "dalle", number: 0, image_body: "dalle", image_drag: "sprite_for_drag", posx: 640, posy: 840, flag: true, type: 0, physicsType: 0, position: Object, 53 de plus… } util.js:21:3 obj_game Object { id: 0, config: Object, physicsConfig: undefined, parent: "game", width: 1280, height: 1920, resolution: 1, _width: 1280, _height: 1920, transparent: false, 52 de plus… } main.js:1793:5 TypeError: this.world is undefined[En savoir plus]
  15. functional programmation error ....

    hi, i would use functional programmation but in this case i don't know why it doesn't work. in first comment code, this works but below and exactly the same it doesn't work..why ? //if(canon[0]){ // //for (var i = 0; i < canon.length; i++){ // //game.add.existing(canon[i]) // //} //} function foreach(tableau,action){ for(var i=0;i<tableau.length;i++){ action(tableau[i]); } } var logic_add_intenal=function(obj){ if(obj[0]){ foreach(obj,game.add.existing) } } logic_add_intenal(canon) // error is TypeError: this.world is undefined