I'm trying to load up a game level using a pseudomap that I have stored in a json file, but I don't know the syntax on how to iterate through every character of the string. Here is an example of the json pseudomap:
So everywhere there is a 'w' I want to place a wall. The \n is a placeholder for a line break ina standard .txt file
Here is my attempt at this, but it doesn't compile
1 2 3 4 5 6 7 8
boost::property_tree::ptree pt;
boost::property_tree::read_json("levels/level" + std::to_string(levelNumber) + ".json", pt);
std::string pseudomap("levels.level1.map");
for(unsignedint i = 0; i < pt.get_child(pseudomap).size(); i++){
if(pt.get_child(pseudomap)[i] == "w"){ //I want to treat pt like a vector of chars that I can iterate through
AddWall();
}
}
What doesn't compile is if(pt.get_child(pseudomap)[i] because I don't know how to access a specific element of the current string in a boost property tree. Can anybody help me solve this?
I used property_tree before and I don't have my code with me, but maybe this will help:
Do you really mean to use get_child() on map? It is just a string, so I would have thought that something like pt.get<std::string>("levels.level1.map")
would get you a string that you can then do what you like with.
I'm no expert in boost property trees, but you've made "spawnpoints" an array (because of the square brackets [...]) containing a single element. So you'd need to specifically access the first element of that array.
Or, presumably, you really want to iterate over each element of that array in turn, if you're generalizing to more than one spawn point.
for(boost::property_tree::ptree::value_type &v : pt.get_child("levels.level1.spawnpoints")) {
// use v, which IIRC is another property tree representing the subtree
// in your case that would be a tree with x and y children, I think
}