Sign in to follow this  
Followers 0
Diana (Cda)

Combining beep and sleep on one line, way to?

7 posts in this topic

I'm finding that beeps and sleep take up lots of lines. Taking a cue from other syntax, was hoping to find way to combine syntax on one line.

Just as an example, a long time ago I used to do this:

Send("text")

Send("{tab}")

Send("text")

Send("{tab}")

Send("text")

Send("{tab}")

because that's how I saw it one thread.

Some time later, I saw this format in another thread, which made life easier.:

Send("text{tab}text{tab}text{tab}")

Is there perhaps something similar, by adding code if need be, to do the same type of thing to this:

Beep(700,50)

Sleep(250)

Beep(700,50)

Sleep(250)

Beep(700,50)

Sleep(250)

Beep(700,50)

Sleep(250)

Beep(700,50)

Sleep(250)

I realize it's not the same type of thing at all but it would be of enormous help to have the beep and sleep commands on less lines by combining as much as will fit on any given line.

Thanks! :)

Share this post


Link to post
Share on other sites



Well... a loop?

Share this post


Link to post
Share on other sites

Well... a loop?

Dang, sorry. That's what I get for copy/pasting text <g>. No, a loop wouldn't work. Sorry I wasn't clear. My intention for one script is to use a beep song, but some of those can be very, very long. i.e., if the script were printed out, it would print on 2 or 3 pages.

No, I've seen in other scripting languages, though I am of course no expert, that code can sometimes be placed on one line with the right type of separator. Was looking for that type of solution here.

Thanks. :)

Share this post


Link to post
Share on other sites

Hello Diana (Cda),

I haven't some across such a separator. I hope I'm understanding your issue correctly when I suggest something like this:

Func BeepThenSleep( $tone, $duration, $sleeptime )
    Beep( $tone, $duration )
    Sleep( $sleeptime )
EndFunc

BeepThenSleep( 2000, 10, 250 )
BeepThenSleep( 3000, 10, 250 )
BeepThenSleep( 2000, 10, 250 )
BeepThenSleep( 3000, 10, 250 )

Or something like this:

Func PlayPhrase( $sPhrase )
    $aNotes = StringSplit( $sPhrase, "," )
    For $i = 1 to $aNotes[0]
        $aNoteData = StringSplit( $aNotes[$i], ":" )
        Beep( $aNoteData[1], $aNoteData[2] )
        Sleep( 250 )
    Next
EndFunc

; Phrase = "pitch:duration , pitch:duration, ... 
PlayPhrase( "2000:10,3000:10,4000:10,2000:50,3000:50,4000:50" )

Zach...

Share this post


Link to post
Share on other sites

Hello Diana (Cda),

I haven't some across such a separator. I hope I'm understanding your issue correctly when I suggest something like this:

Func BeepThenSleep( $tone, $duration, $sleeptime )
    Beep( $tone, $duration )
    Sleep( $sleeptime )
EndFunc

BeepThenSleep( 2000, 10, 250 )
BeepThenSleep( 3000, 10, 250 )
BeepThenSleep( 2000, 10, 250 )
BeepThenSleep( 3000, 10, 250 )

Or something like this:

Func PlayPhrase( $sPhrase )
    $aNotes = StringSplit( $sPhrase, "," )
    For $i = 1 to $aNotes[0]
        $aNoteData = StringSplit( $aNotes[$i], ":" )
        Beep( $aNoteData[1], $aNoteData[2] )
        Sleep( 250 )
    Next
EndFunc

; Phrase = "pitch:duration , pitch:duration, ... 
PlayPhrase( "2000:10,3000:10,4000:10,2000:50,3000:50,4000:50" )

Zach...

The 2nd one I'm having a bit of a time to wrap my brain around it <g>, but the first one I can understand and, yes, it will definitely be a major, major improvement! It's totally awesome.

(I feel like when Spock says of Khan how "betrays his 2-dimension thinking" in a world that deals in 3-dimensional space. I'm going to have to learn to work with variables, I believe they're called? They're coming in handy lately as many people lately have used syntax that uses them. Wow.)

Thanks! Will put this to work. :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yeah. Variables.

He also uses functions. I would think you'd learn variables before functions, but I'm also used to learning programming in classrooms ;p

Anyway, I'll try to explain his second code snippet..here's the whole thing.

Func PlayPhrase( $sPhrase )
    $aNotes = StringSplit( $sPhrase, "," )
    For $i = 1 to $aNotes[0]
        $aNoteData = StringSplit( $aNotes[$i], ":" )
        Beep( $aNoteData[1], $aNoteData[2] )
        Sleep( 250 )
    Next
EndFunc

Wow, I just realized he gave an example. I feel dumb. Anyway, so you'd write in your code:

PlayPhrase( "2000:10,3000:10,4000:10,2000:50,3000:50,4000:50" );

and ..uhh..

You know what? I'd just try it, because I'm confused. I need to sober up, tell me if you don't figure it out laugh.gif

Edited by Nevin

Share this post


Link to post
Share on other sites

Awesome, thank you! Lot to take in but it helps to know these things now. Re the arrays vs variables and order to learn, well, that's the trouble with being a noob to all intents and purposes <g>. Don't know any better. Despite the time I've been using AI, a lot of the terms are still words to me. Though I'm making great strides lately.

Thanks again! :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0