I'm a newbie here. But I saw this topic by chance, and I've seen the problem here. Your code didn't work because your Direct X had not ready yet.

Try to put these lines in your code:
.....
video_screen = 2;
video_mode = 8;

//put these lines in your code:
level_load("");
wait(2);

on_esc = NULL;
.....

Your code will run correctly.

Thanks for paying attention to me.