Что нового

Рандомное появление текста

Rakim

Новичок
Сообщения
85
Репутация
4
Люди как зделать что бы при каждом нажатии на одну и ту же кнопку вылазил разный текст и рандомно ?
 

Fever

Скриптер
Сообщения
308
Репутация
112
Код:
#Include <Misc.au3>

Global $Text[6] = [0, "text1", "text2", "text3", "text4", "text5"]

While 1
	If _IsPressed(10) Then ;клавиша Shift
		MsgBox(0, "", $Text[Random(1, 5, 1)])
	EndIf
WEnd
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Fever
А зачем _IsPressed?

Код:
Global $aText[6] = [5, "text1", "text2", "text3", "text4", "text5"]

HotKeySet("{ESC}", "_Exit")
HotKeySet("{ENTER}", "_ShowRandomText")

While 1
    Sleep(10)
WEnd

Func _Exit()
	Exit
EndFunc

Func _ShowRandomText()
	HotKeySet(@HotKeyPressed)
	Send(@HotKeyPressed)
	
	MsgBox(64, "Random Text", $aText[Random(1, $aText[0], 1)])
	
	HotKeySet(@HotKeyPressed, "_ShowRandomText")
EndFunc
 

prokazzza

Новичок
Сообщения
160
Репутация
2
CreatoR сказал(а):
Fever
А зачем _IsPressed?

Код:
Global $aText[6] = [5, "text1", "text2", "text3", "text4", "text5"]

HotKeySet("{ESC}", "_Exit")
HotKeySet("{ENTER}", "_ShowRandomText")

While 1
    Sleep(10)
WEnd

Func _Exit()
	Exit
EndFunc

Func _ShowRandomText()
	HotKeySet(@HotKeyPressed)
	Send(@HotKeyPressed)
	
	MsgBox(64, "Random Text", $aText[Random(1, $aText[0], 1)])
	
	HotKeySet(@HotKeyPressed, "_ShowRandomText")
EndFunc

А можно доработать скрипт, чтобы он выбирал рандомно, но никогда не повторял одно и тоже значение? К примеру, если уже был text4, он уже не будет выбираться

??
 
A

Alofa

Гость
prokazzza сказал(а):
А можно доработать скрипт...
Код:
#include <Array.au3>
Global $iCount = 1, $aText[6] = [5, "text1", "text2", "text3", "text4", "text5"]

HotKeySet("{ESC}", "_Exit")
HotKeySet("{ENTER}", "_ShowRandomText")

While Sleep(100)
WEnd

Func _ShowRandomText()
	HotKeySet(@HotKeyPressed)
	Send(@HotKeyPressed)
	
	If $iCount > $aText[0] Or $iCount = 1 Then
		_ArrayShuffle($aText, 1)
		$iCount = 1
	EndIf
	MsgBox(64, "Random Text", $aText[$iCount])
	$iCount += 1
	HotKeySet(@HotKeyPressed, "_ShowRandomText")
EndFunc   ;==>_ShowRandomText

Func _Exit()
	Exit
EndFunc   ;==>_Exit
 

prokazzza

Новичок
Сообщения
160
Репутация
2
Alofa сказал(а):
prokazzza сказал(а):
А можно доработать скрипт...
Код:
#include <Array.au3>
Global $iCount = 1, $aText[6] = [5, "text1", "text2", "text3", "text4", "text5"]

HotKeySet("{ESC}", "_Exit")
HotKeySet("{ENTER}", "_ShowRandomText")

While Sleep(100)
WEnd

Func _ShowRandomText()
	HotKeySet(@HotKeyPressed)
	Send(@HotKeyPressed)
	
	If $iCount > $aText[0] Or $iCount = 1 Then
		_ArrayShuffle($aText, 1)
		$iCount = 1
	EndIf
	MsgBox(64, "Random Text", $aText[$iCount])
	$iCount += 1
	HotKeySet(@HotKeyPressed, "_ShowRandomText")
EndFunc   ;==>_ShowRandomText

Func _Exit()
	Exit
EndFunc   ;==>_Exit

То что нужно! Спасибо!
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
prokazzza

Предупреждение За нарушение общих правил (пункт В.2):
Старайтесь избегать “Over quoting” (преувеличенное цитирование) - цитируйте только необходимую часть сообщения, которая наилучшим образом подчеркнёт суть цитируемого.


С уважением, ваш Глобальный модератор.






Добавлено:
Сообщение автоматически объединено:

prokazzza
На будущее. Начинайте новую тему.
Не нужно писать в решенной.
 
Верх