From e9ca0738a4b18032151af42baca1f88629408d52 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 29 Dec 2011 23:43:25 -0700 Subject: While loops work perfectly :) --- src/gamestate.cpp | 23 +++++++++++++++++++++++ test.stage | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 3f09c3f..902d0a9 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -366,7 +366,30 @@ void GameState::parse( const AstBranch::NodeList &lCode ) break; case AstNode::tForEach: + + break; + case AstNode::tWhile: + { + AstBranch::NodeList lWhile = + dynamic_cast(*i)->getNodeList(); + AstBranch::NodeList::const_iterator iTest = lWhile.begin(); + AstBranch::NodeList::const_iterator iDo = iTest+1; + + for(;;) + { + parse( dynamic_cast(*iTest)-> + getNodeList() ); + Variable v = popDeref(); + if( v.getType() != Variable::tBool ) + throw Bu::ExceptionBase("conditional did not evaluate to boolean."); + if( !v.getBool() ) + break; + + parse( dynamic_cast(*iDo)-> + getNodeList() ); + } + } break; } diff --git a/test.stage b/test.stage index c19dac9..3fa32c0 100644 --- a/test.stage +++ b/test.stage @@ -57,5 +57,11 @@ situation <> enter { display('''Entered stuff''' + player.name); + count = 0; + while count < 5 do + { + display('thing to count!'); + count += 1; + } } } -- cgit v1.2.3