melonjs

Confused on prototype bindings, this statement

时光总嘲笑我的痴心妄想 提交于 2019-12-23 20:33:00
问题 In the following code, I'm wondering how context is bound to this : In obj.myMethod(); , context is given to the object. So logging it gives the object. In var myFun = obj.myMethod; then myFun(); , context is given to the Window. The only difference is you're setting the function to a variable. var obj = { myMethod : function () { console.log(this); //'this' is bound to context of object } }; obj.myMethod(); //calling object property directly = Object {myMethod: function} var myFun = obj

RPG - storing player data for semi-complex tree structure

点点圈 提交于 2019-12-23 08:33:12
问题 I'm making a web RPG in js, using melon JS and SQL DB with PHP. This question is about how to store completed and current tasks per non-player character (NPC). NPC dialog and task data: all dialog is stored in a js object in the following structure: var dialog = { quests : { quest1 : { NPCName ("Joe"): { TaskName ("1 - Introductions") : { "english" : [ "Hello, here is some dialog", "More dialog..." (stored in array so I can cycle through it) ],//more items per task }, //more tasks per NPC },