Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OCaml-保持一个可视计时器_Ocaml - Fatal编程技术网

OCaml-保持一个可视计时器

OCaml-保持一个可视计时器,ocaml,Ocaml,我正在用OCaml制作一个数独游戏 我正在尝试在顶部添加一个计时器,这样玩家可以看到他解数独需要多长时间。我环顾了一下四周,这张照片似乎就是我要找的 为了绘制计时器,我写了一个函数draw_time,函数的内容太长,不重要,但它有这样的结构: let rec hello () = Lwt.bind (Lwt_unix.sleep 14400.) (fun () -> print_endline "Hello, world !"; hello ()) Lwt.asy

我正在用OCaml制作一个数独游戏

我正在尝试在顶部添加一个计时器,这样玩家可以看到他解数独需要多长时间。我环顾了一下四周,这张照片似乎就是我要找的

为了绘制计时器,我写了一个函数draw_time,函数的内容太长,不重要,但它有这样的结构:

let rec hello () = 
    Lwt.bind (Lwt_unix.sleep 14400.) 
       (fun () -> print_endline "Hello, world !"; hello ())
Lwt.async (hello)
我已经对它进行了测试,它的功能确实可以正常工作

我的游戏的主循环如下所示:

let main_loop gs f_init f_end f_key f_mouse = 

    f_init;
        let timer = draw_time () in
        try 
            while true do
                try 
                    if gs.completed <> true then
                        let event = Graphics.wait_next_event event_types in
                            if event.Graphics.keypressed then 
                                f_key event.Graphics.key
                            else if event.Graphics.button then 
                                f_mouse event.Graphics.mouse_x event.Graphics.mouse_y               
                with 
                | _ -> raise End
            done
        with 
        | End  -> f_end () 
    ;;
让main_循环gs f_init f_end f_键f_鼠标=
f_init;
让定时器=绘制时间()
尝试
尽管如此
尝试
如果gs.completed为true,则
让event=Graphics.wait\u next\u事件\u输入
如果按event.Graphics.key,则
f_key event.Graphics.key
否则,如果event.Graphics.button
f_mouse event.Graphics.mouse_x event.Graphics.mouse_y
具有
|提升端
完成
具有
|结束->f_结束()
;;
这似乎不起作用。当我关闭窗口(和程序)时,程序只执行draw_time,而当窗口打开且计时器应该被绘制时,程序不执行draw_time


我到底做错了什么?

为了运行Lwt程序,您需要启动,它将处理您的线程

let () = Lwt_main.run (Lwt_io.printl "Hello, world!")
Lwt具有将Lwt主回路集成到Glib中的代码。但是,据我所知,图形模块并没有这样的集成


您可能会发现有趣的是,它是异步库的集成,非常接近Lwt和图形模块。它甚至在

中提到过,有点不明确,请给出
draw\u time
的定义。我认为不需要这样做,因为问题不在draw\u time。如果我打电话给你好而不是抽签时间,这是完全相同的问题。当我关闭程序时,程序开始每秒打印“Hello,world!”而不是在程序运行时。