Method to get infos from XML files?

oh what the hay… ohm…

fixed
Also I forgot to check if the XML code is working. I just checked the GUI and display. Checking…

Oh I’m getting the same errors… ohm…

I managed to fix it: i.imgur.com/64bV1DJ.jpg

        pugi::xml_document modulesList;
        pugi::xml_parse_result result = modulesList.load_file("Data/Scripts/Modules.xml"); //load XML
        pugi::xml_node xml_root=modulesList.child("xml");  // the first child is (weirdly) the <xml> tag.

        // iterate over the child of the "<xml>" root node.
        for(pugi::xml_node_iterator it=xml_root.children().begin();
            it!=xml_root.children().end();it++)
        {
            pugi::xml_node& child=*it;

            std::string name(child.name());
std::cout<<"name: "<<name<<std::endl;
            if(name=="infos")
            {
                for(pugi::xml_attribute_iterator it=child.attributes().begin();
                   it!=child.attributes().end();it++)
                {
                    pugi::xml_attribute& attr=*it;
std::cout<<"attr: "<<attr.name()<<std::endl;

                    if(std::string((const char*)attr.name())=="count")
                        modulesCount = atoi(attr.value()); //get modules count
                }
            }
        }
std::cout<<"modulesCount: "<<modulesCount<<std::endl;

std::stoi is actually a C++11 function. atoi is the older C possibility.

Works for me now.

(The “Device lost” message in the output appeared when I resized the Urho window for some reason but everything kept working fine. Maybe that’s just a note.)

yes so i guess i just forgot to put the font in my ressources folder… ><
the text show fine, sometime i check the log but i guess i didn’t checked at the good time, i wonder.

i have a “projet” directory on my bureau. with the console i run a little script:

so it prepare the compilation in my “projet_build” directory.
then i delete the CoreData and Data shortcut from projet_build/bin and copy in it those from my projet folder with in it just what i need normally. ><
then in the console, i go to the projet_build folder and i use “make” (edit: or i just edit the main.cpp in my “projet” folder and use make directly)

[spoiler]i will try to see if my “count” return the value i want with the other method:

pugi::xml_node infos = modulesList.child("infos"); pugi::xml_attribute count; count = infos.child_value("count"); [/spoiler]
oh wait you beat me to it.
i will try your code for the xml so. it’s almost 4am here, so i will do that tomorow. ^^;
oh and that’s why the keys are set like this, i’m french so i have a azerty keyboad configuration through with tab you should be able to free the mouse too. and the light color represent the 3D axis ^^.

thx again for the help.

Settings URHO3D_SAMPLES is only useful to tell the Urho build process if it should build the Urho samples (“01_HelloWorld”, “02_HelloGUI”,…). You can skip setting that as it isn’t doing anything for your project.
See urho3d.github.io/documentation/1 … lding.html for details on the build process.

the code compile fine but i have two others questions (i have tones of questions lol…) and i should be good to go.

1/ how do you enable the console ? i saw a build option to do that in the link you gave but it’s only for windows and i’m sure i saw how to do that somewhere else but i don’t remember where.

2/ how do i convert my int back into a string so i can append it to my text string and use window_text->SetText(my_string);
checking some tutos, i think it should be something like that and i tryed different things with char or other things but i wasn’t able to compile with my tries:

        std::string str=("modulesCount = ");
        str.append(/*converstion of modulesCount into const char* ?*/);
        String s(str.c_str(),str.size());

      window_text->SetText(s);

thx, i wasn’t sure the sample option was needed or not.

[quote=“noals”]the code compile fine but i have two others questions (i have tones of questions lol…) and i should be good to go.

1/ how do you enable the console ? i saw a build option to do that in the link you gave but it’s only for windows and i’m sure i saw how to do that somewhere else but i don’t remember where.
[/quote]
Try starting your program from the terminal. There should be a visible output then. You can configure your IDE to start the program in a terminal. For example in CodeBlocks you set the “type” under “Build targets” in the project properties to “Console Application” (you may want to also uncheck “Pause when execution ends” there). In QtCreator the option is a checkbox and called “Run in terminal” in the projects run options.

C++11 has std::to_string and std::stoi. In non C++11 the best option seems to be ostringstream: stackoverflow.com/questions/5590 … tring-in-c.
Oh I’m actually using that to display my FPS:

std::string str="WASD, mouse and shift to move. T to toggle fill mode,\nG to toggle GUI, Tab to toggle mouse mode, Esc to quit.\n";
{
    std::ostringstream ss;
    ss<<1/timeStep;
    std::string s(ss.str());
    str.append(s.substr(0,6));  // limit the float value text length to 6 characters like "123.45" or "1.2345"
}
str.append(" FPS ");
String s(str.c_str(),str.size());  // convert std::string to Urho3D::String
window_text->SetText(s);         // set Urho3D::Text widget's text

[quote=“gawag”]
Try starting your program from the terminal. There should be a visible output then.[/quote]
ha yes, thx you, i will do that. i don’t use an IDE, i just code with gedit.

i didn’t #include in my previous tries… ><

everything works fine now.
http://s7.postimg.org/n7enmpda3/Capture_du_2016_03_09_18_32_21.png

thanks a lot for all your help.

hi, i encountered another little problem i don’t really understand.

i changed a little my xml :

<xml>
<infos count="2"/>
<module1 type="1" exits="2" path="Models/cor5x20x1/cor5x20x1.mdl" texturepath="Models/cor5x20x1/cor5x20x1.xml"/>
<module2 type="2" exits="4" path="Models/room20x20x1/room20x20x1.mdl" texturepath="Models/room20x20x1/room20x20x1.xml"/>
</xml>

and here is the code that compile fine but don’t seem to return the values i want.
my string “module” actually return “module” + an int, module1 or module2 so it’s not the problem.

            if(name==module) // "module" + randomLine 
            {
                for(pugi::xml_attribute_iterator it=child.attributes().begin();
                   it!=child.attributes().end();it++)
                {
                    pugi::xml_attribute& attr=*it;

                    if(std::string ((const char*)attr.name())=="type")
                    {
                        moduleType=std::atoi(attr.value());
                    }
                    if(std::string ((const char*)attr.name())=="exits")
                    {
                        exits=std::atoi(attr.value());
                    }
                    if(std::string ((const char*)attr.name())=="path")
                    {
                        modulePath=attr.value();
                    }
                    if(std::string ((const char*)attr.name())=="texturepath")
                    {
                        moduleTexturePath=attr.value();
                    }
                }
            }

i didn’t verified yet but moduleType and exits should works fine since they are int.
modulePath and moduleTexturePath are std:string so i though i didn’t need to use std::atoi
i tryed the same conversion method as for the other or i just tryed :

String mP(modulePath.c_str(),modulePath.size()); String mTP(moduleTexturePath.c_str(),moduleTexturePath.size());
but they return nothing apparently.
what did i do wrong ?

my project files

thinking about t, i think it maybe have something to do with the “” because my string maybe return the value from the xml but since i want to use it directly to load a module, it don’t work because it end up being :

instead of :

i don’t know, i’m a little confused.

bah, nvm. i will try to clean up my code a little because with all those conversion and string, it’s a mess.
before i was able to return my moduleX string in the console so i know it worked but now with my tries, even that seem to return nothing.

there is something i will never understand through.
why every engine makes their own int, their own string and stuff like that ?
can’t peoples just update the c++ library so everyone can use the same object ? sigh…

[quote=“noals”]there is something i will never understand through.
why every engine makes their own int, their own string and stuff like that ?
can’t peoples just update the c++ library so everyone can use the same object ? sigh…[/quote]

Because of this:

That is, the current standards are kind of a pain in the ass. Not to mention things like Vector2/3/4, Matrix, Quaternion, etc… are not standard at all. On top of that, things such as int can vary in byte size, so they’re usually standardized to fixed bit sizes (int_16, uint_32, etc…) in many libraries.

Luckily for things like String, we can convert to/from C-style strings much like most other libraries. That way, converting from one library to another usually involves something like:

Urho3D::String ToUrho3D(lib2::String otherString) { return Urho3D::String(lib2String.c_str()); }

and many other formats are converted very similarly:

Urho3D::Vector3 ToUrho3D(lib2::Vector3 otherVector) { return Urho3D::Vector3(otherVector.x, otherVector.y, otherVector.z); }

This allows each library to work with common data types in a way that works for them. If the STL is not able to handle a problem elegantly, it’s easier to maintain your own implementation on top of that than rely on a non-standard “standard”.

yeah, it’s like a saying in france : “why makes things easier when we can make it complicated” …
if int for example became obsolete because of 64 bit OS and stuff like that, people could just remplace int by int32 and int64, etc… so everyone use the same.
i’m really a beginner and i can’t even get some values from an xml properly but i have a logical mind and sometime i think peoples didn’t understand the concept of object oriented programmation.

anyway, i have work to do. i feel like i’m stepping from the little main.cpp to a more complexe project so i’m kinda satisfied to make some progress but it become harder fast, wish me courage. ^^;