IsKeydown in scar

Discussion in 'Code Snippets and Tutorials' started by 333, Apr 7, 2007.

Thread Status:
Not open for further replies.
  1. 333

    333 Newbie

    Joined:
    Apr 4, 2007
    Messages:
    6
    Likes Received:
    0
    How would you write Scar script that will print a message when you hit space.

    I've done this:

    if IsKeyDown(32) then
    Writeln 'You have pressed space!';

    But I don't know why it comes up with an error.
     
  2. zav75

    zav75 Level I

    Joined:
    Feb 28, 2007
    Messages:
    76
    Likes Received:
    6
    Location:
    Canada, Province of Québec
    ok maybe this code example could help

    Code (Text):
    1. program Example;
    2.  
    3.  
    4. begin
    5.      while(not IsKeyDown('q') )do
    6.      begin
    7.           if( IsKeyDown(' ') )then
    8.           begin
    9.           Writeln('You have pressed space!');
    10.           wait(15);
    11.           end;
    12.      end;
    13. end.
    ^^

    the iskeydown need and char between ' ', as 'a', space is ' ' character
     
  3. marlene

    marlene Moderator
    Staff Member

    Joined:
    Dec 23, 2006
    Messages:
    1,492
    Likes Received:
    12
    Location:
    Somewhere under the Rainbow (Montreal)
    Great example zav...

    you might want to change the wait time to:

    Code (Text):
    1. wait(1000);
    otherwise just pressing the key might return a lot of "You have pressed space"
     
  4. zav75

    zav75 Level I

    Joined:
    Feb 28, 2007
    Messages:
    76
    Likes Received:
    6
    Location:
    Canada, Province of Québec
    I like it when It spams :D
     
  5. Dusk412

    Dusk412 Level I

    Joined:
    Aug 2, 2008
    Messages:
    88
    Likes Received:
    9
    First, you want to have a repeat and until around it so that it will check over and over. Otherwise the script will check once, if it isn't down at that exact moment, no message. Second of all, can you please post the error?
     
Thread Status:
Not open for further replies.