GameLoop parameter
-
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!
-
@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.
-
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.
-
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?
-
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'
-
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.
-
@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.
-
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.