So, question in header… i was loaded a javascript filter from somebody on forum, in his example he make 2 boxes, passing through each other, but if i paste it in my game and change the Objects to mine - its crashing the game. Please help me.
The collision filter example can crash in several ways, I didn’t think about every possible exception, I will list here the errors I can think of now:
- You don’t pass the object in the event (in the bottom of the script event editor window, you have to pass the object).
- There must be at least one object, in the example I use ‘objects[0]’ it takes the first object in the list, if the previous conditions leave the count of considered objects to 0 the script will crash (there is not ‘objects[0]’ since ‘objects’ is empty). The code will set the filter for just one object too! So you should replace it with a “for each” loop, this way (with this loop you can pass an empty objects list):
for(var i = 0;i<objects.length;++i) {
//Set the filter for the object 'objects[i]' here
//You can create just one filter outside the loop, and then attach it to every object inside the loop, I think
}
- The code assumes that the object has the Physics Automatism, and that it is named “Physics”, change this string with your physics automatism name otherwise.
If you think there is another error, check the console (Shift+Ctrl+K on Firefox, Shift+Ctrl+I on Chrome, etc) and tell me the error, or share the file (with basic resources to make it work is better)