Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
In my test level (Windows, physics on) I have added various things to the standard behaviours, like multiple stand/idle, attack, hit and die animations. At first look everything works fine. But - depending on the number of NPCs/enemies - after 18 to 50 minutes the game crashes down to 1 - 3 frames per second and I get a lot of "out of memory" errors in my scripts. An example with 2 fishes, who swim around and flee, if the player comes too close let's the game crash after around 50 minutes. Besides "Game Actor with Health" (randomly patrol) and "Collide when moved" the fishes have the following script: [code]// The following embedded xml is for the editor and describes how the behavior can be edited: // Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action /* <behavior jsname="behavior_wlEntityMoveNoGravNoKill" description="Entity no gravitation no kill"> <property name="WalkAnimation" type="string" default="walk" /> <property name="RunAnimation" type="string" default="run" /> <property name="DieAnimation" type="string" default="die" /> <property name="Fly" type="bool" default="false" /> <property name="EscapeDistance" type="int" default="40" /> <property name="WalkSpeed" type="int" default="7" /> <property name="RunSpeed" type="int" default="20" /> </behavior> */ behavior_wlEntityMoveNoGravNoKill = function() { this.LastTime = null; this.InitHeight = null; this.MyPos = null; this.Animation = null; this.MyName = null; this.MyVariable = null; this.SpeedName = null; }; // called every frame. // 'node' is the scene node where this behavior is attached to. // 'timeMs' the current time in milliseconds of the scene. // Returns 'true' if something changed, and 'false' if not. behavior_wlEntityMoveNoGravNoKill.prototype.onAnimate = function(node, timeMs) { // get the time since the last frame if (this.LastTime == null) { // we were never called before, so store the time and cancel this.LastTime = timeMs; this.InitHeight = ccbGetSceneNodeProperty(node, 'Position'); this.MyName = ccbGetSceneNodeProperty(node, 'Name'); this.Animation = ccbGetSceneNodeProperty(node, 'Animation'); this.MyVariable ="vx"+this.MyName; this.SpeedName = ""+this.MyName+".movementspeed"; return false; } //ccbSetCopperCubeVariable(name, -1); this.MyPos = ccbGetSceneNodeProperty(node, 'Position'); var player = ccbGetSceneNodeFromName("Player1"); var playerpos = ccbGetSceneNodeProperty(player, 'Position'); //calculate distance var dx = playerpos.x - this.MyPos.x; var dy = playerpos.y - this.MyPos.y; var dz = playerpos.z - this.MyPos.z; var dist = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2)); this.Animation = ccbGetSceneNodeProperty(node, 'Animation'); //walk and escape if ((dist > this.EscapeDistance + 5) && this.Animation != this.WalkAnimation && this.Animation != this.DieAnimation) { ccbSetCopperCubeVariable(this.SpeedName, this.WalkSpeed); ccbSetSceneNodeProperty(node, "Animation", "None"); ccbSetSceneNodeProperty(node, "Animation", this.WalkAnimation); //ccbPlaySound("ding1.wav"); } if (dist < this.EscapeDistance && this.Animation != this.RunAnimation && this.Animation != this.DieAnimation) { ccbSetCopperCubeVariable(this.SpeedName, this.RunSpeed); ccbSetSceneNodeProperty(node, "Animation", "None"); ccbSetSceneNodeProperty(node, "Animation", this.RunAnimation); } //Correct Y-position if (!this.Fly) { /* if (this.MyPos.y > waterlevel - 3 && dist > this.EscapeDistanc |
||||
|
I don't know, what's wrong with this script and let's the game crash, but I must admit that I don't know much about scripting. I have just taken some actions and behaviours from the extensions folder and changed and expanded them to my needs. |
||||
|
I have just seen, that not the whole code was posted, so here is the rest: //Correct Y-position |
||||
|
Hm, difficult to say with only this partial code, sounds like you have a memory leak somewhere in your javascript. If you like, send me the file (see support -> contact) and I'll have a look at that. |
||||
|
Thanks Niko, I have sent you an email. |
||||
|
I just wanted to add that I like Coppercube and am quite happy, what I could achieve in my first test level - if we can solve this memory leak: |
||||
|
Wow... your game is looking good dude... keep it up...! |
||||
|
it is easy to import from an external 3d software, hands with weapons like in your picture? |
||||
|
Hi Leo, Yes, it was easy to import 3D-models like the hands, but I still don't know how to get rid of the memory leak :( |
||||
|
As I wrote per mail, I looked through your game, and it seems to be some javascript object which isn't freed by your scripts. You probably add some objects into a global variable and over time, they get more and more and are never freeed. You have so many and long scripts in there, of which I didn't quite understand which script does what, so that it probably easier for you to spot this. But if you like I can try to look again. |
||||
|
Looks like I missed your email, maybe it got in my spam folder? |
||||
|
Yes, could be, seems like during the last months for example gmail tends to think my mails are spam, although I'm only usually writing a few lines without any web links and similar... |
|