AtomicTorch Studio Forums

VoidExpanse => Modding info => Topic started by: Afaut on August 23, 2017, 05:31:34 am

Title: Problem with script
Post by: Afaut 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?
Title: Re: Problem with script
Post by: ai_enabled 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!
Title: Re: Problem with script
Post by: Afaut 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