+ 1

Im trying to make branching dialogue paths in C++

Heya i need help with my C++ Bot. Im looking for a ways to make say a certain response make it say something else leading down another conversation path. I know it doesnt work on this app. I have a CxxDroid for this bot and it works there. https://code.sololearn.com/cYDyUQoi8MZe/?ref=app

6th Jan 2019, 6:45 AM
Dayton Wyer
Dayton Wyer - avatar
2 Antworten
+ 1
I would say take out all the response variables except one. There's no need to have 50,000, when you can use one repeatedly. It takes up far too much memory, especially depending on how long your story will be. I see a huge load of repetition in your code. I would recommend putting that in a function, which could divide your code by 3 or more. Have the function have parameters for wait time and the string for the bot to output. At this point, you only need a response variable in the function. I would say you can either have a, b, c, d choice responses, or you can get into AI programming and basically detect specific words like "do," "don't," "like," etc.
6th Jan 2019, 7:00 AM
Rain
Rain - avatar
+ 1
For example, this code: std::cout << "MSG: Im Jane, its nice to meet you!" << "\n"; getline (std::cin, response1); sleep_for(nanoseconds(6)); sleep_until(system_clock::now() + seconds(3)); ^ Can be simplifies with a function. Put it in something like this: void Message(string janeMessage, int sleepTime, int nanoSeconds){ string response; std::cout << janeMessage << std::endl; getline (std::cin, response); sleep_for(nanoseconds(nanoSeconds)); sleep_until(system_clock::now() + seconds(sleepTime)); } With this function, you can shorten everything down to minimal lines, for example: Message("MSG: Im Jane, its nice to meet you!", 3, 6); is the same as all this: std::cout << "MSG: Im Jane, its nice to meet you!" << "\n"; getline (std::cin, response1); sleep_for(nanoseconds(6)); sleep_until(system_clock::now() + seconds(3));
6th Jan 2019, 7:07 AM
Rain
Rain - avatar