• Welcome to AtomicTorch Studio Forums.
 

Getting an on event script hooked up (e.g. OnShipDestroyed)

Started by loudent, April 17, 2015, 12:55:13 AM

loudent

Hi All,

I'm putting together an event script, in this case OnShipDestroyed). I have an OnInit() function where I bind OnShipDestroyed to a function in the script. I put the script in a mod pack and loaded.  However when a ship is destroyed it doesn't seem to be calling the script (in this case I have a test which sends a notification to the player and the notification doesn't seem to show up). Is there something I need to do to make sure the script is called? (

ai_enabled

Hello!
Please have a look on scripts/global/Collision.js it contains handler on ship destroyed event and works very well.
If you have problems with the script, it's better to run the game server in multiplayer mode, so you could read the server output. And you can use console.PrintError("test") in script to write messages to the console with the red color.
Place console.PrintError("init") at Init() method to be sure it has been invoked.
Regards!

loudent

hi,

In fact that his the very script I used as the basis for the one I created. It simply doesn't appear to be working so I was thinking that there might be additional steps I am missing. It appears that I'm not.

Thanks for the hint about running in multiplayer mode so I can see the output. I'll give that a go and see if I can find out why it isn't working.

Is there any way to use a debugger to step through the code or do I rely on console output?

Thanks

jeeplaw

Loudent, I use that same collision.js file in my mod as well. If you want to post the code up I can take a stab at it, It might be a variable issue as it was for me.

loudent

I'm sure it's a problem with my code. I have no working knowledge of JavaScript so I could be making any number of mistakes. I mostly wanted to make sure there wasn't something missing before I spend hours figuring out what I did wrong.

I'll probably just strip it down to minimal functions and add it piece by piece.

-loudent

loudent

Edited out

loudent

Edited out