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 Aquen

Hi guys,

I have a little bug in my level transitioning:

I tried to build the trigger box for the level transitioning in my game which looks like this:

ig.module(
        'game.entities.levelexit'
)
.requires(
        'plugins.box2d.entity'
)
.defines(function(){ 
        EntityLevelexit = ig.Entity.extend({
                
                _wmDrawBox: true,
                _wmBoxColor: 'rgba(0, 0, 255, 0.7)',
                _wmScalable: true,       
                size: {x: 8, y: 8},
                level: null,
                checkAgainst: ig.Entitiy.TYPE.A,
              
                update: function(){},
                check: function( other ){
                  if(other instanceof EntityPlayer){
                  if (this.level) {
                        var levelName = this.level.replace(/^(Level)?(\w)(\w*)/, function( m, l, a, b){
                          return a.toUpperCase() + b;                                 
                        });
                        ig.game.loadLevelDeferred( ig.global['Level'+levelName]);
                  }
                  }
                }
        });
});

When I try to open the weltmeister or the game I get the following error:

Unhandled Error: Cannot convert 'ig.Entity' to object.

My game is a jumpnrun based on Johncoms modified Box2D Plugin.
Can anyone help?

1 decade ago by Joncom

On what line number, and in what file does the error occur?

1 decade ago by Aquen

The error occurs in the file I posted above. The levelexit.js
It occurs in this line:

EntityLevelexit = ig.Entity.extend({

1 decade ago by Joncom

The error message seems to be saying that ig.Entity is undefined. Can you confirm this? Add in this line to check:

.defines(function(){ 
    console.log(ig.Entity); // <-- Add this line.
    EntityLevelexit = ig.Entity.extend({
        // ...        

And then observe in your console what is being printed. Does it print undefined? Does it print something else?

1 decade ago by Aquen

Hmm why should it be undefined? I mean, in the other files I also have the ig.Entity extend line and it works.

That's what the console spills out after inserting the line:

[url=http://www.servimg.com/image_preview.php?i=893&u=12389801][img]http://i56.servimg.com/u/f56/12/38/98/01/unbena10.png[/img][/url]

[url=http://www.servimg.com/image_preview.php?i=894&u=12389801][img]http://i56.servimg.com/u/f56/12/38/98/01/unbena11.png[/img][/url]

1 decade ago by Aquen

Ok the picture is very small:

Console Output

levelexit.js:10
function Class() {
		if( !initializing ) {
			
			// If this class has a staticInstantiate method, invoke it
			// and check if we got something back. If not, the normal
			// constructor (init) is called.
			if( this.staticInstantiate ) {
				var obj = this.staticInstantiate.apply(this, arguments);
				if( obj ) {
					return obj;
				}
			}
			for( var p in this ) {
				if( typeof(this[p]) == 'object' ) {
					this[p] = ig.copy(this[p]); // deep copy!
				}
			}
			if( this.init ) {
				this.init.apply(this, arguments);
			}
		}
		return this;
	}

1 decade ago by Joncom

I&039;m not sure what's wrong. Want to upload your game somewhere again and I could take a look? Just make sure you don't include the #/lib/impact/ folder.

1 decade ago by Aquen

Ok here is the download link(without the impactjs lib):

http://www.file-upload.net/download-8147488/Spiel.zip.html

1 decade ago by Joncom

1. I found trigger.js in the root folder. According to your code, it belongs in the /lib/game/entities/ folder instead. Move it there.

2. Your game also looks for a file called levelchange.js, but it doesn&039;t appear to exist anywhere in the zip you provided. Do you mean to load #levelexit.js instead?

1 decade ago by Aquen

1. this was because in the previous version I tried the level transitioning with a trigger.js and a levelchange.js, but it didn't work. That's why I tried it with the levelexit.

I changed it back to the old version now, which looks like this:



ig.module(
        'game.entities.levelchange'
)
.requires(
        'impact.entity'
)
.defines(function(){ 
        console.log(ig.Entity);
       EntityLevelchange = ig.Entity.extend({
_wmDrawBox: true,
_wmBoxColor: 'rgba(0, 0, 255, 0.7)',
_wmScalable: true,
size: {x: 8, y: 8},
level: null,
triggeredBy: function( entity, trigger ) {
if(this.level) { 
varlevelName = this.level.replace
(/^(Level)?(\w)(\w*)/, function( m, l, a, b ) {
return a.toUpperCase() + b;
});
var oldplayer = ig.game.getEntitiesByType( EntityPlayer )[0];
ig.game.loadLevel( ig.global['Level'+levelName] );
var newplayer = ig.game.getEntitiesByType( EntityPlayer )[0];

newplayer = oldplayer;
}
},
update: function(){}
});
});

Now the game loads, and also the weltmeister but the old problem remains:

When my character touches the triggerentitiy nothing happens.
I made a trigger and a levelchange entity in the weltmeister, and connected them.

Here ist the download link of the old version:
http://www.file-upload.net/download-8152551/Spiel.zip.html

1 decade ago by Joncom

So the error:
Unhandled Error: Cannot convert 'ig.Entity' to object.
is gone?

Maybe add a console.log call to your trigger to verify it's being activated (even if the level change is not working)...

1 decade ago by Aquen

Yeah the other error is gone.

When I add the log line to my trigger.js the console tells me the following:

function Class() {
		if( !initializing ) {
			
			// If this class has a staticInstantiate method, invoke it
			// and check if we got something back. If not, the normal
			// constructor (init) is called.
			if( this.staticInstantiate ) {
				var obj = this.staticInstantiate.apply(this, arguments);
				if( obj ) {
					return obj;
				}
			}
			for( var p in this ) {
				if( typeof(this[p]) == 'object' ) {
					this[p] = ig.copy(this[p]); // deep copy!
				}
			}
			if( this.init ) {
				this.init.apply(this, arguments);
			}
		}
		return this;
	}

1 decade ago by Joncom

Quote from Aquen
When I add the log line to my trigger.js the console tells me the following...
I did not mean to use the same console.log as before. Because we don&039;t actually care about #ig.Entity anymore...

We're trying to isolate where the problem is:

I meant, add something like console.log("Triggered!") to the part of your trigger where an event is supposed to happen, so that you can see if the trigger is broken, or if the levelchange entity is broken.

If you see "Triggered!" in your console, it will mean your trigger is working fine and your levelchange entity is failing. If you don't see the message, then likely there is something wrong with the trigger.

1 decade ago by Aquen

Oh sorry my mistake... :-)

Ok I added the log at differen lines to check various things:
1. In the init function to see, if it get's initialized correctly
--> Works

2. In the check function, to see if this works right.
--> Does not work

3. Just to be safe in the update function:
--> Works


So it seems the check function is not going to be called?
Why that?

1 decade ago by Joncom

Make sure you have this.parent() in your update function.

1 decade ago by Aquen

I had the this.parent(); in the trigger.js but forgot it in the levelchange.js . Also I
wrote varlevelName instead of var levelName.

It works now. :-)

Thanks again for your help!
Page 1 of 1
« first « previous next › last »