Rick Posted December 31, 2009 Share Posted December 31, 2009 I can't figure out what I'm doing wrong here. In an object I set "quit" to "true" when I press a key, yet the below never breaks the loop SetGlobalString("quit", "false") while (KeyHit(KEY_ESCAPE) == 0) or (GetGlobalString("quit") == "false") do fw:Update() fw:Render() Flip(0) end Yet this works, which is telling me that the object that I check for a keypress and set "quit" to "true" is working. So why doesn't it work in the above code? SetGlobalString("quit", "false") while (GetGlobalString("quit") == "false") do fw:Update() fw:Render() Flip(0) end Quote Link to comment Share on other sites More sharing options...
Niosop Posted December 31, 2009 Share Posted December 31, 2009 You're using an OR instead of an AND? Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
macklebee Posted December 31, 2009 Share Posted December 31, 2009 Lua handles logical operators different than what you are probably used to... The or binary operator also does not necessarily return a boolean value. If the first argument is not false or nil it is returned, otherwise the second argument is returned. So, a boolean is only returned if the first argument is true or the second argument is a boolean. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
TylerH Posted December 31, 2009 Share Posted December 31, 2009 No, he really needs an AND in there. No matter what his GetGlobalString("quit") == "false" comparison is, the KeyHit(KEY_ESCAPE) == 0 is always true, so the or never goes any further. Hence why it works without the KeyHit test. Use an and and all will be fine. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
macklebee Posted December 31, 2009 Share Posted December 31, 2009 No, he really needs an AND in there. No matter what his GetGlobalString("quit") == "false" comparison is, the KeyHit(KEY_ESCAPE) == 0 is always true, so the or never goes any further. Hence why it works without the KeyHit test. Use an and and all will be fine. yes, wasn't saying that it wasn't... was explaining the use of OR in lua Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
TylerH Posted December 31, 2009 Share Posted December 31, 2009 The use of OR in lua seems the same as using || in C++. Lua supports both logical OR and bitwise OR, but using the same 'or' keyword. No confusion at all there Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rick Posted December 31, 2009 Author Share Posted December 31, 2009 Bah. Duh. I just wrote it out in true or false and realized it. I swear when I get into a new language the most basic things escape me sometimes. I need to just go to sleep. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.