Key mobile phone assistant! Urgent. Can only execute the first subroutine on the penalty station, debugging no problem.

evan5202012 注册会员
2023-02-28 21:44

The code seems to be fine, I recommend checking if the emulator supports continuous script execution and if there are any related Settings that need to be changed

cxmingko 注册会员
2023-02-28 21:44

Code check many times, for everyone to give the opinion also made a lot of changes and try, the result is the same. With the mobile version and PC emulator debugging, everything can be implemented smoothly. However, only the first subroutine can be executed after the Sprite is generated. Very speechless.

coolsubo 注册会员
2023-02-28 21:44

Hello, regarding your question that the key phone assistant can only run the first subroutine.
First of all, make sure that your program is correct before generating the elf, because it was, and there is a possibility that some code may have gone somewhere, such as entering an endless loop or requiring a key to execute.
Next, check the tool that generated the elf for any steps that were not performed correctly or missed. Otherwise, if you can do it before, you can usually do it as an elf.
Again, if you still haven't solved the problem, it is recommended to comment out the method one by one, then add the code one by one, add a test, so that you can definitely locate the problem. It just takes a little time.

dongwei1529 注册会员
2023-02-28 21:44

It is possible that after the elf is generated, the script called contains statements that execute in a loop, causing only the first subroutine to execute.


solution is to write the looping statement as a separate subroutine, and then call that subroutine in the main program. Then the elf will execute all the subroutines in the order you want them to. In addition, it is recommended to add exception handling to the program to facilitate error detection and debugging.

daipeiai 注册会员
2023-02-28 21:44
< div class = "md_content_show e397 data - v - 3967" = "" >

thank you very much for your patience solutions

lishuqin_2 注册会员
2023-02-28 21:44

This answer quotes ChatGPT

The program may not execute properly for several reasons:

1. The resolution of the simulator is different from that of the mobile phone, resulting in the error of coordinate calculation. When debugging, you may be using a PC emulator, and the generated elf may not be able to locate the target correctly when running on a mobile phone due to the difference in resolution. Please check that the coordinates generated by the elf are correct and modify them as required.

2. Certain steps require permissions to be performed on the phone. For example, some operations require the hover window permissions you allow your elf, otherwise they cannot be performed. Please check your phone's permission Settings to make sure the elf has the required permissions.

3. Some random numbers are generated in the script. These random numbers can result in different results when the program is executed on the emulator than when it is executed on the phone. It is recommended to limit the range of these random numbers to a small interval to ensure that similar results can be produced in different environments.

4. Some operations in the script need to wait for a certain amount of time before they can be executed. For example, some operations have to wait a while for the target to appear. If your wait time is not set correctly, the program may not execute correctly. You are advised to adjust the waiting time based on actual conditions to ensure that the operation can be performed at the correct time.

1. Coordinate calculation. In your program, many operations are implemented based on coordinates. Since the resolution of the simulator and the mobile phone may be different, the coordinate calculation may be biased. Coordinate calibration can be done in Elf recording mode, or other methods can be used to calculate the correct coordinates. Here is an example code that uses pixel proportions and offsets for coordinate calculations, which can be adjusted to suit the situation:

' 设置像素比例和偏移量,根据实际情况进行调整
Dim ratioX = 2.0, offset_X = 100
Dim ratioY = 2.0, offset_Y = 200

' 计算修正后的坐标
Dim x = Int((z - offset_X) * ratioX)
Dim y = Int((k - offset_Y) * ratioY)

' 在修正后的坐标上执行操作
Tap x, y

2. Random number generation problem. In your program, some operations are implemented based on random numbers. Such an operation may produce different results in different environments, causing the program to fail to execute normally. You can limit the range of random numbers to ensure similar results in different environments. Here is an example code that uses a fixed random number seed to generate random numbers, ensuring the same result in different environments:

' 固定随机数种子,确保在不同的环境下产生相同的结果
Randomize 12345

' 生成随机数
Dim x = Int(10 * Rnd() + 1)

3. Time waiting problem. In your program, some operations have to wait a while before they can be performed. If the wait time is not set correctly, the program may fail to execute properly. You can adjust the waiting time based on actual conditions to ensure that the operation can be performed at the correct time. Here is an example of code that uses a fixed wait time to ensure that the operation executes at the correct time:

' 等待一段时间后执行操作
Delay 1000

Fix the code as follows:

' 设置像素比例和偏移量,根据实际情况进行调整
Dim ratioX = 2.0, offset_X = 100
Dim ratioY = 2.0, offset_Y = 200

' 固定随机数种子,确保在不同的环境下产生相同的结果
Randomize 12345

' 等待的时间,根据实际情况进行调整
Dim waitTime = 1000

Dim y = Int(501 * Rnd() + 500)

    Call ZG()
    For 120
        Call PG()
        Call SG()
        Call CSW()
    Call HG()

Sub ZG()
    Dim z, k, a, b
    z = Int(60 * Rnd() + 1200)
    k = Int(33 * Rnd() + 326)
    a = Int(59 * Rnd() + 904)
    b = Int(63 * Rnd() + 223)

    ' 计算修正后的坐标
    Dim x1 = Int((z - offset_X) * ratioX)
    Dim y1 = Int((k - offset_Y) * ratioY)
    Dim x2 = Int((a - offset_X) * ratioX)
    Dim y2 = Int((b - offset_Y) * ratioY)

    ' 在修正后的坐标上执行操作
    Tap x1, y1
    Delay waitTime
    Tap x2, y2
    Delay waitTime
End Sub

' 修正其他子程序的代码,与上面的方式类似

deltaw6 注册会员
2023-02-28 21:44

Right, so check to see what the reason is.

fyb3526642 注册会员
2023-02-28 21:44

Based on Monster group and GPT write:
The generated elf may not recognize the subroutine correctly. You can try to wrap a subroutine as a function and then call the function in the main program. For example, wrap the ZG() Function As Function ZGFunc() As Boolean, then call ZGFunc() in the main program. If you need to pass arguments, you can add them to the function's argument list.

csxpeter0 注册会员
2023-02-28 21:44

encapsulation Function encapsulation is the same effect. Only the first Funtion function executes

lheleven 注册会员
2023-02-28 21:44

Part of this answer references GPT, GPT_Pro to better solve the problem
This problem may be caused by a subroutine in the script that is not called correctly. call z6() on line 3 is not called correctly, so it only goes to the first subroutine.
To solve this problem, first make sure that all the subroutines are called correctly, then check the code for any logical errors, such as whether the condition of the loop is correct, whether variables are declared correctly, etc.

In addition, if you want to execute the script properly, you need to check whether the version of the emulator on the PC is correct and ensure that the API functions used by the script are working properly.

In summary, to solve this problem, first make sure that all the subroutines are called correctly, and then check the code for logical errors and version incompatibilities, and API functions that do not work properly.
If the answer is helpful, please accept it.