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. --- demo.stage | 2 +- src/game.cpp | 2 ++ src/gamebuilder.cpp | 2 +- src/gamestate.cpp | 27 ++++++++++++++++++++++----- src/interfacegats.cpp | 1 + src/variable.cpp | 2 +- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/demo.stage b/demo.stage index 5a3fe2e..2b04bd4 100644 --- a/demo.stage +++ b/demo.stage @@ -91,11 +91,11 @@ situation <> You don't seem to have anything with you but the clothes you're wearing. (You also posses an eerily accurate innate sense of direction.)'''); - goto( <> ); } enter { + goto( <> ); } } diff --git a/src/game.cpp b/src/game.cpp index 05c5eca..77d65d8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -11,6 +11,8 @@ #include "functionkeys.h" #include "functioncount.h" +#include + Game::Game() { hGlobalParam.insert("start", Variable::newSituationName("start") ); diff --git a/src/gamebuilder.cpp b/src/gamebuilder.cpp index e8ecf63..1002d71 100644 --- a/src/gamebuilder.cpp +++ b/src/gamebuilder.cpp @@ -123,7 +123,7 @@ void GameBuilder::beginSituationMode( Situation::Mode m ) void GameBuilder::closeSituationMode() { -// sio << "Set situation <<" << pCurSit->getName() << ">> mode " << eCurSitMode << " to " << *pCurRoot << sio.nl; + //sio << "Set situation <<" << pCurSit->getName() << ">> mode " << eCurSitMode << " to " << *pCurRoot << sio.nl; pCurSit->setAst( pCurRoot, eCurSitMode ); pCurRoot = pCurNode = NULL; } 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 diff --git a/src/interfacegats.cpp b/src/interfacegats.cpp index 2e33aee..d2afce3 100644 --- a/src/interfacegats.cpp +++ b/src/interfacegats.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/src/variable.cpp b/src/variable.cpp index 88ac1bc..4ddec1a 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1048,7 +1048,7 @@ void Variable::deinitType() Variable::Type Variable::bestType( Variable::Type t1, Variable::Type t2 ) const { - Type tBest = Bu::max( t1, t2 ); + Type tBest = Bu::buMax( t1, t2 ); return tBest; } -- cgit v1.2.3