找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6889|回复: 4

[求助] 关于等待线程的写法是什么啊,求助老大

[复制链接]

1

主题

8

回帖

10

积分

学前班

鲜花
0
猫粮
19
发表于 2021-2-26 15:43:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
这个多线程脚本,在答题后,会重头开始执行打怪,有没有办法让答题执行的时候暂停线程1.答题完毕后继续执行线程1
Thread.SetShareVar "首领循环关开",True
Thread.SetShareVar "答题检测关开",True
Thread.SetShareVar "答题完毕关开",False


dim 线程1,线程2
线程1 = thread.start(首领循环)
线程2 = thread.start(答题检测)

Do
If Thread.GetShareVar("答题检测关开") = False and Thread.GetShareVar("首领循环关开") = True Then
Thread.Stop 线程1
Thread.SetShareVar "首领循环关开",False
TracePrint "停止线程1"
答题流程
End If
If Thread.GetShareVar("首领循环关开") = False and Thread.GetShareVar("答题流程关开") = False Then
        线程1 = thread.start(首领循环)
        Thread.SetShareVar "首领循环关开", True
        线程2 = thread.start(答题检测)
        Thread.SetShareVar "答题检测关开",True
End If

Loop

Do
        Delay 1000
Loop

Function 首领循环
Delay 800
For 2
        TracePrint "打怪1"
        Delay 800
        TracePrint "打怪2"
        Delay 800
        TracePrint "打怪3"
        Delay 800
        TracePrint "打怪3"
        Delay 800
        TracePrint "打怪5"
        Delay 800
        TracePrint "打怪6"
        Delay 800
        TracePrint "打怪7"
        Delay 800
        TracePrint "打怪8"
        Delay 800
        TracePrint "打怪9"
        Delay 800
        TracePrint "打怪10"
        Delay 800
        TracePrint "打怪11"
        Delay 800
        TracePrint "打怪12"
        Delay 800
Next
End Function

Function 答题检测
Do
Dim datiX,datiY
FindMultiColor 551,596, 574,679,"04C628","-7|3|04BF28,-4|15|05A626,-3|21|01E928,-7|25|03C227,-1|33|03D929,-1|44|02DC28,-5|49|02E228,-5|62|03D428,0|75|05B527",0,0.9,datiX,datiY
If datiX > -1 Then
Thread.SetShareVar "答题检测关开",False
TracePrint "开始答题"
Delay 1000
Exit Do

Else
Thread.SetShareVar "答题检测关开",True
TracePrint "检测答题"
Delay 100
  TracePrint "检测答题"
Delay 100
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
End If
Loop
End Function


Function 答题流程


        TracePrint "正在答题1"
        Delay 800
        TracePrint "正在答题12"
        Delay 800
        TracePrint "正在答题13"
        Delay 800
        TracePrint "正在答题14"
        Delay 800
        TracePrint "正在答题15"
        Delay 800
        TracePrint "正在答题16"
        Delay 800
        TracePrint "正在答题17"
        Delay 800
        TracePrint "答题完毕"
        Delay 800
Thread.SetShareVar "答题流程关开",False
End Function
楼主热帖
  • 打卡等级:寻得绝学

1082

主题

2114

回帖

4298

积分

院长

鲜花
7
猫粮
6450
QQ
发表于 2021-2-26 22:03:00 | 显示全部楼层
没必要用多线程, 你可以把答题封装到一个子程序里或者延时函数里, 随时调用就是了

1

主题

8

回帖

10

积分

学前班

鲜花
0
猫粮
19
 楼主| 发表于 2021-2-27 21:22:19 | 显示全部楼层
本帖最后由 caitou282 于 2021-2-27 21:32 编辑
紫猫 发表于 2021-2-26 22:03
没必要用多线程, 你可以把答题封装到一个子程序里或者延时函数里, 随时调用就是了 ...

答题是游戏里不定时间跳出来的答题验证,不答题会掉线,重连还是要验证,不停打怪操作会影响答题结果,停止的话,副本做了一半,又得从第一个副本开始。多线程的wait 等待,能实现暂停某一线程吗?
重新整理了下代码,新手刚开始学,只能用笨办法一步一步去做了,参数一用多了脑袋就混乱了,所以代码有点长,老大请指点一二,谢谢!
Thread.SetShareVar "答题流程",False
Thread.SetShareVar "定时任务",False
Rem 开始

dim a,b,c
a = thread.start(首领循环)
b = thread.start(答题检测)
c = thread.start(时间检测)

Do
If Thread.GetShareVar("答题流程") = True Then
thread.Stop (a)
TracePrint "停止线程1"
thread.Stop (b)
TracePrint "停止线程2"
thread.Stop (c)
TracePrint "停止线程3"
答题流程
Thread.SetShareVar "答题流程", False
Exit Do
End If

If Thread.GetShareVar("定时任务") = True Then
thread.Stop (a)
TracePrint "停止线程1"
thread.Stop (b)
TracePrint "停止线程2"
thread.Stop (c)
TracePrint "停止线程3"
定时任务
Thread.SetShareVar "定时任务",False

Exit Do
End If
Loop

Goto 开始

Function 时间检测
Do

Dim 当前时间Dim 定时一 =  "12:00"
Dim 定时二  = "12:10"
Dim 定时三  = "19:30"
Dim 定时四 = "19:40"
Dim 定时五  = "17:00"
Dim 定时六  = "17:40"
当前时间 = DateTime.Format ("%w:%H:%M")
TracePrint 当前时间

If DateTime.Format("%H:%M") > 定时一 and DateTime.Format("%H:%M") <定时二 Then
Thread.SetShareVar "定时任务",True
Exit Do
ElseIf DateTime.Format("%H:%M") >= 定时三 and DateTime.Format("%H:%M") < 定时四 Then
Thread.SetShareVar "定时任务",True
Exit Do
ElseIf DateTime.Format("%H:%M") >= 定时五and DateTime.Format("%H:%M") < 定时六 Then
Thread.SetShareVar "定时任务",True
Exit Do
End If
Delay 2000
Loop
End Function

Function 定时任务
Dim 定时一 =  "12:00"
Dim 定时二  = "12:10"
Dim 定时三  = "19:30"
Dim 定时四 = "19:40"
Dim 定时五  = "17:00"
Dim 定时六  = "17:40"
If DateTime.Format("%H:%M") > 定时一 and DateTime.Format("%H:%M") <定时二 Then
任务1
ElseIf DateTime.Format("%H:%M") >= 定时三 and DateTime.Format("%H:%M") < 定时四 Then
任务2
ElseIf DateTime.Format("%H:%M") >= 定时五and DateTime.Format("%H:%M") < 定时六 Then
任务3
End Function

Function 首领循环
Do
        TracePrint "打怪1"
        Delay 800
        TracePrint "打怪2"
        Delay 800
        TracePrint "打怪3"
        Delay 800
        TracePrint "打怪3"
        Delay 800
        TracePrint "打怪5"
        Delay 800
        TracePrint "打怪6"
        Delay 800
        TracePrint "打怪7"
        Delay 800
        TracePrint "打怪8"
        Delay 800
        TracePrint "打怪9"
        Delay 800
        TracePrint "打怪10"
        Delay 800
        TracePrint "打怪11"
        Delay 800
        TracePrint "打怪12"
        Delay 800
Next
Loop
End Function

Function 答题检测
Do
Dim datiX,datiY
FindMultiColor 551,596, 574,679,"04C628","-7|3|04BF28,-4|15|05A626,-3|21|01E928,-7|25|03C227,-1|33|03D929,-1|44|02DC28,-5|49|02E228,-5|62|03D428,0|75|05B527",0,0.9,datiX,datiY
If datiX > -1 Then
Thread.SetShareVar "答题流程",True
TracePrint "开始答题"
Delay 1000
Exit Do

Else

TracePrint "检测答题"
Delay 100
  TracePrint "检测答题"
Delay 100
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
  TracePrint "检测答题"
Delay 1000
End If
Loop
End Function


Function 答题流程
        TracePrint "正在答题1"
        Delay 800
        TracePrint "正在答题12"
        Delay 800
        TracePrint "正在答题13"
        Delay 800
        TracePrint "正在答题14"
        Delay 800
        TracePrint "正在答题15"
        Delay 800
        TracePrint "正在答题16"
        Delay 800
        TracePrint "正在答题17"
        Delay 800
        TracePrint "答题完毕"
        Delay 800
End Function

1

主题

23

回帖

25

积分

按键电脑&手机班学员

鲜花
0
猫粮
69
发表于 2021-3-28 15:01:36 | 显示全部楼层
代码太长没看。不过我可以给你提供个思路不知道可行否。
老师说的有道理不过我还是按照你用多线程写发的说。
主线程上游戏,打怪升级等一些列操作,包括检测答题界面,有答题就调用子线程答题就行了。
看你的情况貌似是子线程是主线程,那么应该也是一样的,
在子线程里加共享变量
获取共享变量,和设置共享变量,你仔细研究研究这两个命令应该就能解决了,最后根据获取到主线程的共享变量后再在子线程里判断是继续还是重新开始。

1

主题

23

回帖

25

积分

按键电脑&手机班学员

鲜花
0
猫粮
69
发表于 2021-3-28 15:09:12 | 显示全部楼层
我觉得分清主次就好,
答题是随机出的,不答题就不能打怪,
所以主循环里一定要有检测答题,一但有答题立刻停止打怪,
答题结束后给变量一个值,再传给打怪子线程,打怪线程根据得到的变量值选择继续还是重新开始打怪,这样说能明白吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|紫猫编程学园

GMT+8, 2024-5-18 22:19

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表