So I went through one of my programs and used alternatives. However there are a couple of statements relating to a timer that I think should be left as if's. Just wondering what you guys think and if there are any better alternatives.
I have a key press capture event within draw actor. There is a timer between each key press to make a delay to prevent the key being repeated.
The key press is caught in a function called InputText() this returns an integer of 1 or 0 to say if there had been a key press . I was saying if (InputText ==1 ) set timer but now I just say
- Code: Select all
Timer = InputText(text,30)*5; //5 is the value of the timer
I aslo got rid of if(timer>0)timer--; bit by using
- Code: Select all
Timer = max(--Timer,0);
Now the one I cant get rid of. When the Timer is 0 and when the text entry box is ready for an input I have
- Code: Select all
if(Timer<=0 && BInputReady)
{
Timer =InputText(text,30)*5;
}
There is also a seperate key capture event for when the enter key is pressed. The Return key does not rely on the key delay but it does rely on the BInputReady boolean
- Code: Select all
if (key[KEY_RETURN] && BInputReady)
{Do stuff}
The only thing that I think I could do to make it better is to have
- Code: Select all
switch (BInputReady)
{
case 1: if(Timer<=0) {do stuff}
if (key[KEY_RETURN]{do stuff}
break;
default:{Error Trap Break} break;
}
Any other ways of doing this that would be better?