Colon

Members
  • Content Count

    7
  • Joined

  • Last visited

  1. Hi, I am trying to organize my game, and try to collect some functions in an extra file so I dont need to rewrite them in every state. I am trying to convert this: world.js update: function() { this.game.physics.arcade.overlap(this.player, this.items, this.collect, null, this); } collect: function(player, collectable) { console.log('melon'); collectable.destroy(); }, to this: world.js update: function() { this.game.physics.arcade.overlap(this.player, this.items, collect(this.player, this.items), null, this); } functions.js function collect(player, collectable) { console.log('melon'); collectable.destroy(); } So what happens when I run my game with that is that the collect function is in an infinite loop, even if I dont overlap the item. Can you tell my why it is doing that and how I can fix that? Thanks, Colon
  2. Colon

    create: function() => unexpected token :

    ok so basically, my project is about dialogs with npcs. I have for example a json file, generated with basic information about a npc: job, where/when he/she was born, name, how he/she looks. The plan is that I can walk over to that npc, and have a dialog with them. I can ask the npc suggested questions and he will answer properly. So my idea was to use that plugin, because it looks usefull and a bit like what I am planing to do. But maybe I should just try to write my own one and down't spend anymore time on that plugin to get it running and trying to convert then.
  3. Colon

    create: function() => unexpected token :

    Yes it maybe is.... I checked the actual plugin due to the Conv.play(), and I adressed it wrong, its (id, type) not (type, id) as it says in the example. And I have a new error now (Cannot read property '0' of undefined). Just running from one error to another. Not sure right now if I will get that script running some time. Thanks so much for you help so far, not sure what I should do with it. Do you got that plugin running?
  4. Colon

    create: function() => unexpected token :

    Thanks, the book is good. I read the first 100 pages about the states and it helped me alot. I am still not sure where and how I should use the exmaple code. The example code is an own state I think, but the stateManager does not find it, because of the (function(){ 'use strict' ... If I delete the (function(){ 'use strict' ... the state is found. What can I do that the stateManager finds that state, even if I am using (function(){ 'use strict' ... ? If I dont use it, stateManager finds the state, but it gives me an error that the Conv.play() is not a function. 1: Line 3&4 , what I think, is that this means, that the following method or state? in the brackets uses strict, which helps to throw more exceptions. (function() { 'use strict'; .... and 2: Line 6-8 if we look at my preloader.js and the example, var state is equal to my Game.preloader. What is the difference between function state(game) and function (game) var state = function state(game) {}; state.prototype = { ... and pretty sure that Line 48 will give me a problem too window.MyGame.states.MyState = state; Here is my code so far: index.html <!doctype html> <html> <head> <meta charset="UTF-8"/> <title>2DWorld</title> <script src="scripts/phaser.min.js" type="text/javascript"></script> <script src="states/preloader.js" type="text/javascript"></script> <script src="states/app.js" type="text/javascript"></script> <script src="states/dialog.js" type="text/javascript"></script> <script src="scripts/lodash.min.js" type="text/javascript"></script> <script src="scripts/phreaknation.manager.dialog.min.js" type="text/javascript"></script> <script src="scripts/require.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> var game = new Phaser.Game(800, 600); game.state.add("Preloader", Game.preloader); game.state.add("Dialog", Game.dialog); // game.state.add("App", Game.app); game.state.start("Preloader", false); </script> </body> </html> preloader.js var Game = {}; var manDiag; var config; Game.preloader = function (game) {}; Game.preloader.prototype = { init: function(){ }, preload: function(){ console.log("preloader, preloaded"); }, create: function(){ game.plugins.add(PhreakNation.Plugins.DialogManager); // manDiag = this.game.plugins.add(PhreakNation.Plugins.DialogManager); config = require (['scripts/config.js']); // manDiag.load(config); this.state.start("Dialog"); }, }; dialog.js (function() { 'use strict'; Game.dialog = function state(game) {}; Game.dialog.prototype = { create: function () { manDiag = this.game.plugins.add(PhreakNation.Plugins.DialogManager); manDiag.load(config); var Conv = manDiag.get('dialog', 1); Conv.play(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); var list = Conv.answers(); var choice = _.random(0, 2); console.log('Options: ', list); console.log('Chose: `%s`', list[choice]); Conv.choose(choice); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); list = Conv.answers(); choice = _.random(0, 2); console.log('Options: ', list); console.log('Chose: `%s`', list[choice]); Conv.choose(_.random(0, 1)); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); } } } // window.MyGame.states.MyState = state; ) Thanks, Colon
  5. Colon

    create: function() => unexpected token :

    1.No I didn't solve it yet. I can't get it running. 2.Maybe, I am not sure, at least I have an index.html now an my example in a .js file. It doesn't give me any errors but it doesn't go thru the create:function() Working on it for many hours now, but no success. And also in the config.js was that line which gave me an error: modulee.exports = { .... The "modulee" gives me the error. Gives me no more error with "module" thats ok, an easy fix but that means it was never tested? I am just confused. var config = require(['config2.js']); console.log("%cDialog", "color:white; background:red"); var manDiag; (function() { 'use strict'; var state = function state(game) {}; console.log("%cstate", "color:white; background:red"); state.prototype = { create: function () { console.log("%cCreate:", "color:white; background:red"); manDiag = this.game.plugins.add(PhreakNation.Plugins.DialogManager); manDiag.load(config); var Conv = manDiag.get('dialog', 1); Conv.play(); console.log("%cStarting my awesome gme", "color:white; background:red"); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); var list = Conv.answers(); var choice = _.random(0, 2); console.log('Options: ', list); console.log('Chose: `%s`', list[choice]); Conv.choose(choice); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); list = Conv.answers(); choice = _.random(0, 2); console.log('Options: ', list); console.log('Chose: `%s`', list[choice]); Conv.choose(_.random(0, 1)); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); } }; // window.MyGame.states.MyState = state; })(); Thanks
  6. Hey I am trying to get a plugin running, the Dialog Manager Plugin It gave me already a few problems like require.js but I think I solved them. But now the create: function() gives me a problem. It says "Uncaught SyntaxError: Unexpected token :" I found a good explanation about the differences of function create() vs create: function() But I am not realy sure what to do with the code to get it running. Kind of new to phaser. I think there will be an easy solution for it but I don't see it and can't find very much about it. This is my code so far. Maybe you can help me with that. Thanks! I am using phaser 2 of course <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>DiaTester</title> <script src="plugin/phaser.js"></script> <script src="//cdn.jsdelivr.net/phaser/2.2.2/phaser.min.js"></script> <script src="plugin/lodash.min.js"></script> <script src="plugin/phreaknation.manager.dialog.min.js"></script> <script src="plugin/require.js" "></script> <style type="text/css"> body { margin: 0; } </style> </head> <body> <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload(){ }; function create(){ game.plugins.add(PhreakNation.Plugins.DialogManager); }; function update(){ }; var config = require(['plugin/config2.js']); var manDiag; (function() { 'use strict'; var state = function state(game) {}; state.prototype = { ... create: function () { ... manDiag = this.game.plugins.add(PhreakNation.Plugins.DialogManager); manDiag.load(config); var Conv = manDiag.get('dialog', 1); Conv.play(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); var list = Conv.answers(); var choice = _.random(0, 2); console.log('Options: ', list); console.log('Chose: `%s`', list[choice]); Conv.choose(choice); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); list = Conv.answers(); choice = _.random(0, 2); console.log('Options: ', list); console.log('Chose: `%s`', list[choice]); Conv.choose(_.random(0, 1)); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); Conv.next(); console.log('[%s]: %s', Conv.actor().name(), Conv.text()); } ... }, ... }; window.MyGame.states.MyState = state; })(); </script> </body> </html>