Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Problem with EnvDirectGetSlot

Help
2011-08-29
2012-11-23
  • I'm having a strange problem where I'm creating a COOL instance, running the engine, retrieving an instance slot value that was set via rules.  Then I reset the engine, create another COOL instance (of the same name), run the engine again where the rules set the slot value to a different value.  But this time, when I use EnvDirectGetSlot and DataObjectToString to retrieve the slot value, I actually get the slot value from the prior run.  This pattern appears to continue…I'm always getting the slot value from the previous run, not the current run.

    Code snippet is:

    SHORT CLIPSRuleService::executeRuleset( const String& ruleSetName, ArrayList& bomObjs, SHORT numOfRulesToFire )
    {
        DATA_OBJECT slotValue;
        VOID    *engineEnv;
        VOID    *clpsCardPtr = NULL;
        Object    *arrayObject = NULL;
        String    objStr;
        String    tempStr;
        String    strSlot = "";
        int        idx;

        engineEnv = getEnvironment(ruleSetName);

        for (idx=0; idx < bomObjs.size(); idx++)
        {
            // Process each BOM objects
            arrayObject = bomObjs.get( idx );
            if ( NULL != arrayObject )
            {
                if ( NULL != dynamic_cast< String * >( arrayObject ) )
                {
                    objStr = arrayObject->toString(objStr);
                    getCoolInstanceStr(objStr);

                    // Reset the Environment
                    EnvReset(engineEnv);

                    //Creating Instance
                    clpsCardPtr = EnvMakeInstance(engineEnv, (char *)objStr.toCharArray());

                    //Executing the ruleset
                    EnvRun(engineEnv,-1);

                    //Retrieve the Slot Value
                    EnvDirectGetSlot(engineEnv, clpsCardPtr, (char *) "FloorLimit", &slotValue);

                    //Convert the Data Object to String
                    strSlot = DataObjectToString(engineEnv, &slotValue);

                }

     
  • Oh, and here's my class definition:

    (defclass Card (is-a USER)
    (role concrete)
    (pattern-match reactive)
    (slot CardNumber (type STRING))
    (slot FloorLimit (type STRING))
    )

     
  • Gary Riley
    Gary Riley
    2011-08-30

    Use the EnvWatch function to watch rules, instances, and slots, so that you can observe changes as you create the instance and run your rules. I don't see anything obviously wrong with the code.