-
Notifications
You must be signed in to change notification settings - Fork 105
Conditional Command
The framework provides a conditional if-then
or if-then-else
to be used to compose scripts.
To support some examples, we will use the following script as support:
if(HaveQtdUnitsHarversting(20)) (attack(Worker,weakest)) (attack(Ranged,weakest) attack(Light,weakest))
Where if(HaveQtdUnitsHarversting(20))
represents the if + boolean function, (attack(Worker,weakest))
represents then + action function, and (attack(Ranged,weakest) attack(Light,weakest))
represents the else + action function. The basic structure to produce this script, in code, is:
line 1. //boolean
line 2. iBooleanDSL boolC = new BooleanDSL("HaveQtdUnitsHarversting(20)");
line 3. //then
line 4. CommandDSL c1 = new CommandDSL("attack(Worker,weakest)");
line 5. CDSL cdslThen = new CDSL(c1);
line 6. //else
line 7. CommandDSL c2 = new CommandDSL("attack(Ranged,weakest)");
line 8. CommandDSL c3 = new CommandDSL("attack(Light,weakest)");
line 9. CDSL cdsl2 = new CDSL(c3);
line 10. CDSL cdslElse = new CDSL(c2, cdsl2);
The complete structure can be interpreted (composed) as:
Using the fragments above, we can compose a if-then structure by using the code:
The complete structure can be interpreted (composed) as:
Using the fragments above, we can compose a if-then-else structure by using the code:
Class BuilderDSLTreeSingleton provides a method to get the structure If
(S2DSL) in a simple way:
-
BuilderDSLTreeSingleton.getInstance().buildS2Grammar(true);
-- Parameter true to compose if with parameter BuilderDSLTreeSingleton.getInstance().buildS2Grammar(false);
-
BuilderDSLTreeSingleton.getInstance().buildS2ThenGrammar(true);
-- Parameter true to compose if with parameter BuilderDSLTreeSingleton.getInstance().buildS2ThenGrammar(false);
-
BuilderDSLTreeSingleton.getInstance().buildS2ElseGrammar(true);
-- Parameter true to compose if with parameter BuilderDSLTreeSingleton.getInstance().buildS2ElseGrammar(false);