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
wrote a script program with key Sprite mobile assistant(debug with PC simulator, execute a set of actions in a loop), debugging everything is normal, generate the Sprite and then execute with PC simulator. Only the first subroutine in a script program can be executed. What is the cause and how can it be fixed? Thanks! The code is as follows:
Dim y =Int(501 * Rnd() + 500)
Do
Call ZG()
For 120
Call PG()
Call SG()
Call CSW()
Next
Call HG()
Loop
Sub ZG()
Randomize
//展开快捷栏
Dim z,k
z = Int(60 * Rnd() + 1200)
k = Int(33 * Rnd() + 326)
Dim a,b
a = Int(59 * Rnd() + 904)
b = Int(63 * Rnd() + 223)
Tap z, k
Delay y
//默认点击快捷键2
Tap a, b
Delay y
End Sub
//找到抛出并点击,否则找武器点击后抛出
Sub PG()
Randomize
Do
Dim intX,intY
FindPic 931,586,1075,719,"Attachment:paogan.png","000000",0,0.9,intX,intY
If intX > -1 And intY > -1 Then
Dim p,c
p = Int(64 * Rnd() + 972)
c = Int(65 * Rnd() + 619)
Tap p,c
Delay y
Exit Do
Else
Dim intX1,intY1
FindMultiColor 1001,446,1208,611,"C2C2C2","12|20|CBCBCB,4|23|CBCBCB,29|44|C1C1C1",0,0.9,intX1,intY1
If intX1 > -1 And intY1 > -1 Then
Dim w,q
w = Int(66 * Rnd() + 1080)
q = Int(66 * Rnd() + 483)
Tap w,q
Delay y
End If
End If
Loop
End Sub
// 收回
Sub SG()
Randomize
Do
Dim intX,intY
FindMultiColor 1023,429,1188,599,"DFBC9F","4|6|F3C59F,3|-1|C9A78C,4|-2|B99D85",0,0.9,intX,intY
If intX > -1 And intY > -1 Then
Exit Do
End If
Loop
Dim s,g,l
s = Int(66 * Rnd() + 1080)
g = Int(66 * Rnd() + 483)
l = Int(6 * Rnd() + 10)
For l
Tap s,g
Delay y
Next
End Sub
Sub CSW ()
Randomize
Dim o
o =Int(501 * Rnd() + 500)
Dim eat
eat =Int(2001 * Rnd() + 6000)
Dim intX,intY
FindPic 84,36,213,69,"Attachment:baoshidu.png","000000",0,0.9,intX,intY
If intX > -1 And intY > -1 Then
Dim a,b
a = Int(65 * Rnd() + 1200)
b = Int(30 * Rnd() + 328)
Tap a, b
Delay o
End If
Dim c,d
c = Int(42 * Rnd() + 233)
d = Int(55 * Rnd() + 1104)
Tap d,c
Delay o
Dim i,j
i = Int(62 * Rnd() + 1082)
j = Int(50 * Rnd() + 491)
Tap i, j
Delay eat
Call ZG()
End Sub
Sub HG()
Randomize
Dim y
y = Int(1001 * Rnd() + 1000)
Dim q,r
q = Int(74 * Rnd() + 1152)
r = Int(43 * Rnd() + 217)
Tap q, r
Delay y
Dim a,b
a = Int(47 * Rnd() + 348)
b = Int(50 * Rnd() + 639)
Tap a,b
Delay y
Dim c,d
c = Int(63 * Rnd() + 774)
d = Int(69 * Rnd() + 624)
Tap c, d
Delay y
Dim e,f
e = Int(72 * Rnd() + 201)
f = Int(43 * Rnd() + 660)
Tap e,f
Delay y
Dim g,h
g = Int(127 * Rnd() + 707)
h = Int(33 * Rnd() + 477)
Tap g, h
Delay y
Dim i,j
i = Int(62 * Rnd() + 678)
j = Int(60 * Rnd() + 88)
Tap i, j
Delay y
Dim k,l
k = Int(68 * Rnd() + 99)
l = Int(40 * Rnd() + 663)
Tap k, l
Delay y
Dim m,n
m = Int(62 * Rnd() + 776)
n = Int(63 * Rnd() + 626)
Tap m, n
Delay y
Dim o,p
o = Int(37 * Rnd() + 1200)
p = Int(32 * Rnd() + 10)
Tap o,p
Delay y
End Sub
0 Answer
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
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.
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.
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.
Thesolution 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.
thank you very much for your patience solutions
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)
Do
Call ZG()
For 120
Call PG()
Call SG()
Call CSW()
Next
Call HG()
Loop
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
' 修正其他子程序的代码,与上面的方式类似
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.
encapsulation Function encapsulation is the same effect. Only the first Funtion function executes
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.
这家伙很懒,什么都没留下...