Error on save & load function. Bug?

Get help using Construct 2

Post » Mon May 15, 2017 8:44 pm

Hey there! So i am trying to add a save and load function, but i keep getting the same error no matter what.
I do not use any plugins or anything like that.

Error says;

Javascript error!
Uncaught TypeError: Cannot read property 'ApplyLinearImpulse' of null
http://localhost50000/Physics_Behaviour.js, line 2223 (col12)

This may be a bug in Construct 2 or a third party plugin or behaviour -
please report it to the developer following the bug report guidelines.

EDIT; It happens always when the player is in a different layout than the layout the game was saved in.
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Mon May 15, 2017 10:53 pm

We will definitely need your project .capx or at least a shortened version of it to reproduce the possible bug and to help you with this.

I am positive though that it is no bug and just a line of code that needs to be changed.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue May 16, 2017 1:53 pm

randomly wrote:We will definitely need your project .capx or at least a shortened version of it to reproduce the possible bug and to help you with this.

I am positive though that it is no bug and just a line of code that needs to be changed.


Unfortunately i can not give u any type of version of this as the scale is way too large and the game almost done.
Is there no other way to find out what the problem is?
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Tue May 16, 2017 2:33 pm

Seems to be working now when i deleted the physics impulse.
Code is;


'X on created, - apply physics impulse 10 at angle 270 + (15-random30)) at image point 0'

Why would this crash the game? And how to fix this code?
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Tue May 16, 2017 2:57 pm

Greaver wrote:Cannot read property 'ApplyLinearImpulse' of null


Judging from this, it sounds like the action is trying to apply an Impulse on an object that doesn't exist.
Since you said that the error occurs when you are in a different layout than the one the game saved before:
  1. Can the object that you are applying the impulse to be destroyed?
  2. What kind of object is it that you are applying the impulse to?
  3. What physics type are you using? Did you try to change it? (Project properties -> asm.js/web

Can you also try to put a "Wait dt seconds" before you apply the impulse?

If all this doesn't help, you can try to save the object's status' in an Array and save the Array as JSON in LocalStorage.
This will, of course, be a very tedious thing to do, but if it's the last option, you might wanna do this instead of leaving the error in your game.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue May 16, 2017 5:03 pm

randomly wrote:
Greaver wrote:Cannot read property 'ApplyLinearImpulse' of null


Judging from this, it sounds like the action is trying to apply an Impulse on an object that doesn't exist.
Since you said that the error occurs when you are in a different layout than the one the game saved before:
  1. Can the object that you are applying the impulse to be destroyed?
  2. What kind of object is it that you are applying the impulse to?
  3. What physics type are you using? Did you try to change it? (Project properties -> asm.js/web

Can you also try to put a "Wait dt seconds" before you apply the impulse?

If all this doesn't help, you can try to save the object's status' in an Array and save the Array as JSON in LocalStorage.
This will, of course, be a very tedious thing to do, but if it's the last option, you might wanna do this instead of leaving the error in your game.


Hey there! Thanks for ur time, appreciated! Adding DT worked and the problem is solved.

The impulse was on a ''floating'' text message with a destroy on fade. No idea what caused the error. I tried changing physics but it did not help.
However adding a DT time worked, same goes for ''wait 0.1 second''.

Thank you for your kind reply ^_^
-All the best!
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Tue May 16, 2017 5:56 pm

You could also use Wait 0 seconds, should have the same result.

If you're interested in the reason why this action might be needed in some cases:
When an object is created, it sometimes needs a frame to "prepare itself".
During that time, you can set e.g. parameters or coordinates, but the object isn't interactive yet, thus can't be affected by other plugins/behaviors.

To give an example, the Text object expression Text.TextHeight doesn't return the correct height in the same frame as setting the text.
This means, when you change the text and put an action underneath that, calling the .TextHeight expression, it will not return the correct number.
But if you put a Wait dt seconds in between, it will work.

So, if you have an issue like this again, where an object just doesn't seem to react or an object expression doesn't return what it should, you might wanna wait a frame.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests