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

Author Topic: A little confused in the "Getting started" Tutorial  (Read 1041 times)

0 Members and 1 Guest are viewing this topic.

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
A little confused in the "Getting started" Tutorial
« on: October 08, 2012, 01:21:29 am »
http://sfml-dev.org/tutorials/2.0/start-vc.php

At the buttom of the page, the little test, i got everything to work.

But im confused about the nested while-loop

it looks like to me that the nested-while-loop is like an if-statement, because it go in and do the thing 1 single time, and then jump out of the loop again. I know it because i tested it with the cout thing inside the first while-loop, and it looped around 24/7.

Why not just make it to an if-statement? That would seem less confusing because then you know for sure it will do the statement 1 single time and jump out.

i actually tried to replace "while" with "if" and it worked perfectly, but why make it to a while-loop and why does it jump out?
« Last Edit: October 08, 2012, 01:30:06 am by Assassinbeast »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: A little confused in the "Getting started" Tutorial
« Reply #1 on: October 08, 2012, 01:44:03 am »
Yes it works as long as you really just get one event per iteration which is mostly not the case.
For example try to limit the framerate (window.setFramerateLimit(60) and then move your mouse around the screen or press some keys and move the mouse around simultaneously and you'll notice that more than one event is triggered within one iteration. Thus if that would happen constantly and you'd use an if-statement your event queue will slowly fill up (since you can only process one event ever iteration and every iteration two or more get added) and running your application long enough will eventually eat your whole memory and crash the application, also all the events would start to be extremely delayed.

Thus it's advised to use a while loop for polling events.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything