Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
After a couple hours on the mail archive, I found the problem. When I added the defglobal to the Rete engine I used this command: *Defglobal playerIDGlobal = new Defglobal(*PLAYER_ID*, new Value(self.getID()));* *engine.addDefglobal(playerIDGlobal);* * * But this doesn't specify a type for the Value object, so when I tried to match against *?*PLAYER_ID** on the lhs of my rules it always returned false because the type of the defglobal was defaulted to Java object. I changed the command to this: *Defglobal playerIDGlobal = new Defglobal(*PLAYER_ID*, new Value(self.getID(), RU.INTEGER));* *engine.addDefglobal(playerIDGlobal);* * * And now everything seems to be working fine, Just out of curiosity though how does Jess infer types of variables when it is matching on the lhs of rules? Thanks, Hunter McMillen On Wed, Jan 11, 2012 at 6:04 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: For everything to work right, you always have to use the asterisks (as I said, they're part of the name), and you must include a (defglobal) declaration before using the variable. Setting a global variable by hand without declaring it first produces undefined results (I.e., it'll work right some of the time.) From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Wed, 11 Jan 2012 16:37:11 -0500 To: jess-users@sandia.gov Subject: Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule I placed the asterisks around PLAYER_ID then still received an error when the rule fired: No such variable *PLAYER_ID* But then noticed that when I call setVariable, I name the variable PLAYER_ID not *PLAYER_ID* so I changed my statement to this: *engine.getGlobalContext().setVariable(*PLAYER_ID*, new Value(player.getID());* and everything works fine. Does* getGlobalContext().setVariable(...)* define global variables implicitly? or do you have to include the asterisks like I did? Thanks. Hunter McMillen On Wed, Jan 11, 2012 at 3:13 PM, Friedman-Hill, Ernest ejfr...@sandia.gov wrote: The asterisks are part of the defglobal's name. You're not comparing to the defglobal: you're binding the value in the slot to a new variable. It's not legal to negate such a constraint in its first use, as the error message said. You need to use * (unit (ID ?id) (typeID ?typeID) (player ~?*PLAYER_ID*))* From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Wed, 11 Jan 2012 14:38:31 -0500 To: jess-users@sandia.gov Subject: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: *engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID());* * * And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID *(defrule myUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID))* *=* * .)* * * But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID *(defrule enemyUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID))* *=* * .)* * * How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: *engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID());* * * And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID *(defrule myUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID))* *=* * .)* * * But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID *(defrule enemyUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID))* *=* * .)* * * How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
The asterisks are part of the defglobal's name. You're not comparing to the defglobal: you're binding the value in the slot to a new variable. It's not legal to negate such a constraint in its first use, as the error message said. You need to use (unit (ID ?id) (typeID ?typeID) (player ~?*PLAYER_ID*)) From: Hunter McMillen mcmil...@gmail.commailto:mcmil...@gmail.com Reply-To: jess-users@sandia.govmailto:jess-users@sandia.gov Date: Wed, 11 Jan 2012 14:38:31 -0500 To: jess-users@sandia.govmailto:jess-users@sandia.gov Subject: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID()); And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID (defrule myUnitSeen (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID)) = .) But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID (defrule enemyUnitSeen (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID)) = .) How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
I placed the asterisks around PLAYER_ID then still received an error when the rule fired: No such variable *PLAYER_ID* But then noticed that when I call setVariable, I name the variable PLAYER_ID not *PLAYER_ID* so I changed my statement to this: *engine.getGlobalContext().setVariable(*PLAYER_ID*, new Value(player.getID());* and everything works fine. Does* getGlobalContext().setVariable(...)* define global variables implicitly? or do you have to include the asterisks like I did? Thanks. Hunter McMillen On Wed, Jan 11, 2012 at 3:13 PM, Friedman-Hill, Ernest ejfr...@sandia.govwrote: The asterisks are part of the defglobal's name. You're not comparing to the defglobal: you're binding the value in the slot to a new variable. It's not legal to negate such a constraint in its first use, as the error message said. You need to use * (unit (ID ?id) (typeID ?typeID) (player ~?*PLAYER_ID*))* From: Hunter McMillen mcmil...@gmail.com Reply-To: jess-users@sandia.gov Date: Wed, 11 Jan 2012 14:38:31 -0500 To: jess-users@sandia.gov Subject: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: *engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID());* * * And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID *(defrule myUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID))* *=* * .)* * * But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID *(defrule enemyUnitSeen * * (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID))* *=* * .)* * * How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen
Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule
For everything to work right, you always have to use the asterisks (as I said, they're part of the name), and you must include a (defglobal) declaration before using the variable. Setting a global variable by hand without declaring it first produces undefined results (I.e., it'll work right some of the time.) From: Hunter McMillen mcmil...@gmail.commailto:mcmil...@gmail.com Reply-To: jess-users@sandia.govmailto:jess-users@sandia.gov Date: Wed, 11 Jan 2012 16:37:11 -0500 To: jess-users@sandia.govmailto:jess-users@sandia.gov Subject: Re: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule I placed the asterisks around PLAYER_ID then still received an error when the rule fired: No such variable *PLAYER_ID* But then noticed that when I call setVariable, I name the variable PLAYER_ID not *PLAYER_ID* so I changed my statement to this: engine.getGlobalContext().setVariable(*PLAYER_ID*, new Value(player.getID()); and everything works fine. Does getGlobalContext().setVariable(...) define global variables implicitly? or do you have to include the asterisks like I did? Thanks. Hunter McMillen On Wed, Jan 11, 2012 at 3:13 PM, Friedman-Hill, Ernest ejfr...@sandia.govmailto:ejfr...@sandia.gov wrote: The asterisks are part of the defglobal's name. You're not comparing to the defglobal: you're binding the value in the slot to a new variable. It's not legal to negate such a constraint in its first use, as the error message said. You need to use (unit (ID ?id) (typeID ?typeID) (player ~?*PLAYER_ID*)) From: Hunter McMillen mcmil...@gmail.commailto:mcmil...@gmail.com Reply-To: jess-users@sandia.govmailto:jess-users@sandia.gov Date: Wed, 11 Jan 2012 14:38:31 -0500 To: jess-users@sandia.govmailto:jess-users@sandia.gov Subject: JESS: [EXTERNAL] How to negate a variable when in lhs of a rule Hi everyone, I am trying to differentiate between Objects that belong to a certain user inside two of my rules. I have a variable created from Java like this: engine.getGlobalContext().setVariable(PLAYER_ID, new Value(player.getID()); And I want to use this variable in rules to determine which objects belong to each player. This rule works fine when just using ?PLAYER_ID (defrule myUnitSeen (unit (ID ?id) (typeID ?typeID) (player ?PLAYER_ID)) = .) But when I try to negate the variable I get an error, First use of variable negated: PLAYER_ID (defrule enemyUnitSeen (unit (ID ?id) (typeID ?typeID) (player ~?PLAYER_ID)) = .) How can I specify anything other than ?PLAYER_ID on the lhs of a rule? Thanks, Hunter McMillen