scanForNearestShipWithScanClass: is not working

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

scanForNearestShipWithScanClass: is not working

Post by Eric Walch »

The new function scanForNearestShipWithScanClass is not working yet. I tried to use it but it didn't recognise my ships. So I wrote a small testscript for a ship placed near the station and the buoy.

Code: Select all

    IDLE = {
        ENTER = (); 
        EXIT = (); 
        "TARGET_FOUND" = ("commsMessage: Buoy found"); 
    UPDATE = ("scanForNearestShipWithScanClass: CLASS_BUOY", "commsMessage: Hello Player", "pauseAI: 10"); 
    }; 
I did get the UPDATE message but never the FOUND message. Even using a "setDesiredRangeTo: 20000.0" in the script didn't help (in case the new function had a range). With the debugging tool I checked the AI was in the IDLE state and the scann_class of the buoy was CLASS_BUOY
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

My C knowledge is still not enough to really understand all but following the scan code I see no strange things. Only when I come in the new file: OOEntityFilterPredicate I see something strange.

Code: Select all

BOOL HasScanClassPredicate(Entity *entity, void *parameter)
{
	return [(id)parameter intValue] == [entity scanClass];
}
"parameter" is the scanclass we are looking for. Is it changed to an integer and than compared with the string "scanClass"? Could this be that it always returns NO?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6628
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Parameter is converted to an int value and it gets compared with scanClass, indeed. But scanClass is not a string. In reality it is an integer value. In OOTypes.h, you will find

Code: Select all

typedef enum
{
	CLASS_NOT_SET					= -1,
	CLASS_NO_DRAW					= 0,
	CLASS_NEUTRAL					= 1,
	CLASS_STATION					= 3,
	CLASS_TARGET					= 4,
	CLASS_CARGO						= 5,
	CLASS_MISSILE					= 6,
	CLASS_ROCK						= 7,
	CLASS_MINE						= 8,
	CLASS_THARGOID					= 9,
	CLASS_BUOY						= 10,
	CLASS_WORMHOLE					= 444,
	CLASS_PLAYER					= 100,
	CLASS_POLICE					= 999,
	CLASS_MILITARY					= 333
} OOScanClass; 
Then in Entity.h there is the declaration OOScanClass scanClass (line 104). This is the scanClass that is compared with the parameter value. I had a quick look at the code and it looks pretty OK to me, too. But maybe I will have a better look sometime during the weekend and see if I can discover anything.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Eric is correct; 1.70 is not converting the scan class string to an integer before setting up the search predicate, so the only way it’ll work is if you pass an integer instead of a symbolic name. (But don’t do that; it won’t work in future.)

The JavaScript equivalent works, though:

Code: Select all

this.findNearestBuoy = function()
{
    let result = null
    try
    {
        result = system.entitiesWithScanClass("CLASS_BUOY", player)[0]
    }
    catch (error)
    {
        // If we get here, no buoys were found.
    }
    return result
}
Post Reply