Author Topic: Getting an on event script hooked up (e.g. OnShipDestroyed)  (Read 1750 times)

loudent

  • Full Member
  • ***
  • Posts: 141
    • View Profile
Getting an on event script hooked up (e.g. OnShipDestroyed)
« on: April 17, 2015, 12:55:13 am »
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

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 1041
    • View Profile
Re: Getting an on event script hooked up (e.g. OnShipDestroyed)
« Reply #1 on: April 17, 2015, 03:56:19 am »
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

  • Full Member
  • ***
  • Posts: 141
    • View Profile
Re: Getting an on event script hooked up (e.g. OnShipDestroyed)
« Reply #2 on: April 17, 2015, 09:26:27 am »
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

  • Newbie
  • *
  • Posts: 46
    • View Profile
Re: Getting an on event script hooked up (e.g. OnShipDestroyed)
« Reply #3 on: April 17, 2015, 10:53:53 am »
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

  • Full Member
  • ***
  • Posts: 141
    • View Profile
Re: Getting an on event script hooked up (e.g. OnShipDestroyed)
« Reply #4 on: April 17, 2015, 10:59:11 am »
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

  • Full Member
  • ***
  • Posts: 141
    • View Profile
Re: Getting an on event script hooked up (e.g. OnShipDestroyed)
« Reply #5 on: April 17, 2015, 11:00:30 am »
Edited out
« Last Edit: April 17, 2015, 08:51:37 pm by loudent »

loudent

  • Full Member
  • ***
  • Posts: 141
    • View Profile
Re: Getting an on event script hooked up (e.g. OnShipDestroyed)
« Reply #6 on: April 17, 2015, 12:41:45 pm »
Edited out
« Last Edit: April 17, 2015, 08:51:49 pm by loudent »