SetTimer, perform actions at different Times

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MadnessInTheHouse

SetTimer, perform actions at different Times

19 Aug 2018, 13:30

Hey,
I'm new to scripting and Ahk
I made a Script for a Game, where i got the Problem that the Timer stops during performing actions, but i would like it to continue counting, while it does specific action at specific times.
(Press 1 -> start Counting until reaching 320, start counting from 0 in an infinite loop, perform the actions during the times)

Would be great if someone could help me out xd
Thanks already :3

2::Pause

1::
#Persistent
SetTimer:
SetTimer, Timed, 50
Timed:
++curTime
timed := round(CurTime/20, 1)
ToolTip, %timed%
sleep 50

{
if timed = 1
{
SetMouseDelay, 100

#IfWinActive, LiquidBounce b25.5 | 1.8.8

Sleep 150
Send {t}
Sleep 50
Send {/}
Sleep 150
Click 798,379,10
Send {ESC}
Sleep 150
}


if timed = 200
{
++curTime
Send, Zweihundert
}



if timed = 320
{
++curTime
Sleep 500

Send {t}
Sleep 25
Send, /
Sleep 25
Send, is
Sleep 25
Send {Enter}

Sleep 500

Click 630, 410

Sleep 3500



setTimer, Timed, off
timed = 0
Tooltip
curtime = 0
GoTo, SetTimer
}
}
Return
Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: SetTimer, perform actions at different Times

20 Aug 2018, 02:05

Hallo,
try (untested):

Code: Select all

#Persistent
2::Pause
1::
SetTimer:
SetTimer, Timed, 50
Timed:
++curTime
timed := round(CurTime/20, 1)
ToolTip, %timed%
;sleep 50 ;avoid Sleeps in the main timer!
if timed = 1
	SetTimer, timed1, -1
if timed = 320
	SetTimer, timed320, -1
Return
timed1:
SetMouseDelay, 100
IfWinActive, LiquidBounce b25.5 | 1.8.8
{
	Sleep 150
	Send {t}
	Sleep 50
	Send {/}
	Sleep 150
	Click 798,379,10
	Send {ESC}
	Sleep 150
}
Return
timed320:
++curTime
Sleep 500
Send {t}
Sleep 25
Send, /
Sleep 25
Send, is
Sleep 25
Send {Enter}
Sleep 500
Click 630, 410
Sleep 3500
setTimer, Timed, off
timed = 0
Tooltip
curtime = 0
;GoTo, SetTimer ;not recommended, the secondary timer timed320 requires the Return
SetTimer, Timed, On
Return
Madness
Posts: 3
Joined: 19 Aug 2018, 13:18

Re: SetTimer, perform actions at different Times

20 Aug 2018, 05:40

Danke für die schnelle Antwort :D
Während der Ausführung der timed1 Befehle stoppt der Timer komplett, allerdings habe ich darin noch ein paar mousemove befehle während denen der timer seeehr langsam weiterläuft xd

Hast du noch eine Idee ?
Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: SetTimer, perform actions at different Times

21 Aug 2018, 02:51

Hallo,
hast du vielleicht das ;sleep 50 ;avoid Sleeps in the main timer! reaktiviert?
Autohotkey schläft bereits im timed1 und kann (genau wie unsereiner) nicht zwei Sleeps gleichzeitig ausführen!
Näheres unter https://ahkde.github.io/docs/misc/Threads.htm.
Alles was länger dauert, hat (meiner Meinung nach) im Haupttimer nichts zu suchen!
D.h.: Schleifenausführungsdauer < Periode!

maybe you have the ;sleep 50, avoid Sleeps in the main timer! reactivated?
Autohotkey is already sleeping in timed1 and (just like us) can't do two sleeps at the same time!
See https://autohotkey.com/docs/misc/Threads.htm for details.
Anything that takes longer has (in my opinion) no place in the main timer!
This means: Loop execution time < period!
Madness
Posts: 3
Joined: 19 Aug 2018, 13:18

Re: SetTimer, perform actions at different Times

21 Aug 2018, 17:47

Ohh okay ich habe das sleep 50 im haupttimer zwar rausgenommen, aber ich möchte bei timed1 nicht dass der Timer 50 sleept sondern dass die Aktion die timed 1 ausführt um 50 verzögert wird xd
Hast du dafür eine Lösung ? wie ich also im script pausen einbaue obwohl der Timer weiterläuft ?

Vielen Dank für die schnellen Antworten und die gute Hilfe ^^'
Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: SetTimer, perform actions at different Times

22 Aug 2018, 03:17

Hallo,
Sleeps in Nebentimern bremsen den Haupttimer nicht aus, vorausgesetzt der Haupttimer hat selbst keine!
Zum Testen habe ich dies Skript:

Code: Select all

SetTimer, Timer, 100
Space::
	Notiz = Sleep Aufruf mit Hotkey
	Gosub, Sleep
Return
Esc::Reload
Timer:
	N++
	ToolTip, % N " " Notiz
	;Sleep, 90
	IF N = 100
	{
		Notiz = Sleep Aufruf mit Timer
		SetTimer, Sleep, -1
	}
	If N = 200
	{
		Notiz = Sleep Aufruf mit Gosub
		Gosub, Sleep
	}
Return
Sleep:
	ToolTip, % N " " Notiz
	Sleep, 3000
	Notiz =
Return
nach 10 Sekunden (N=100), 20 Sekunden (N=200) und zusätzlich mit Hotkey Space erfolgen verschiedene Sleep-Aufrufe. Hotkey Escape macht einen Reload.
Teste dies einmal mit auskommentierten ;Sleep, 90 und einmal mit aktivierten.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: fiendhunter and 234 guests