From 0655735c84f412b7ad3e65381dc24694a9ac8071 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 May 2015 15:23:03 -0600 Subject: Goto was confused. The variable was being reset, then used by reference as the next destination. Confusing to debug. --- src/gamestate.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/gamestate.cpp') diff --git a/src/gamestate.cpp b/src/gamestate.cpp index b009e4c..ceed091 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -10,6 +10,8 @@ #include #include + +#include using namespace Bu; GameState::GameState( Game *pGame, Interface *pIface ) : @@ -281,7 +283,9 @@ void GameState::gotoSituation( const Bu::String &sName ) hsSituation.insert( sName, new Scope() ); pSit->exec( *this, Situation::modeSetup ); if( !sGoto.isSet() ) + { pSit->exec( *this, Situation::modeEnter ); + } } else { @@ -290,7 +294,7 @@ void GameState::gotoSituation( const Bu::String &sName ) if( sGoto.isSet() ) { - gotoSituation( sGoto ); + gotoSituation( sGoto.clone() ); } } @@ -315,7 +319,7 @@ void GameState::execCommand( const Bu::String &sCmd ) } if( sGoto.isSet() ) - gotoSituation( sGoto ); + gotoSituation( sGoto.clone() ); } void GameState::execOption( int idx ) @@ -323,7 +327,7 @@ void GameState::execOption( int idx ) pGame->getSituation( sCurSituation )->execOption( *this, idx ); if( sGoto.isSet() ) - gotoSituation( sGoto ); + gotoSituation( sGoto.clone() ); } bool GameState::hasVariable( const Bu::String &sName, ScopeId id ) @@ -461,8 +465,21 @@ Variable &GameState::deref( Variable &src, bool bCreate ) return sPlayer.get( r.sName ); case sidSituation: - hsSituation.get( sCurSituation )->insert( r.sName, Variable() ); - return hsSituation.get( sCurSituation )->get( r.sName ); + if( hsSituation.has( sCurSituation ) ) + { + hsSituation.get( sCurSituation )->insert( r.sName, Variable() ); + return hsSituation.get( sCurSituation )->get( r.sName ); + } + else + { + Bu::println("No such situation: %1").arg( sCurSituation ); + Bu::println("Available:"); + for( ScopeHash::iterator i = hsSituation.begin(); i; i++ ) + { + Bu::println(" <<%1>>").arg( i.getKey() ); + } + ::exit( 0 ); + } } } else -- cgit v1.2.3