Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by dahl

So no errors when i run it from localhost, but it just sits there "dead" does not seem to play at all. Anything you folks can see that i'm missing would be great, thanks!
ig.module (
    'game.main'
)
.requires (
    'impact.game',
    'impact.font',
    'game.entities.redskull',
    'game.entities.blueskull',
    'game.entities.purpleskull',
    'game.entities.greenskull',
    'game.entities.orangeskull',
    'game.entities.yellowskull',
    
    'game.levels.main'
)
.defines (function() {
MyGame = ig.Game.extend ( {
    playing: 'true',
    count: '0',
    seqnum: '0',
    sequence: [],
    hardmode: 'false',
    
    
init: function() {
    this.playing = 'true',
    this.count = '0',
    this.seqnum = '0',
    this.sequence = [],
    this.hardmode = 'false',
    
    this.loadLevel ( LevelMain );
    
    function spin_it(n) {
        if(n==1) {
            ig.game.EntityRedskull.anims.spin;
        } else
        if(n==2) {
            ig.game.EntityYellowskull.anims.spin;
        } else
        if(n==3) {
            ig.game.EntityBlueskull.anims.spin;
        } else
        if(n==4) {
            ig.game.EntityOrangeskull.anims.spin;
        } else
        if(n==5) {
            ig.game.EntityPurpleskull.anims.spin;
        } else
        if(n==6) {
            ig.game.EntityGreenskull.anims.spin;
        }
    };
    
    function rng() {            //random number generator
        Math.floor(Math.random()*6+1);
        return;
        }
    function set_up() {             //sets up the game
        count = 0;
        seqnum = 0;
        playing = 'true';
        // create the sequence
        for(var s = 0; s<500; s++) {
            sequence[s] = rng();
            }
        }
    function begin() {
        count = 0;
        playing = 'true';
        // AI
        for(var s = 0; s<=seqnum; s++) {
            setTimeout("spin_it("+ sequence[s] +")", s*interval);
        }
    }
},

update: function() {		
			
		// Update all entities and BackgroundMaps
		this.parent();
	},
	
draw: function() {
		// Draw all entities and BackgroundMaps
		this.parent();
		
	}
});

    ig.main('#canvas', MyGame, 60, 160, 240, 2);

});

I set 'playing' to true throughout so that it would start up, but it's just not. thanks.

1 decade ago by fugufish

i lost sight of the code. try using console.log() in each section of the code, and try to narrow it down to where the problem is. Important is to understand the flow of events, and spot the bottleneck. Takes some time, but once you know it, you'll never repeat it again.

1 decade ago by dahl

Ok, so i got my declarations moved around and it got the process moving a bit, but now i'm getting.... "sequence[s] = rng();" 'sequence is not defined'. in the following code, it is where the Array is to be filled with the pattern that is to be checked against...(firefox, firebug)
ig.module (
    'game.main'
)
.requires (
    'impact.game',
    'impact.font',
    'game.entities.redskull',
    'game.entities.blueskull',
    'game.entities.purpleskull',
    'game.entities.greenskull',
    'game.entities.orangeskull',
    'game.entities.yellowskull',
    
    'game.levels.main'
)
.defines (function() { 
MyGame = ig.Game.extend ( {
    playing:  'true',
    count: '0',
    seqnum: '0',
    hardmode: 'false',
    sequence: new Array(),
    spinIt: function(n) {  
        if(n==1) {
            ig.game.EntityRedskull.anims.spin;
        } else
        if(n==2) {
            ig.game.EntityYellowskull.anims.spin;
        } else
        if(n==3) {
            ig.game.EntityBlueskull.anims.spin;
        } else
        if(n==4) {
            ig.game.EntityOrangeskull.anims.spin;
        } else
        if(n==5) {
            ig.game.EntityPurpleskull.anims.spin;
        } else
        if(n==6) {
            ig.game.EntityGreenskull.anims.spin;
        }
    },
    
    rng: function() {          //random number generator
        Math.floor(Math.random()*6+1);
        return;
        },
    setUp: function() {             //sets up the game
        count = 0;
        seqnum = 0;
        playing = 'true';
        // create the sequence
        for(var s = 0; s<150; s++) {
            sequence[s] = rng();
            }
        },
    begin: function() {
        count = 0;
        playing = 'true';
        // AI
        for(var s = 0; s<=seqnum; s++) {
            setTimeout("spin_it("+ sequence(s) +")", s*interval);
        }
    },
    
    
init: function() {
	
    this.setUp();
    this.begin();
    
    this.playing = 'true',
    this.count = '0',
    this.seqnum = '0',
    this.sequence = [],
    this.hardmode = 'false',
        
    this.loadLevel ( LevelMain );
    
    this.parent();
},

update: function() {		
			
		// Update all entities and BackgroundMaps
		this.parent();
	},
	
draw: function() {
		// Draw all entities and BackgroundMaps
		this.parent();
		
	}
});

    ig.main('#canvas', MyGame, 60, 160, 240, 2);

});

anyway, thanks for any help you can give it would be great!

1 decade ago by MikeL

Looks like you are forgetting to add this. in many places, e.g.
for(var s = 0; s<150; s++) {
            sequence[s] = rng();
            }
        },

should be
for(var s = 0; s<150; s++) {
            this.sequence[s] = this.rng();
            }
        },

Keep in mind that any variable or function which belongs to a class, must be preceded with this.. If a variable is local to a function (as in s in your loop above), then it can stand alone.

I see some other places where that may be a problem as with count used in the begin function and so forth.

On another note, when you declare class variables outside of init() (as in count and seqnum), you do not need this. However by using the single quotes you are creating strings. You should redo that part as in:
    playing:  true,
    count: 0,
    seqnum: 0,
    hardmode: false,

Now you have 2 booleans and 2 integers. If you declare these variables as you have , then there is no need to declare them again within your init() function (unless of course you want to for some specific reason).

Hopefully that helps some :)

1 decade ago by dahl

thanks Mr. L! that was great. now the only prob i'm having is with .....
 for(var s = 0; s<=this.seqnum; s++) {
            setTimeout('this.spinIt(this.sequence[s])', s*this.interval);
	}

's' is a local variable, so it is defined in the first line, no? i'm getting an error that states that 's' is not defined. it is written exactly the same as the setUp() and that one throws no error. not quite sure what i screwed up there.

thanks again for the above help.

1 decade ago by dominic

The string you put in the setTimeout() call will be executed in another context, long after your local s variable is gone and the this doesn&039;t point to your class anymore. Try to use <1> instead of #setTimeout().

1 decade ago by MikeL

Ah very good Dominic. I thought it was something to do with the setTimeout(), but wasn't sure.

By the way dahl, Impact timers are one of the unsung killer features of Impact in my opinion. I use them all over the place. For a more detailed description of timers also see this thread.

1 decade ago by dahl

Yep guys it was that silly timer. i'm working on one atm with impacts timers, but i'm getting an error in a for loop, that makes no sense to me...
aITurn: function() {
	this.seqnum = (this.seqnum + 1);
	for(i = 0; i <= this.seqnum; i++) {
		var seq = this.sequence[i];

firebug is giving me a warning 'assignment to undeclared variable i'. i know it's just a warning, but the game populates, but does not play. any ideas?
thanks.

edit: shakes head i found it, silly mistake. thanks for all your help guys, you've been great!
Page 1 of 1
« first « previous next › last »