Bomberman - QTimer, QTimerEvent, Signals and Slots connection problems
-
Sorry, did you ever try to use your debugger?
This is not a signal-slot problem. Set a breakpoint in the slot routines and you will find out that the slots are called regularly. The counter "int element" is increased each time.
I guess you should either use the debugger or output statements to a file to find out if the program is doing as you expect. -
//Please read from the edit//
Umm... I don't know what are you talking to me about. How do I set a breakpoint in the slot routines? What is it? I'm using the debugger but it's running without errors. Sorry for lack in my knowledge but I'm still learning the QT. Actually I'm in the high school and It's my project for a 6 grade. We didn't have too much lessons with QT and almost all what I used I learnt from the tutorials on this page.
But back to topic:
Could you explain it in clearlier way, that I could understand? Maybe step-after-step? I don't have any idea how to set breakpoints...PS. Maybe we should change the channel of the communication? If u still want to help me. The forum isn't fast enough. I did not mention that I have to finish it by the end of May.
//edit
Hi Volker. Thanks for reply and for this load of useful advices. After reading this link I think I get your point. I'm just stressed and now I know - that's my problem.So I'll give some more details now:
I'm using:
Qt Creator 2.0.1
Based on Qt 4.7.0 (32 bit)Built on Aug 24 2010 at 11:00:55
I've read about the breakpoints and now I understand it. The loops, as you said are working properly, connects aren't the problem. The enemies are probably moving in the bomberfield.cpp but it's not transfered to the enemy.cpp. Their centers don't change so they don't change in the paintEvent as well and in effect don't move.
From what I learnt until now about connect() is that the signals' and slots' parameters must be the same. So how can I transfer the data from the:
@int curEnemyX[5];
int curEnemyY[5];@
in bomberfield.cpp to:
@QRect Enemy::enemyRect(){
QRect result(0, 0, 39, 39);
result.moveCenter(QPoint(curX, curY));
return result;
}@
in enemy.cpp every time the timeout() signal is called? -
[quote author="Jizin" date="1306086194"]
PS. Maybe we should change the channel of the communication? If u still want to help me. The forum isn't fast enough. I did not mention that I have to finish it by the end of May.[/quote]This statement will most likely drive you to the point where you get no answers at all and make everyone involved so far upset.
This forum (as many others too) is driven by volunteers. Requesting them to do things for you becaus you have a problem, is for sure one of the worst habits.
Make sure to behave friendly in a forum, for example read and understand http://www.catb.org/~esr/faqs/smart-questions.html
This is not an official support channel of Nokia and Digia. And if it was, you'd have to pay commercial support to actually request things.
-
Ok, I've thought about what you told me and I think I got the solution... I've finally made my enemies move, however it causes a lot of different and strange errors.
Here is the newest version of the project:
<problem solved, link deleted>This time I cannot isolate my problem, because it's a strange mix of everything I've made so far. So the enemies move only once, not in the loop. Furthermore now there are a lot of undefined, surprising connections. As example now the enemies move and sometimes:
- everything is alright,
- they disappear and do nothing more,
- they disappear and some of the obstacles as well,
- they are duplicating and 2 of them are reacting to the keyboard events: i press cursor key to move so one of them moves, I press another key and another one moves.
There are strange errors in the debuger as well. All of the problems appears randomly.
I think that the first issue (about only one move) is probably here:
@ void Enemy::moveEnemy(){
static int element = 0;
emit timerRunningFalse(element);
element++;
}
@
I need the element variable to know which enemy move, but after it increases up to 5 (all of the enemies move) it's not zeroed... Where should I put in it the 0 value?The other problems are about autoEnemyTimer[i] (which isn't stopped nowhere, so that can cause problems) and the obstacle[i]->existence variable. I first make enemies and then obstacles (because they're dependent on each other, and it was just easier to remember 5 enemies than ~150 obstacles), so they're maybe moving because the obstacle is made or the variable is set...
//edit
After some workout I finally made it. The problem was in the code I posted before. The element just increased without end and there are only 5 enemies. Adding this:
@if(element > 4) element = 0;@
solved everything. Now the enemies move continously and withing the area I set them (they don't go over the edges of map and on the obstacles). The next think I'm working on is a proper algorithm for moving (for now it's only randomizing only 1 of 4 possible directions, which makes it they barely move (goes one step right and one step left, up and down onto the same position). -
//Edit
I've just solved it... The timers' timeout() were connected to the moveEnemy() where the elements increased up until the 5, but if 1 is destroyed then it went through doing nothing just taking the time and slowing the rest. I used another variable:
@bool enemyExistence;@
And the moving and painting is done only if this variable is true. I left the autoEnemyTimers alone and everything works fine.Hi. I've encountered another strange problem. After making moving enemies everything went well. Up until I decided to add the option to destroy them with the bombs. Destroying one makes the rest slowing... I added proper conditions:
@for(int i = 0; i < numberEnemy; i++){
if(bomb->bombCenter.x() - 20 > curEnemyX[i] - 40 && bomb->bombCenter.x() - 20 < curEnemyX[i] + 40 && bomb->bombCenter.y() + 20 > curEnemyY[i] - 40 && bomb->bombCenter.y() + 20 < curEnemyY[i] + 40)
autoEnemyTimer[i]->stop();
}@
Stoping the timer makes them unable to move anymore. Furthermore I added the condition in paintEvent:
@for(int i = 0; i < numberEnemy; i++){
if(autoEnemyTimer[i]->isActive())
enemy[i]->paintEnemy(painter, curEnemyX[i], curEnemyY[i]);
}@
So they aren't painted when destroyed. And that all works. But here's the problem. When one of them is destroyed it doesn't move anymore and isn't painted as well. But the rest start moving slower... With 5 of them the speed is good, but when only 1 is left it moves really slow... I don't know what's causing this problem and how to fix it. I've the
@int autoEnemyTimer[5]@
and start them independently. And I'm using them like:
@for(int i = 0; i < numberEnemy; i++){
connect(autoEnemyTimer[i], SIGNAL(timeout()), enemy[i], SLOT(moveEnemy()));
connect(enemy[i], SIGNAL(randomEnemyDirection(int)), this, SLOT(randomEnemyDirection(int)));
}@
Anyone know why there are these undefined connections between different autoEnemyTimers timeout() signals? -
So, It's me again. I finally made my game to the state when it's playable. Everything works as it should, but I just encountered another strange error, this time with the .exe of my application. When I open the project normally with QT, compile and run, everything is ok, and looks like this:
"Good one":http://imageshack.us/photo/my-images/845/goodu.png/
And when i try to run the .exe it looks like this:
"Your text to link here...":http://imageshack.us/photo/my-images/829/badp.png/
At first it wanted some libraries: mingwm10.dll, libgcc_s_dw2-1.dll, msvcp71d.dll, msvcr71d.dll, QtCored4.dll, QtGuid4.dll but after I copied them to the folder the application finally executed but with the effect shown above.
I also tried the release (copied libraries as well) and the effect is same. What can cause this problem? -
After all I solved the problems myself, with help and useful advices of koahnig (really thanks for that!)... I left the interesting fragments (with the problems) and posted the solutions, so if anyone meets up with the same problem he'd probably read what he need, learn and correct. What's the point of posting here the whole source of the game? If u want to play it then I can upload the Release...