• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ strings from config.lua

_M4G0_

Intermediate OT User
Joined
Feb 6, 2016
Messages
521
Solutions
16
Reaction score
103
How can I get the strings from config.lua
e.g:
wordsList = "x, x1, x2,"

tryed
std::list<std::string> wordsList{g_config.getString(ConfigManager::WORDS_LIST)}; < compiled but not success
std::list<std::string> wordsList = g_config.getString(ConfigManager::WORDS_LIST);
 
Solution
Add WORDS_LIST in configmanager.h before LAST_STRING_CONFIG.
In configmanager.cpp inside of ConfigManager::load(), look underneath the other string config values and add this underneath the last one
C++:
string[WORDS_LIST] = getGlobalString(L, "wordsList", "");

And that's all you have to do. If you're trying to split the values after getting them you'll have to use this:
#include <boost/algorithm/string.hpp> in the cpp file you're going to be splitting this in:
C++:
std::vector<std::string> word_list;
boost::split(word_list, g_config.getString(ConfigManager::WORDS_LIST), boost::is_any_of(", "));
Now you're free to do whatever with word_list, it won't contain the comma or space inside the strings. If you want to...
You need to add whatever WORDS_LIST is in configmanager.h (in enum string_config_t) and configmanager.cpp (under ConfigManager::load())

You should then be able to use g_config.getString(ConfigManager::WORDS_LIST) if whatever you link to WORDS_LIST in the .cpp file is a clean string and your file has the extern ConfigManager g_config; link.
 
Add WORDS_LIST in configmanager.h before LAST_STRING_CONFIG.
In configmanager.cpp inside of ConfigManager::load(), look underneath the other string config values and add this underneath the last one
C++:
string[WORDS_LIST] = getGlobalString(L, "wordsList", "");

And that's all you have to do. If you're trying to split the values after getting them you'll have to use this:
#include <boost/algorithm/string.hpp> in the cpp file you're going to be splitting this in:
C++:
std::vector<std::string> word_list;
boost::split(word_list, g_config.getString(ConfigManager::WORDS_LIST), boost::is_any_of(", "));
Now you're free to do whatever with word_list, it won't contain the comma or space inside the strings. If you want to iterate the list do this:
C++:
for (std::string word : word_list) {
    // do what you want with each  word
}
 
Solution
Back
Top