<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Запись текста в массив и удаление через 5 минут]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=11387</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11387&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Запись текста в массив и удаление через 5 минут».]]></description>
		<lastBuildDate>Wed, 04 May 2016 13:55:59 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103351#p103351</link>
			<description><![CDATA[<p>Спасибо большое.</p>]]></description>
			<author><![CDATA[null@example.com (MoZg)]]></author>
			<pubDate>Wed, 04 May 2016 13:55:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103351#p103351</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103330#p103330</link>
			<description><![CDATA[<p>Думаю что и по другому тоже, только надо дожить до момента выполнения кода из 11 поста.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Wed, 04 May 2016 01:02:14 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103330#p103330</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103329#p103329</link>
			<description><![CDATA[<p>Так да, вроде работает.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Wed, 04 May 2016 00:54:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103329#p103329</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103328#p103328</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Wed, 04 May 2016 00:40:02 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103328#p103328</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103327#p103327</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Wed, 04 May 2016 00:24:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103327#p103327</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103326#p103326</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Wed, 04 May 2016 00:12:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103326#p103326</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103325#p103325</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 03 May 2016 23:48:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103325#p103325</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103324#p103324</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Тут как-то не очень логично — последнее значение удалено, а таймер продолжает работать.</p></blockquote></div><p>Почему, в данном случае так и должно быть. Я сначала тоже думал для каждого ключа выделять отдельный таймер, но потом решил что для конкретной задачи это избыточно, да и мало ли сколько там ключей наберётся, таймер это же тоже ресурс, ничего плохого если он раз в 5 минут будет запускать проверку вхолостую.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Tue, 03 May 2016 23:32:50 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103324#p103324</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103322#p103322</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 03 May 2016 22:03:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103322#p103322</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103318#p103318</link>
			<description><![CDATA[<p><a href="http://forum.script-coding.com/viewtopic.php?pid=103326#p103326">http://forum.script-coding.com/viewtopi … 26#p103326</a>.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Tue, 03 May 2016 19:23:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103318#p103318</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=103313#p103313</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (MoZg)]]></author>
			<pubDate>Tue, 03 May 2016 18:35:45 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=103313#p103313</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=101711#p101711</link>
			<description><![CDATA[<p>Спасибо большое, задача решена.</p>]]></description>
			<author><![CDATA[null@example.com (MoZg)]]></author>
			<pubDate>Tue, 08 Mar 2016 12:28:25 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=101711#p101711</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=101708#p101708</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Tue, 08 Mar 2016 00:40:40 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=101708#p101708</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=101707#p101707</link>
			<description><![CDATA[<p>Непонятно, в чём сложность.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 07 Mar 2016 19:39:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=101707#p101707</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Запись текста в массив и удаление через 5 минут]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=101698#p101698</link>
			<description><![CDATA[<p>Доброго времени суток, мне нужна реализация записи текста в массив и удаление через 5 мин после записи. Т.е. Мы записываем текст в массив и через 5 мин после записи удаляем его. Заранее спасибо.</p>]]></description>
			<author><![CDATA[null@example.com (MoZg)]]></author>
			<pubDate>Mon, 07 Mar 2016 14:51:58 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=101698#p101698</guid>
		</item>
	</channel>
</rss>
