<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Вывод переменной со случайным индексом]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13954&amp;type=atom" />
	<updated>2018-07-19T08:29:11Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=13954</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вывод переменной со случайным индексом]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127148#p127148" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>Key1 := &quot;text1&quot;
Key2 := &quot;text2&quot;
Key3 := &quot;text3&quot;

Random, val, 1, 3
MsgBox % word := Key%val%</code></pre></div><p>Но лучше так:<br /></p><div class="codebox"><pre><code>keys := [&quot;text1&quot;, &quot;text2&quot;, &quot;text3&quot;]
Random, idx, 1, keys.MaxIndex()
MsgBox % word := keys[idx]</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-07-19T08:29:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127148#p127148</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Вывод переменной со случайным индексом]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127147#p127147" />
			<content type="html"><![CDATA[<p>Здравствуйте.<br /><em>Вопрос примитивный до ужаса, но не смог найти ответ или пример. Можно реализовать через множество IF, но это слишком объемно и некрасиво <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></em></p><p>Есть набор определенных переменных <strong><em>(Key1, Key2, Key3, ... KeyN)</em></strong>, которые имеют текст внутри. Необходимо выводить в случайном порядке переменные и присваивать заголовочной переменной <strong><em>word</em></strong>. Для этого использовалась функция <strong><em>random</em></strong>.</p><p>Примерно так:</p><div class="codebox"><pre><code>Key1 = &quot;text1&quot;
Key2 = &quot;text2&quot;
...
KeyN = &quot;text3&quot;

random, vall,1,N</code></pre></div><p><span class="bbu">Далее вопрос.</span> Необходимо присвоить значение переменной <em><strong>KeyN </strong></em>с индексом случайной переменной <em><strong>vall</strong></em> в переменную <em><strong>word</strong></em>. Можно-ли это сделать в одну строку? Например: <em><strong>word = %Key%vall</strong></em> (да, это не работает, но думаю суть примерно объяснил).<br />Т.е. чтобы по факту если <em><strong>vall </strong></em>имеет значение <em><strong>2</strong></em>, то присвоилось значение <em><strong>word = %Key2</strong></em> и вывод <em><strong>Msgbox, %word</strong></em> давал результат <em><strong>text2</strong></em>.</p><p>Благодарю.</p>]]></content>
			<author>
				<name><![CDATA[SUser]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39394</uri>
			</author>
			<updated>2018-07-19T07:04:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127147#p127147</id>
		</entry>
</feed>
