首页 > 解决方案 > 如何修复此 gnuplot 错误以处理按键?

问题描述

我正在尝试为我的 gnuplot 脚本提供基本的键盘交互。我相信我使用gnuplot 5.4 patchlevel 1的是 MOUSE_CHAR 作为记录,但是使用下面最简单的脚本,无论我按什么键,我都会收到错误消息。

while (1) {
    pause mouse keypress
    show variable MOUSE_

    if (exists("MOUSE_CHAR")) {
        if (MOUSE_CHAR == "w") {
            print "w"
        }
    }             # <-- line 114

    replot
}

输出显示按下了正确的键,例如:

        MOUSE_KEY = 119
        MOUSE_CHAR = "w"

或者

        MOUSE_KEY = 114
        MOUSE_CHAR = "r"

但是在我得到之后

"hrtp.gp" line 114: Non-numeric string found where a numeric expression was expected

标签: keyboardgnuplotmousenumeric

解决方案


字符串相等的测试eq不是==,所以你想要if (MOUSE_CHAR eq "w") { print "w" }


推荐阅读