[Pogamut-list] Giving my agent a weapon

nvh pogamut-forum at artemis.ms.mff.cuni.cz
Tue Feb 24 18:14:03 CET 2009


Giving my agent a weapon

Author: nvh

Hi,

Currently I'm trying to give an agent a weapon at the beginning of an experiment and unlimited ammo. Therefor I've the following code in my doLogic() loop:
^
       if (first) {
            first = false;
            body.addInventory("xWeapons.ShockRiflePickup");
            //Wait for the weapon to arrive
            while (!memory.hasWeaponOfType(ItemType.SHOCK_RIFLE)) {
                try {
                    Thread.sleep(10);
                    log.info("Slept 10 ms");
                    body.addInventory("xWeapons.ShockRiflePickup");
                } catch (InterruptedException ex) {
                    log.severe("Sleeping went wrong");
                }
            }
            body.changeWeapon(memory.getWeapon(ItemType.SHOCK_RIFLE));
            return;
        }
        if (memory.getAgentAmmo() < 10) {
            body.addInventory("xWeapons.ShockAmmoPickup");
            log.info("Added new supplies");
        }
^
This works fine, but sometimes my agent gets stuck in an infinite loop saying "Slept 10 ms", which I don't get because it tries to add the weapon every time it repeats that loop, so it should come out of it sometime, right?

What am I doing wrong, or is there some other way to give my agent one of the non-default weapons at start?

Niels





More information about the Pogamut-list mailing list