Results 1 to 7 of 7

Thread: Problem with if-condition and while loop

  1. #1
    Join Date
    Sep 2007
    Location
    Estonia
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Problem with if-condition and while loop

    'Ello.

    Code:
    program AutoTyper;
    
    var Speed: integer;
    var Output: string;
    
    begin
    
        Speed := 10; //Time between two outputs is calculated as Speed * 100 * Length(Output) / 10
        Output := 'This is a test!' + chr(13);
    
        while(true) do
        begin
            if IsFunctionKeyDown(0) then
                while(true) do
                begin
                    SendKeysWait(Output, 50, 10);
                    Wait(Speed * 100 * Length(Output) / 10);
                    if IsFunctionKeyDown(0) then
                       break;
                end;
        end;
    end.
    Problem is in inner loop, with break. Without break it repeatedly writes text as I want, but if I am using that break then it is working even if no Shift key is down anymore...
    It is my first script in SCAR and Pascal so don't be too evil.

    Please recommend workarounds or give some ideas about how to do it correctly.
    "Life and Death are partners, not enemys."
    By Repentinus

  2. #2
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I don't get what you're asking 100%. I can help you (probably) if you tell me exactly what you want this script to do.

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I think you need to add a not to your if statement that triggers the break, as I think what you want is to press shift, then it continues typing until you press shift again and that's what adding a not will do.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  4. #4
    Join Date
    Sep 2007
    Location
    Estonia
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    mixster got it right, thank you.
    "Life and Death are partners, not enemys."
    By Repentinus

  5. #5
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    SCAR Code:
    while(true) do
        begin
            if IsFunctionKeyDown(0) then
                while(true) do
                begin
                    SendKeysWait(Output, 50, 10);
                    Wait(Speed * 100 * Length(Output) / 10);
                    if IsFunctionKeyDown(1) then // just changed the key you press
                       break;
                end;
        end;

    you press te same key to start and o stop the loop. just press different keys and you'll stop having that problem.
    edit: nvm, didn't read properly. but this way you don't have to keep on pressing, and then just press a different key to stop

    btw in SRL we use TypeSend('text here') instead of SendKeys. and in TypeSend you don't need to include char 13. also it is more common to use Repeat Until(false) than while(True), but both work the same way and it's entirely up to you.

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  6. #6
    Join Date
    Sep 2007
    Location
    Estonia
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks, I used this two keys workaround but can someone explain why it do not work with one key. I just want understand, not blindly follow someone's directions. Thank you so much, guys.
    "Life and Death are partners, not enemys."
    By Repentinus

  7. #7
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    the reason why i told you to use two keys is because smart is very fast, and when you press down shift it'll start typing and sometimes it'll think you pressed the shift key again and stop.

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Loop
    By Ethan1221 in forum OSR Help
    Replies: 16
    Last Post: 12-22-2008, 05:31 PM
  2. Nooby Loop Problem :(
    By pianoman933 in forum OSR Help
    Replies: 2
    Last Post: 05-18-2008, 04:01 PM
  3. loop problem
    By drizzt in forum OSR Help
    Replies: 5
    Last Post: 02-16-2008, 12:30 AM
  4. Main Loop Problem
    By kryptonite in forum OSR Help
    Replies: 9
    Last Post: 07-25-2007, 02:22 PM
  5. Infite loop problem
    By twobac in forum OSR Help
    Replies: 6
    Last Post: 02-03-2007, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •