ofxUI addon save value from guiEvent()

Hi there, I am using the text field widget from the ofxUI addon. What I would like to do is to grab the string cityOutput variable form the guiEvent() method and reuse it in draw(). I can’t seem to figure out how to do it because void guiEvent() does not return anything, and if i change it to string guiEvent() and return the string, ofAddListener() won’t take it as an argument.

void ofApp::guiEvent(ofxUIEventArgs &e)
{
    string name = e.getName();
    if(name == "city"){
        ofxUITextInput *ti = (ofxUITextInput *) e.widget;
        string cityOutput = ti->getTextString();
        cout << cityOutput << endl;
        
        
        if(ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_ENTER)
        {
            cout << "ON ENTER: ";
            
        }
        else if(ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS)
        {
            cout << "ON FOCUS: ";
        }
        else if(ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_UNFOCUS)
        {
            cout << "ON BLUR: ";
        }
        
    }


}

the variable ‘cityOutput’ is local to the guiEvent function. This means that every time the guiEvent function is entered into, it creates a temporary variable called cityOutput and then deletes that variable from memory when exiting the function.

If you want to store the result of ofxUITextInput into cityOutput so you can use it in your draw function you simply just declare string cityOutput in you ofApp.h file. Then that variable is global to your ofApp class and can be read and written to in any of it’s methods, include guiEvent();