Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GameLoop parameter
Forum Updated to NodeBB v4.3 + New Features

GameLoop parameter

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 714 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    juve938383
    wrote on last edited by juve938383
    #1

    Hello everyone!
    I am working on a project that I downloaded from Github in QT. The problem is that it doesn't work properly. In the code below you can see the main() function. The code runs and every time it shows the part inside the if conditional. I tried debugging and I saw that argc has only 1 element but it seems like it should have 2 for the GameLoop to work. Maybe someone can give me an idea on how to make it work based on what the creator has mentioned: "Usage: ./pacman maps/map.txt"

    #include <gameclass.h>,
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        GameLoop    *loop;
    
        if (argc == 1 || argc > 2)
        {
            std::cout << "Invalid number of parameters.\n";
            std::cout << "Usage: ./pacman maps/map.txt\n";
            exit(0);
        }
    
        loop = new GameLoop(argv[1]);
    
        loop->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        loop->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        loop->setFixedSize(WIDTH, HEIGHT);
        loop->setSceneRect(0, 0, WIDTH, HEIGHT);
        loop->show();
        loop->ft_roll_game();
        return a.exec();
    }
    

    Thank you!

    1 Reply Last reply
    0
    • J juve938383

      Wow, that explains a lot. However, I did copy the file to the right path (added the "maps.txt" in a folder called "pacman maps" which was in the same path as the exe file) and I pasted its path in the Command line arguments section but it shows the same thing.

      M Offline
      M Offline
      mchinand
      wrote on last edited by mchinand
      #6

      @juve938383 said in GameLoop parameter:

      Wow, that explains a lot. However, I did copy the file to the right path (added the "maps.txt" in a folder called "pacman maps" which was in the same path as the exe file) and I pasted its path in the Command line arguments section but it shows the same thing.

      In general, try to avoid creating directories with spaces in them. You can make it work (adding quotes around the path), but it's just another thing to worry about. That usage text is not referring to a folder named 'pacman maps'.

      In the usage text

      ./pacman maps/map.txt
      

      ./pacman is the path to the executable file that you built. The './' is just saying that it's in the current directory that you're in.

      maps/map.txt is the path to the file the program expects (and used as the argument to GameLoop). In this case, it's a relative path to your current working directory. This is what you would add to the 'Command line arguments' in QtCreator as mentioned above.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mchinand
        wrote on last edited by
        #2

        That usage text is telling you that you need to provide the path to a text file when you run the program. The source code you downloaded probably included an example text file that could be used. Without knowing more about the code, no one can help you with what should be in the text file.

        1 Reply Last reply
        2
        • J Offline
          J Offline
          juve938383
          wrote on last edited by
          #3

          Oops, I thought the GameLoop was a general class and that is why I asked but it seems to be user defined. As you can see in the screenshot below, its parameter should be a file name pointer. Now I have the file name but I am not sure how to pass it to the constructor as it takes in a char pointer, not a string. What do you suggest? Screenshot_1.png

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mchinand
            wrote on last edited by
            #4

            The code above does that for you, you don't have to modify the code. If the name of the executable that is created after you build it is gameloop.exe then you have to call it like this:

            gameloop.exe C:/Users/username/gameloop/map/map.txt 
            

            Where the file map.txt exists in whatever path you give.

            If you're running it from QtCreator, you can specify the file name (the command line argument it expects) by going to the 'Projects' tab on the left side panel and then selecting 'Run' and modifying the 'Command line arguments'

            1 Reply Last reply
            2
            • J Offline
              J Offline
              juve938383
              wrote on last edited by
              #5

              Wow, that explains a lot. However, I did copy the file to the right path (added the "maps.txt" in a folder called "pacman maps" which was in the same path as the exe file) and I pasted its path in the Command line arguments section but it shows the same thing.

              M 1 Reply Last reply
              0
              • J juve938383

                Wow, that explains a lot. However, I did copy the file to the right path (added the "maps.txt" in a folder called "pacman maps" which was in the same path as the exe file) and I pasted its path in the Command line arguments section but it shows the same thing.

                M Offline
                M Offline
                mchinand
                wrote on last edited by mchinand
                #6

                @juve938383 said in GameLoop parameter:

                Wow, that explains a lot. However, I did copy the file to the right path (added the "maps.txt" in a folder called "pacman maps" which was in the same path as the exe file) and I pasted its path in the Command line arguments section but it shows the same thing.

                In general, try to avoid creating directories with spaces in them. You can make it work (adding quotes around the path), but it's just another thing to worry about. That usage text is not referring to a folder named 'pacman maps'.

                In the usage text

                ./pacman maps/map.txt
                

                ./pacman is the path to the executable file that you built. The './' is just saying that it's in the current directory that you're in.

                maps/map.txt is the path to the file the program expects (and used as the argument to GameLoop). In this case, it's a relative path to your current working directory. This is what you would add to the 'Command line arguments' in QtCreator as mentioned above.

                1 Reply Last reply
                2
                • J Offline
                  J Offline
                  juve938383
                  wrote on last edited by
                  #7

                  Thanks a lot!! It is finally working! Wooohoo! Thank you for your patience, I know those may be basic stuff, but I am just a beginner.

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved