Jump to content

Ternary line for GUI loop?


Go to solution Solved by Werty,

Recommended Posts

Hello,

Just to keep the GUI open after doing stuff, I need to rerun a basic GUI loop.

As an alternative to a Do/Until, I tried a ternary one-liner, but AutoIt doesn't like the syntax:

;So the app doesn't close after the for loop
;~ Do
;~     Sleep(10)
;~ Until GUIGetMsg() = $GUI_EVENT_CLOSE
;BAD (GUIGetMsg() = $GUI_EVENT_CLOSE) ? (Exit) : (Sleep(10))
;BAD GUIGetMsg() = $GUI_EVENT_CLOSE ? Exit : Sleep(10)

Is that syntax just impossible?

Thank you.

Edited by littlebigman
Link to comment
Share on other sites

  • Developers
21 minutes ago, littlebigman said:

Is that syntax just impossible?

Not impossible, but for starters: Why do you think that a one line If or  Ternary can replace a loop?
You only test one time this way!

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hmm, according to "Oscar" on the german autoit forum, a guy worth listening to,  the sleep isnt even necesary when using GuiGetMsg()...

GUIGetMsg automatically creates sleeps (without mouse movement/keystrokes) to reduce the load on the processor.

https://autoit.de/thread/88029-matrix-falling-code/?postID=710746#post710746

So...

While GuiGetMsg()<>-3
WEnd

...should be enough.

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

  • Developers

Guess Oscar read the helpfile as it is clearly defined how a msg loop works and no sleep() is needed : https://www.autoitscript.com/autoit3/docs/guiref/GUIRef_MessageLoopMode.htm

It is actually discouraged to add any sleep(). 😉

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

26 minutes ago, Jos said:

It is actually discouraged to add any sleep(). 😉

Just to prevent the GUI being unresponsive but this won't happen if you sleep just a few ms. I think for most people it's a habit to use the sleep in main loop. I know for years that GUIGetMsg() automatically idles the CPU and yet I still use that sleep most of the time. :rolleyes:

When the words fail... music speaks.

Link to comment
Share on other sites

  • Solution
1 hour ago, Jos said:

Guess Oscar read the helpfile as it is clearly defined how a msg loop works and no sleep() is needed : https://www.autoitscript.com/autoit3/docs/guiref/GUIRef_MessageLoopMode.htm

It is actually discouraged to add any sleep(). 😉

yes, but you are aware of how many people actually reads the helpfile. :)

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

  • Developers
1 minute ago, Werty said:

yes, but you are aware of how many people actually reads the helpfile. :)

Hardly anybody actually reads the whole page ever.... Only a few open it.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...