Author Topic: SLEEP works bad under QB64 1.5 32bit  (Read 2165 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
SLEEP works bad under QB64 1.5 32bit
« on: June 29, 2020, 10:03:54 am »
Hi. SLEEP used with $CONSOLE:ONLY  and then _DEST _CONSOLE stop program work in QB64 1.5 32bit, version b5e896d

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: SLEEP works bad under QB64 1.5 32bit
« Reply #1 on: June 29, 2020, 05:41:04 pm »
Yep -- it should, and this isn't a bug with SLEEP. 

(And I can hear it now -- "What the flock?!  Has Steve finally went crazy??!")

Nope.  I haven't. 

I imagine your program looked something similar to the following: 
Code: QB64: [Select]

At which point, your program can now compile, freeze up, and do absolutely nothing for you...

"And how is this not a bug with SLEEP??"  (I can hear the confused shout all the way here at my house already!)

It's because you haven't set the _SOURCE to your program yet.

I'd like to have $CONSOLE:ONLY automatically default to a _DEST _CONSOLE: _SOURCE _CONSOLE, but I haven't sorted out how the heck to have QB64 do that for us yet -- which is why you need that _DEST _CONSOLE to print to the console.  By the same token, you need a _SOURCE _CONSOLE to read input from that console...

Without _SOURCE _CONSOLE, your program ends up waiting for a keypress from the non-existent main program window -- and thus it just sits there and does nothing, as the above program so aptly demonstrates. 

Try this code instead:
Code: QB64: [Select]

Viola!  It works as it should.  ;)



Since $CONSOLE can be used with a main program window, you need to set the _SOURCE for where you're getting input from.  (Which oddly enough, you don't have to do with INPUT, as it somehow works with _DEST and not _SOURCE, as you'd expect.  Perhaps because it can also print to the screen??)


Isn't programming lovely with how inconsistent syntax reacts?  SLEEP reads input based on the _SOURCE... INPUT reads input based on the _DEST...  And it all just leads to folks scratching their heads and saying, "What the flock??!  Now I see why poor Steve is as crazy as he is!"...



Anywho, that should address the issue -- unless I'm talking out my rear again and completely missed the problem.  If it still doesn't work as you'd expect, with the _SOURCE set, post me some code and explain the issue to me again in a little better detail, and I'll dig into whatever the heck it is I've overlooked again. 

(Another possible issue to keep in mind is:  Many of the console commands are Windows-only, as I don't have a Linux/Mac rig dedicated to test things, so I only pushed the changes to the windows side of things.  If you're running under Linux/Mac, I doubt SLEEP will work for you, no matter what you try.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: SLEEP works bad under QB64 1.5 32bit
« Reply #2 on: July 02, 2020, 03:12:27 pm »
Hi Steve,

Thank you for the detailed analysis of the problem. It was in Windows. Importantly, there is a _SOURCE solution. Would it not be possible to connect the _SOURCE link directly to the C program for _CONSOLE? Of course, I have no idea how difficult it could be.