few conditional rule questions

2228
3
07-08-2012 11:10 AM
BobN
by
New Contributor
Hi,
My first question is:
Why is it not possible to instruct other rules prior to a conditional statement without the script marking the conditional statment as an error?
ex:
 alignScopeToAxes(y)
 s(assetSize("assets/facades/gazeboBeam_1.obj", "x"),assetSize("assets/facades/gazeboBeam_1.obj", "y"),assetSize("assets/facades/gazeboBeam_1.obj", "z"))
 i("assets/facades/gazeboBeam_1.obj")

              case pos == "center_xz":
                    center(xz)
              case pos == "right":
                    t('scope.sx - (assetSize("assets/facades/gazeboBeam_1.obj", "x") / 2), 0, 0)
              else:
                    DoNothing


My second question:
With the same code above, if I do not include an else statement, that as well causes the script to mark it as an error. Why is this so? Haven't the developers of CityEngine ever heard of if statements that do not include an else condition?
0 Kudos
3 Replies
DanielO_Shaughnessy
New Contributor II
This is probably a question best-suited to matthias....but here is a shot at your answer:

1) I think this has to do with how CityEngine reads rule hierarchy. Ie, instead of proceeding from one line in the rule down to the next (which is how I conceptualize coding), it proceeds from one rule (in its entirety) to the next. In your case, then, you would have to separate it out:

Start -->
 alignScopeToAxes(y)
 s(assetSize("assets/facades/gazeboBeam_1.obj", "x"),assetSize("assets/facades/gazeboBeam_1.obj", "y"),assetSize("assets/facades/gazeboBeam_1.obj", "z"))
 i("assets/facades/gazeboBeam_1.obj")
 posCheck

posCheck -->
              case pos == "center_xz":
                    center(xz)
              case pos == "right":
                    t('scope.sx - (assetSize("assets/facades/gazeboBeam_1.obj", "x") / 2), 0, 0)
              else:
                    DoNothing


Alternatively, you could repeat the first bit of code after each conditional statement:

  
           case pos == "center_xz":
       alignScopeToAxes(y)
       s(assetSize("assets/facades/gazeboBeam_1.obj", "x"),assetSize("assets/facades/gazeboBeam_1.obj", "y"),assetSize("assets/facades/gazeboBeam_1.obj", "z"))
       i("assets/facades/gazeboBeam_1.obj")
       center(xz)
            ....etc


2) If you don't include an else statement, then the conditional remains open. Ie, everything after your last line is still part of the "case" - right? Adding in the "DoNothing" rule as you did is one solution, as is simply using NIL.
And for the record, every conditional always includes some sort of "else" condition....otherwise there wouldn't be a conditional to begin with 😉
0 Kudos
MatthiasBuehler1
Frequent Contributor
Thanks for the inputs here, Daniel..


A thread related to the same topic, may give additional answers :

http://forums.arcgis.com/threads/57615-I-find-this-syntax-odd-why-is-this-so

Let me know if there's more questions !

Matt
0 Kudos
BobN
by
New Contributor
And for the record, every conditional always includes some sort of "else" condition....otherwise there wouldn't be a conditional to begin with


Daniel,
if you are not refering to only to CityEngine, then I have to disagree with every conditional statment includes some sor of else condition. For example, a snippet of C++ code could have this type of situation...

your playing a game of blackjack and it is your turn. I have seen where games, like Blackjack, are programmed in an event handling system where the code constantly loops endlessly until the game has won or the play has quit. here is an example of psuedo code...

gameOver = false
while(!gameOver) {
    if PlayerTurn == "Computer" {
        computer takes its turn
    else {
        getevent(&event)
        if event == DRAWCARD
            drawCard();
        elif: event == MAKEBID
            makeBid();
        elif: event == STAND {
            stand()
            PlayerTurn = "Computer";
        }
    }


as you can see in this pethetic poor example, you get the jist, if it is the human player's turn and he does not make a move, there is no else statment that causes the player to break out of his turn until he tells the program he wishes to stand. Thus causing the game to continuously loop in this theory....

did the game end --> no
is it the computer's turn --> no
else, must be player's turn
did the player ask to draw a card from the deck -->  no
did the player ask to make a bet --> no
did the player ask to stand --> no

did the game end.... and so on...
0 Kudos