Why it doesnt work?

Started by mnm, April 22, 2011, 06:45:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mnm

Hello,

Does anyone know why this little thing doesnt work?

Quote
program test;
global
   var;
begin

   set_mode(320,200,32);
   var=1;

   loop
   
      if(key(_down) and var==1)
delete_text(all_text);
write(0,100,100,4,"AAA");
var=2;
      end      
      
      if(key(_down) and var==2)
delete_text(all_text);
write(0,100,100,4,"BBB");
var=1;

      end
      
       frame;
   end
end

It only works when the keys are not the same (like _down and _up for exemple).
But when it's set on key(_down) for both it doesnt work, why?  :)

handsource-dyko

It does work, but the input isn't buffered. Basically it executes really fast, so you need to delay the keypress. Try his:



program test;
global
    var;
begin

    set_mode(320,200,32);
   var=1;

    loop
   
      if (key(_down) and var==1)
         frame(500);
         delete_text(all_text);
         write(0,100,100,4,"AAA");
         var=2;
     end     
     
     if (key(_down) and var==2)
        frame(500);
        delete_text(all_text);
        write(0,100,100,4,"BBB");
        var=1;

    end
     
        frame;
    end
end


The additional frame statement delays the keypress, now it should work.

mnm

yes it works that way, thank you.