Author Topic: Problem with script  (Read 4139 times)

Afaut

  • Newbie
  • *
  • Posts: 8
    • View Profile
Problem with script
« on: August 23, 2017, 05:31:34 am »
Hi, i'm working on a new mod, a device to restore ammunition it work but i have a problem

i've this
Code: [Select]
var ballisticWeapons = ship.GetWeaponsOfType(args.ship_id, 2);

   
   

//check weapon
if (ballisticWeapons == null)
    {
ship.DeviceDeactivate(args.ship_id, args.slot_id, true);
        game.SendNotificationError(game.GetShipOwner(args.ship_id), "No Ballistic Weapon"); // Repair is not required: Repair is not required.
        return;
    }

not working, the game just ignore the if.
i've tried if (ballisticWeapons == undefined)
if (!ballisticWeapons )
and nothing work.
Is someone have an idea why it's not working?

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2038
    • View Profile
Re: Problem with script
« Reply #1 on: August 23, 2017, 05:35:37 am »
Hello!

it always returns an array of IDs (weapon items IDs).
If there are no ballistic weapons, the array will be empty.
So you can simply check the array length: if (ballisticWeapons.length == 0)...

Regards!

Afaut

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem with script
« Reply #2 on: August 23, 2017, 05:53:34 am »
i'll try and i'll tell you if it work.
Edit: It work! thank you, i don't know why in specialobject.js if (ballisticWeapons == null) work and not in my script but now it work
« Last Edit: August 23, 2017, 05:57:11 am by Afaut »

Teerawut

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Problem with script
« Reply #3 on: October 29, 2017, 10:06:34 pm »
I'm looking for a solution to the problem with script.sbobet
« Last Edit: December 27, 2017, 12:54:31 am by Teerawut »

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2038
    • View Profile
Re: Problem with script
« Reply #4 on: October 29, 2017, 10:09:01 pm »
@Teerawut, ok, post it here and we will try to help!