<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Запись текста в массив и удаление через 5 минут]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11387&amp;type=atom" />
	<updated>2016-05-04T13:55:59Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11387</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103351#p103351" />
			<content type="html"><![CDATA[<p>Спасибо большое.</p>]]></content>
			<author>
				<name><![CDATA[MoZg]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33153</uri>
			</author>
			<updated>2016-05-04T13:55:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103351#p103351</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103330#p103330" />
			<content type="html"><![CDATA[<p>Думаю что и по другому тоже, только надо дожить до момента выполнения кода из 11 поста.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-05-04T01:02:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103330#p103330</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103329#p103329" />
			<content type="html"><![CDATA[<p>Так да, вроде работает.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-04T00:54:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103329#p103329</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103328#p103328" />
			<content type="html"><![CDATA[<p>А что не так? Ты дожидался окончания записи в массив? Переполненный ToolTip очень много отнимает времени на отображение.<br /></p><div class="codebox"><pre><code>
CoordMode, ToolTip 
	
#Persistent

Time := 3000
oArr := []

Loop 500  {
	Sleep, 10
	oArr[A_TickCount] := A_Index
} 
MsgBox Запись окончена
SetTimer, Timer, 1000
SetTimer, Remove, -%Time%  
Return

Remove:
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
	{
		oArr.RemoveAt(oArr.MinIndex()), ++i
		ToolTip % i &quot; удалено из массива&quot;,1,1,3
	}
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : (N := Time - (A_TickCount - oArr.MinIndex())) &lt; 1 ? 1 : N)  
	Return
	
Timer:
	For k, v in oArr, content := &quot;&quot;
		content .= &quot;Добавлено &quot; (A_TickCount - k) // 1000 &quot; секунд назад:`t`t&quot; v &quot;`n&quot; 
	ToolTip % &quot;Прошло секунд: &quot; (A_TickCount - Start) // 1000 &quot;`nСодержимое массива:`n`n&quot; content
	Return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-05-04T00:40:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103328#p103328</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103327#p103327" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Должно работать:</p></blockquote></div><p>Нет:<br /></p><div class="codebox"><pre><code>
#Persistent

SetTimer, Timer

Time := 1000
oArr := []

Loop 500  {
	Sleep, 10
	oArr[A_TickCount] := A_Index
} 
SetTimer, Remove, -%Time%  
Return

Remove:
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
	{
		oArr.RemoveAt(oArr.MinIndex()), ++i
		ToolTip % i &quot; удалено из массива&quot;
	}
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : (N := Time - (A_TickCount - oArr.MinIndex())) &lt; 1 ? 1 : N)  
	Return
	
Timer:
	For k, v in oArr, content := &quot;&quot;
		content .= &quot;Добавлено &quot; (A_TickCount - k) // 1000 &quot; секунд назад:`t`t&quot; v &quot;`n&quot; 
	ToolTip % &quot;Прошло секунд: &quot; (A_TickCount - Start) // 1000 &quot;`nСодержимое массива:`n`n&quot; content
	Return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-04T00:24:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103327#p103327</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103326#p103326" />
			<content type="html"><![CDATA[<p>Да, действительно есть ошибка, так понял на коротких интервалах время выполнения удаления и установки критично, поправил.<br /></p><div class="codebox"><pre><code>
#Persistent

Time := 5000   
oArr := []
SetTimer, Remove, -%Time% 
oArr[A_TickCount] := 0
Sleep, 2000
oArr[A_TickCount] := 1

Loop 1000  {
	Sleep, 10
	oArr[A_TickCount] := A_Index
}
Return

Remove:
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
		oArr.RemoveAt(oArr.MinIndex())
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : (N := Time - (A_TickCount - oArr.MinIndex())) &lt; 1 ? 1 : N)  
	ToolTip % oArr[oArr.MinIndex()]
	Return
</code></pre></div><div class="quotebox"><cite>MoZg пишет:</cite><blockquote><p>Столкнулся с такой проблемой...</p></blockquote></div><p>Должно работать:<br /></p><div class="codebox"><pre><code>
#Persistent

Time := 5 * 60 * 1000   ;  5 минут
oArr := []
SetTimer, Remove, -%Time% 
oArr[A_TickCount] := &quot;Text 1&quot;  ; пример записи в такой массив 
Return

Remove:  
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
		oArr.RemoveAt(oArr.MinIndex())
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : (N := Time - (A_TickCount - oArr.MinIndex())) &lt; 1 ? 1 : N) 
	Return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-05-04T00:12:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103326#p103326</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103325#p103325" />
			<content type="html"><![CDATA[<p>Мой корректно работает при достаточно большом количестве ключей:<br /></p><div class="codebox"><pre><code>#Persistent
SetTimer, Timer

MyArray := new DeleteKey(5000)  ; удалять через 5 секунд
Loop 1000  {
	Sleep, 10
	MyArray.Push(A_Index)
}

class DeleteKey
{
	__New(time)  {
		this._time := time
	}
	__Set(key)  {
		if (key != &quot;_time&quot;)  {
			Timer := Func(&quot;Delete&quot;).Bind(this, key)
			SetTimer, % Timer, % &quot;-&quot; this._time
		}
	}
	Push(value)  {
		var := this.MaxIndex()
		this[(var = &quot;&quot; ? 0 : var) + 1] := value
	}
}

Delete(obj, key)  {
	obj.Delete(key)
}

Timer:
	CoordMode, ToolTip
	text := &quot;&quot;
	for k, v in MyArray
		if (k != &quot;_time&quot;)
			text .= &quot;MyArray.&quot; k &quot; = &quot; v &quot;`n&quot;
	ToolTip % text, A_ScreenWidth//2, A_ScreenHeight//2, 1
	Return</code></pre></div><p>А вот твой выдаёт вышеуказанную ошибку, почему — не знаю, не разбирался:<br /></p><div class="codebox"><pre><code>#Persistent

Time := 5000   ;  5 минут
oArr := []
SetTimer, Remove, -%Time% 
oArr[A_TickCount] := 0
Sleep, 2000
oArr[A_TickCount] := 1

Loop 1000  {
	Sleep, 10
	oArr[A_TickCount] := A_Index
}
Return

Remove:
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
		oArr.RemoveAt(oArr.MinIndex())
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : Time - (A_TickCount - oArr.MinIndex())) 
	ToolTip % oArr[oArr.MinIndex()]
	Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-03T23:48:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103325#p103325</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103324#p103324" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Тут как-то не очень логично — последнее значение удалено, а таймер продолжает работать.</p></blockquote></div><p>Почему, в данном случае так и должно быть. Я сначала тоже думал для каждого ключа выделять отдельный таймер, но потом решил что для конкретной задачи это избыточно, да и мало ли сколько там ключей наберётся, таймер это же тоже ресурс, ничего плохого если он раз в 5 минут будет запускать проверку вхолостую.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-05-03T23:32:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103324#p103324</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103322#p103322" />
			<content type="html"><![CDATA[<p>Тут как-то не очень логично — последнее значение удалено, а таймер продолжает работать.<br />Я бы так сделал:<br /></p><div class="codebox"><pre><code>#Persistent
MyArray := new DeleteKey(5000)  ; удалять через 5 секунд
MyArray.MyKey := 1   ; если нужно своё название ключа, кроме зарезервированного &quot;_time&quot;
MyArray.Push(10)		; если название ключа не имеет значения
Return

class DeleteKey
{
	__New(time)  {
		this._time := time
	}
	__Set(key)  {
		if (key != &quot;_time&quot;)  {
			Timer := Func(&quot;Timer&quot;).Bind(this, key)
			SetTimer, % Timer, % &quot;-&quot; this._time
		}
	}
	Push(value)  {
		var := this.MaxIndex()
		this[(var = &quot;&quot; ? 0 : var) + 1] := value
	}
}

Timer(obj, key)  {
	obj.Delete(key)
}</code></pre></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;демо</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#Persistent
SetTimer, Timer

MyArray := new DeleteKey(5000)  ; удалять через 5 секунд
MyArray.MyKey := 1   ; если нужно своё название ключа
Sleep, 1000
MyArray.Push(2)		; если название ключа не имеет значения
Sleep, 1000
MyArray.test := 3
Sleep, 1000
MyArray.Push(4)
Return

class DeleteKey
{
	__New(time)  {
		this._time := time
	}
	__Set(key)  {
		if (key != &quot;_time&quot;)  {
			Timer := Func(&quot;Delete&quot;).Bind(this, key)
			SetTimer, % Timer, % &quot;-&quot; this._time
		}
	}
	Push(value)  {
		var := this.MaxIndex()
		this[(var = &quot;&quot; ? 0 : var) + 1] := value
	}
}

Delete(obj, key)  {
	obj.Delete(key)
}

Timer:
	CoordMode, ToolTip
	text := &quot;&quot;
	for k, v in MyArray
		if (k != &quot;_time&quot;)
			text .= &quot;MyArray.&quot; k &quot; = &quot; v &quot;`n&quot;
	ToolTip % text, A_ScreenWidth//2, A_ScreenHeight//2, 1
	Return</code></pre></div></div></div><p>И ключи, если нужно, можно называть, если не нужно — можно не называть.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-05-03T22:03:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103322#p103322</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103318#p103318" />
			<content type="html"><![CDATA[<p><a href="http://forum.script-coding.com/viewtopic.php?pid=103326#p103326">http://forum.script-coding.com/viewtopi … 26#p103326</a>.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-05-03T19:23:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103318#p103318</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103313#p103313" />
			<content type="html"><![CDATA[<p>Столкнулся с такой проблемой... Бывает что эта строка:<br /></p><div class="codebox"><pre><code>(!oArr.MinIndex() ? Time : Time - (A_TickCount - oArr.MinIndex())) </code></pre></div><p>возвращает отрицательное значение и т.к. перед этим выражением стоит &quot;-&quot;, то получается, например, --1547862 и AutoHotkey выдает ошибку. <a href="http://pixs.ru/showimage/hedjpg_3890909_21792948.jpg">Скриншот</a>. Подскажите как решить эту проблему.</p>]]></content>
			<author>
				<name><![CDATA[MoZg]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33153</uri>
			</author>
			<updated>2016-05-03T18:35:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103313#p103313</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=101711#p101711" />
			<content type="html"><![CDATA[<p>Спасибо большое, задача решена.</p>]]></content>
			<author>
				<name><![CDATA[MoZg]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33153</uri>
			</author>
			<updated>2016-03-08T12:28:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=101711#p101711</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=101708#p101708" />
			<content type="html"><![CDATA[<p>Если каждый ключ удалять в своё время, то как то так:<br /></p><div class="codebox"><pre><code>
#Persistent

Time := 5 * 60 * 1000   ;  5 минут
oArr := []
SetTimer, Remove, -%Time% 
oArr[A_TickCount] := &quot;Text 1&quot;  ; пример записи в такой массив 
Return

Remove:  
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
		oArr.RemoveAt(oArr.MinIndex())
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : Time - (A_TickCount - oArr.MinIndex())) 
	Return
</code></pre></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;Демо:</div><div class="fancy_spoiler"><div class="codebox"><pre><code>
#Persistent

Start := A_TickCount
SetTimer, Demo, 100


Time := 10000   ;  10 секунд
oArr := []
SetTimer, Remove, -%Time% 
 
								;  удаление через:
oArr[A_TickCount] := &quot;Text 1&quot;   ;  через 10 секунд
Sleep 2000 
oArr[A_TickCount] := &quot;Text 2&quot;   ;  через 12 секунд
Sleep 3000						 
oArr[A_TickCount] := &quot;Text 3&quot;   ;  через 15 секунд
Sleep 3000						 
oArr[A_TickCount] := &quot;Text 4&quot;   ;  через 18 секунд
Return

Remove:  
 	If (A_TickCount - oArr.MinIndex() &gt;= Time)
		oArr.RemoveAt(oArr.MinIndex())
	SetTimer, Remove, % &quot;-&quot; (!oArr.MinIndex() ? Time : Time - (A_TickCount - oArr.MinIndex())) 
	Return
	
Demo:
	For k, v in oArr, content := &quot;&quot;
		content .= &quot;Добавлено &quot; (A_TickCount - k) // 1000 &quot; секунд назад:`t`t&quot; v &quot;`n&quot; 
	ToolTip % &quot;Прошло секунд: &quot; (A_TickCount - Start) // 1000 &quot;`nСодержимое массива:`n`n&quot; content
	Return
</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2016-03-08T00:40:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=101708#p101708</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=101707#p101707" />
			<content type="html"><![CDATA[<p>Непонятно, в чём сложность.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-03-07T19:39:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=101707#p101707</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=101698#p101698" />
			<content type="html"><![CDATA[<p>Доброго времени суток, мне нужна реализация записи текста в массив и удаление через 5 мин после записи. Т.е. Мы записываем текст в массив и через 5 мин после записи удаляем его. Заранее спасибо.</p>]]></content>
			<author>
				<name><![CDATA[MoZg]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33153</uri>
			</author>
			<updated>2016-03-07T14:51:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=101698#p101698</id>
		</entry>
</feed>
