【问题标题】:Invalid Syntax Error Script [closed]无效的语法错误脚本[关闭]
【发布时间】:2017-05-25 13:54:09
【问题描述】:

我和我的朋友制作了一个机器人来玩游戏,但是当我们尝试运行它时,它显示无效语法。我们对 Python 了解不多,我想请教更有经验的人。 这是脚本:

#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <sys/time.h>

using namespace std;

int main() {
    POINT p;
    POINT coords[4];
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    printf("Move cursor to following tiles and press enter to select the coordinates:\n\n");

    for(int i = 0; i < 4; i++) {
        printf("%i. tile:", (i+1));
        getchar();
        GetCursorPos(&p);
        coords[i] = p;
        printf("- X: %d, Y: %d\n\n", p.x, p.y);
    }

    COLORREF currColor;
    HDC dc = GetDC(NULL);
    while(true) {
        if(GetAsyncKeyState(VK_ESCAPE)) {
            printf("\rPaused, press ENTER to continue ...");
            getchar();
            printf("Continue ...\n\n");
        }
        bool countFound = 0;
        for(int i = 0; i < 4; i++) {
            COLORREF color = GetPixel(dc, coords[i].x, coords[i].y);


            if(color <= 3000000) {
                printf("\r");

                for(int j = 0; j < i; j++) {
                    printf("[ ] ");
                }
                printf("[X] ");
                for(int j = 0; j < (3-i); j++) {
                    printf("[ ] ");
                }

                mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                SetCursorPos(coords[i].x, coords[i].y);
                mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                if(color > 100000) {
                    Sleep(50);
                } else {
                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                }
            }
        }
    }
    ReleaseDC(NULL, dc);

    return 0;
}

提前谢谢你!

【问题讨论】:

  • 那是 C++,不是 Python。难怪你会遇到语法错误......
  • 那不是 Python 脚本,它是 C++。难怪它在 Python 下不起作用。
  • "Me and my friends made a bot" 不,你没有。您从互联网上下载了一些随机代码,甚至不了解 它是用什么语言编写的 并盲目地尝试运行它。这就是您传播病毒和破坏计算机的方式。请从这个小插曲中学习 - 并非所有在线代码都是它所说的那样。
  • 另外,补充一点@MattDMo 已经说过的内容,这甚至不像机器人的代码看起来。这看起来像与图形相关的代码。你们真的应该更加小心。

标签: python


【解决方案1】:

这不是 Python。这实际上是 C++ 代码。您没有发布错误,所以我不得不假设您尝试将此代码作为 Python 执行,这显然是您的问题。如果你误将其称为 Python,而实际上出现了 C++ 错误,请发布错误。

【讨论】:

  • 非常感谢!
  • 当然!如果您的问题已解决,请务必将此标记为正确答案,以便人们知道问题已结束。
猜你喜欢
  • 2021-07-20
  • 2020-07-02
  • 2015-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
相关资源
最近更新 更多