Re: esc detector wont run -- 'out of scope'
Clangray <[email protected]> Sat, 18 Mar 2017 13:57:35 -0400
| Newsgroups | gmane.comp.lib.sdl |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --===============3559330949830302212== Content-Transfer-Encoding: 7bit Content-Type: multipart/alternative; boundary="_----------=_14898598556794120" This is a multi-part message in MIME format. --_----------=_14898598556794120 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" Thx. Its infinite only under certain circumstances, which is confounding. What are you seeing and how can I fix it. If I use "if": if (SDL_PollEvent(&event)) its not infinite if I use while while(SDL_PollEvent(&event)) if is flag 2, flag 2 ad infinitum *Does the window have to be in the loop to get the benefit of the key stroke?* -- Gray Family [email protected] On Sat, Mar 18, 2017, at 01:32 PM, Jonathan Dearborn wrote: > As typed, your `while(event.type == SDL_KEYDOWN)` is an infinite loop. > > Jonny D > > > On Sat, Mar 18, 2017 at 1:23 PM, Clangray > <[email protected]> wrote: >> __ >> Ok, I introduced a window >> >> >> #include"SDL.h" >> using namespace std; >> >> >> const char* WINDOW_TITLE = "SDL Start"; >> >> int main(int argc, char **argv) >> { >> >> SDL_Init(SDL_INIT_EVERYTHING); >> >> SDL_Window * window = nullptr; >> window = SDL_CreateWindow("Hello World!", >> SDL_WINDOWPOS_CENTERED, >> SDL_WINDOWPOS_CENTERED, >> 640,480, >> SDL_WINDOW_SHOWN); >> >> SDL_Delay(2000); // Delay so that we can see the >> >> SDL_Event event; >> >> cout<<"flag 0"; >> >> >> bool gameRunning = true; >> >> while (gameRunning) >> { >> >> cout<<"flag 1"<<endl; >> while (SDL_PollEvent(&event)) >> { >> gameRunning = false; >> >> cout<<"flag 2"; >> if (event.type == SDL_QUIT) >> { >> cout<<"flag 3"; >> gameRunning = false; >> } >> >> >> while (event.type == SDL_KEYDOWN) >> { >> cout<<"flag 2"; >> SDL_Keycode keyPressed = event.key.keysym.sym; >> >> >> switch (keyPressed) >> { >> case SDLK_ESCAPE: >> gameRunning = false; >> break; >> } >> } >> >> } >> >> } >> >> >> SDL_Quit(); >> >> cout<<endl<<"end flag"; >> return 0; >> >> >> >> } >> >> I'm getting flag2 constantly. >> Esc and other keys seem to have no effect >> >> **if I substitute if for while (below) >> >> change while back to if >> if (SDL_PollEvent(&event)) >> >> output: >> >> flag 0flag 1 >> flag 2 >> end flag >> >> >> -- >> Gray Family >> [email protected] >> >> >> >> On Sat, Mar 18, 2017, at 12:44 PM, Brian Puthuff wrote: >>> I agree also. I thought there was some caveat that you needed a >>> window open to receive input events. >>> >>> >>> On Mar 18, 2017 9:17 AM, "DLudwig" <[email protected]> wrote: >>>> __ >>>> >>>> >>>> >>>> capehill wrote: >>>> >>>> >>>> Do you have a window open? Does Control-C work? >>>> >>>> >>>> >>>> >>>> I'd like to second the above. >>>> >>>> Many platforms need a window open, before input can be received. >>>> Using either SDL_CreateWindowAndRenderer, or just SDL_CreateWindow, >>>> once beforehand at app init, may be sufficient to fix this. >>>> >>>> -- David L. >>>> >>>> _______________________________________________ >>>> SDL mailing list >>>> [email protected] >>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org >>>> >>> _________________________________________________ >>> SDL mailing list >>> [email protected] >>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org >> >> >> _______________________________________________ >> SDL mailing list >> [email protected] >> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org >> > _________________________________________________ > SDL mailing list > [email protected] > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org --_----------=_14898598556794120 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset="utf-8" <!DOCTYPE html> <html> <head> <title></title> </head> <body><div>Thx. Its infinite only under certain circumstances, which is confounding. What are you seeing and how can I fix it.</div> <div>If I use "if":<br></div> <div><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">if (SDL_PollEvent(&event))<br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">its not infinite<br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">if I use while<br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">while(SDL_PollEvent(&event))<br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">if is<br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">flag 2, flag 2 ad infinitum<br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><b>Does the window have to be in the loop to get the benefit of the key stroke?</b></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(31, 31, 31); font-family: "Source Sans Pro", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.1px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><br></div> <div><br></div> <div><br></div> <div id="sig43414442"><div class="signature">--<br></div> <div class="signature"> Gray Family<br></div> <div class="signature"> [email protected]<br></div> <div class="signature"><br></div> </div> <div><br></div> <div><br></div> <div>On Sat, Mar 18, 2017, at 01:32 PM, Jonathan Dearborn wrote:<br></div> <blockquote type="cite"><div dir="ltr"><div>As typed, your `while(event.type == SDL_KEYDOWN)` is an infinite loop.<br></div> <div><br></div> <div>Jonny D<br></div> <div><br></div> </div> <div><div><br></div> <div defang_data-gmailquote="yes"><div>On Sat, Mar 18, 2017 at 1:23 PM, Clangray <span dir="ltr"><<a href="mailto:[email protected]">[email protected]</a>></span> wrote:<br></div> <blockquote defang_data-gmailquote="yes" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204, 204, 204);padding-left:1ex;"><div><u></u><br></div> <div><div>Ok, I introduced a window<br></div> <div><span></span><br></div> <div><span></span><br></div> <div><span>#include"SDL.h" </span><br></div> <div><span>using namespace std;</span><br></div> <div><span></span><br></div> <div><span></span><span></span><br></div> <div><span>const char* WINDOW_TITLE = "SDL Start";</span><br></div> <div><span></span><br></div> <div><span>int main(int argc, char **argv)</span><br></div> <div><span>{</span><br></div> <div><span></span><br></div> <div>SDL_Init(SDL_INIT_EVERYTHING);<br></div> <div><br></div> <div>SDL_Window * window = nullptr;<br></div> <div> window = SDL_CreateWindow("Hello World!",<br></div> <div> <wbr> SDL_WINDOWPOS_CENTERED,<br></div> <div> <wbr> SDL_WINDOWPOS_CENTERED,<br></div> <div> <wbr> 640,480,<br></div> <div> <wbr> SDL_WINDOW_SHOWN);<br></div> <div><br></div> <div> SDL_Delay(2000); // Delay so that we can see the<br></div> <div><br></div> <div>SDL_Event event;<br></div> <div><br></div> <div>cout<<"flag 0";<br></div> <div><span></span><br></div> <div><span></span><br></div> <div><span> bool gameRunning = true;</span><br></div> <div><span></span><br></div> <div><span> while (gameRunning)</span><br></div> <div><span> {</span><br></div> <div><span></span><br></div> <div> cout<<"flag 1"<<endl;<br></div> <div> while (SDL_PollEvent(&event))<br></div> <div> {<br></div> <div> gameRunning = false;<br></div> <div><span></span><br></div> <div><span> cout<<"flag 2";</span><br></div> <div><span> if (event.type == SDL_QUIT)</span><br></div> <div><span> {</span><br></div> <div><span> cout<<"flag 3";</span><br></div> <div><span> gameRunning = false;</span><br></div> <div><span> }</span><br></div> <div><span></span><br></div> <div><span></span><br></div> <div> while (event.type == SDL_KEYDOWN)<br></div> <div> {<br></div> <div> cout<<"flag 2";<br></div> <div> SDL_Keycode keyPressed = event.key.keysym.sym;<br></div> <div><span></span><br></div> <div><span></span><br></div> <div><span> switch (keyPressed)</span><br></div> <div><span> {</span><br></div> <div><span> case SDLK_ESCAPE:</span><br></div> <div><span> gameRunning = false;</span><br></div> <div><span> break;</span><br></div> <div><span> }</span><br></div> <div><span> }</span><br></div> <div><span></span><br></div> <div><span> }</span><br></div> <div><span></span><br></div> <div><span> }</span><br></div> <div><span></span><br></div> <div><span></span><br></div> <div> SDL_Quit();<br></div> <div><br></div> <div> cout<<endl<<"end flag";<br></div> <div> return 0;<br></div> <div><br></div> <div><br></div> <div><br></div> <div>}<br></div> <div><br></div> <div>I'm getting flag2 constantly.<br></div> <div>Esc and other keys seem to have no effect<br></div> <div><br></div> <div>**if I substitute if for while (below)<br></div> <div><br></div> <div>change while back to if<br></div> <div>if (SDL_PollEvent(&event))<br></div> <div><br></div> <div>output:<br></div> <div><br></div> <div>flag 0flag 1 <br></div> <div>flag 2<br></div> <div>end flag<br></div> <div><br></div> <div><br></div> <div><div>--<br></div> <div> Gray Family<br></div> <div> <a href="mailto:[email protected]">[email protected]</a><br></div> <div><br></div> </div> <div><div><div><br></div> <div><br></div> <div>On Sat, Mar 18, 2017, at 12:44 PM, Brian Puthuff wrote:<br></div> <blockquote type="cite"><div><div>I agree also. I thought there was some caveat that you needed a window open to receive input events.<br></div> <div><div><br></div> <div><div><br></div> <div><div>On Mar 18, 2017 9:17 AM, "DLudwig" <<a href="mailto:[email protected]">[email protected]</a>> wrote:<br></div> <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204, 204, 204);padding-left:1ex;"><div><u></u><br></div> <div><div><div align="center"><div><br></div> <div><br></div> <table width="90%" align="center" cellspacing="1" cellpadding="2" border="0"><tbody><tr><td><br></td></tr><tr><td align="left">capehill wrote:<br></td><td><br></td></tr><tr><td><br></td></tr><tr><td align="left">Do you have a window open? Does Control-C work?<br></td><td><br></td></tr><tr><td><br></td></tr></tbody></table></div> <div><br></div> <div><br></div> <div>I'd like to second the above.<br></div> <div><br></div> <div>Many platforms need a window open, before input can be received. Using either SDL_CreateWindowAndRenderer, or just SDL_CreateWindow, once beforehand at app init, may be sufficient to fix this.<br></div> <div><br></div> <div>-- David L.<br></div> </div> </div> <div><br></div> <div>______________________________<wbr>_________________<br></div> <div>SDL mailing list<br></div> <div><a href="mailto:[email protected]">[email protected]</a><br></div> <div><a href="http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org">http://lists.libsdl.org/listin<wbr>fo.cgi/sdl-libsdl.org</a><br></div> <div><br></div> </blockquote></div> </div> </div> </div> <div><u>______________________________<wbr>_________________</u><br></div> <div>SDL mailing list<br></div> <div><a href="mailto:[email protected]">[email protected]</a><br></div> <div><a href="http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org">http://lists.libsdl.org/<wbr>listinfo.cgi/sdl-libsdl.org</a><br></div> </blockquote><div><br></div> </div> </div> </div> <div><br></div> <div>______________________________<wbr>_________________<br></div> <div> SDL mailing list<br></div> <div> <a href="mailto:[email protected]">[email protected]</a><br></div> <div> <a href="http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org">http://lists.libsdl.org/<wbr>listinfo.cgi/sdl-libsdl.org</a><br></div> <div> <br></div> </blockquote></div> </div> <div><u>_______________________________________________</u><br></div> <div>SDL mailing list<br></div> <div><a href="mailto:[email protected]">[email protected]</a><br></div> <div><a href="http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org">http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org</a><br></div> </blockquote><div><br></div> </body> </html> --_----------=_14898598556794120-- --===============3559330949830302212== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ SDL mailing list [email protected] http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org --===============3559330949830302212==--