Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Event::Closed problem  (Read 5124 times)

0 Members and 1 Guest are viewing this topic.

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Event::Closed problem
« on: April 23, 2010, 01:06:25 am »
Hey,

In my project I have 3 Main screens: Menu, The game itself and ScoreBoard.
Now the problem is that when i run the Scoreboard function which draws the ScoreBoard, I noticed that the condition 'Event.Type == Event::Closed' is executed while I didn't close the Window. But with the Menu it doesn't happen.
Any sugestions?

Code: [Select]

bool Menu(sf::RenderWindow &Window);
bool ScoreBoard(sf::RenderWindow &Window);

if (ScoreBoard(Window))
return 0;
if (Menu(Window))
return 0;

//both Menu and ScoreBoard Event loop
while (Window.GetEvent(Event));
{
gui.ProcessKeys(&Event); //only ScoreBoard has this line
if (Event.Type == Event::Closed)
return true;
}
while (!idle)
{
   DoSomething();
}

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Event::Closed problem
« Reply #1 on: April 23, 2010, 01:22:53 am »
My first instinct says that gui::ProcessKeys() does something to Event...

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Event::Closed problem
« Reply #2 on: April 23, 2010, 02:35:38 pm »
Nop, it isnt because of that line, i commented that line and still the same problem. Well i did a breakpoint in the initialization of the Event variavel and its skips the init., and the Event.Type is Closed while i did nothing. :oops:
while (!idle)
{
   DoSomething();
}

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Event::Closed problem
« Reply #3 on: April 23, 2010, 02:57:35 pm »
Can you show more code of this part ?
and some code of other (menu and game) ?
Mindiell
----

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Event::Closed problem
« Reply #4 on: April 23, 2010, 06:18:31 pm »
Here it goes

Main.cpp
Code: [Select]
cp::cpGuiContainer gui;

cp::cpButton buttonok(&Window, &gui, "Aceitar", (input.GetPosition().x + (input.GetSize().x / 2) - 50 ), (input.GetPosition().y + input.GetSize().y + 10), 100, 50);

if(buttonok.CheckState(&Window.GetInput()) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
{
player1.Nick = input.GetLabelText();
Window.ShowMouseCursor(true);
if (ScoreBoard(Window))
return 0;
if (Menu(Window))
return 0;
Initialize(balloon, object, hand, time, player1.SScore, player1.Score, buttonok, input);

}


Menu.cpp
Code: [Select]
while (Window.IsOpened())
{
Event Event;

//Update
while (Window.GetEvent(Event));
{
if (Event.Type == Event::Closed)
return true;
         ...
      }
   }


ScoreBoard.cpp
Code: [Select]
cp::cpGuiContainer Gui;

cp::cpButton button1(&Window, &Gui, "MENU", 512 - 42, 600, 100, 50);
cp::cpButton button2(&Window, &Gui, "FTP", 600, 600, 100, 50);

//main loop
while (Window.IsOpened())
{
Event Event;
//Update
while (Window.GetEvent(Event));
{

//Gui.ProcessKeys(&Event);
if (Event.Type == Event::Closed)
return true;
}

if(button1.CheckState(&Window.GetInput()) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
{
return false;
}
if(button2.CheckState(&Window.GetInput()) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
{
FTPserver();
}
}
while (!idle)
{
   DoSomething();
}

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Event::Closed problem
« Reply #5 on: April 23, 2010, 06:33:25 pm »
Why Event.Type is Closed after being initialized?
while (!idle)
{
   DoSomething();
}

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Event::Closed problem
« Reply #6 on: April 23, 2010, 08:29:19 pm »
Code: [Select]
while (Window.GetEvent(Event));
What is that semicolon at the end of the line? ;)

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Event::Closed problem
« Reply #7 on: April 23, 2010, 08:35:30 pm »
LOL, Epic Mistake :lol:
I had that error in the Menu, and the same happened to him when i call him in the game loop.

Sorry for this stupid error, i didn't noticed it :roll:
Thank you very much :D  :wink:
while (!idle)
{
   DoSomething();
}

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Event::Closed problem
« Reply #8 on: April 23, 2010, 09:58:54 pm »
Second thing, if I were you I will really not use such a CamelCase with those names : Event and Event, it can be very confusing ;)
Mindiell
----

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Event::Closed problem
« Reply #9 on: April 23, 2010, 10:14:01 pm »
Quote from: "led"
Sorry for this stupid error, i didn't noticed it :roll:
Thank you very much :D  :wink:


We are all humans :D
And I agree to Mindiell. Well, there are a lot of naming conventions out there. http://geosoft.no/development/cppstyle.html This is the one I use (except that private members have a "my... " prefix instead), but feel free to google yourself one ;) It really improves readability, so it is more likely other programmers will help you. Good luck on the project ;)

(Btw, this CamelCase appears in SFML tutorials, I guess led took from there... am I right?)

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Event::Closed problem
« Reply #10 on: April 24, 2010, 01:33:36 pm »
Yes your right :wink:
while (!idle)
{
   DoSomething();
}

 

anything