AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

random moves (up, down, left, right)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Endusa



Joined: 09 May 2008
Posts: 21

PostPosted: Wed Jul 23, 2008 9:28 pm    Post subject: random moves (up, down, left, right) Reply with quote

Hi, I wonder if someone could help me with this....I want a script tha press randomly up, down, left and right....Is for character of game move ramdomly...

I realy dont have any idea how to do it.....I think something like this

Code:

x::

loop 15,
{
y = random [,up ,down ,left, right]

Send, {%y% down}{%y% up}

sleep 100
}
Loop 3,
{
PixelSearch, Px, Py, 17, 142, 551, 546, 0xDBBCB5, 3, Fast

Send, {f2 down}{f2 up}
sleep, 100
Send, {f2 down}{f2 up}
sleep, 2000

Click, %Px%, %Py%

}


but it didīt works
Back to top
View user's profile Send private message
SpiderGames



Joined: 09 Jun 2008
Posts: 284
Location: Canada

PostPosted: Wed Jul 23, 2008 9:34 pm    Post subject: Reply with quote

This mgiht not be th best answer. But here it is...
Code:

Loop,
{
Random, fish, 1, 4
if %fish% = 1
Send, {Up}
if %fish% = 2
Send, {Down}
if %fish% = 3
Send, {Left}
if %fish% = 4
Send, {Right}
}
!x::
ExitApp

_________________
http://www.spider-games77.piczo.com
Join the Elite few...
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Endusa



Joined: 09 May 2008
Posts: 21

PostPosted: Wed Jul 23, 2008 9:37 pm    Post subject: Reply with quote

It realy works for me, but is the best way of doing it?
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 908
Location: The Interwebs

PostPosted: Wed Jul 23, 2008 9:40 pm    Post subject: Reply with quote

Endusa wrote:
It realy works for me, but is the best way of doing it?


Pretty much... The random command only supports numbers, so you then have to convert that into a key name. A bit shorter would be to do:

Code:
Random, Key, 1, 4
Key := (Key = 1 ? "Left" : (Key = 2 ? "Right" : (Key = 3 ? "Down" : "Up")))
Back to top
View user's profile Send private message AIM Address
SpiderGames



Joined: 09 Jun 2008
Posts: 284
Location: Canada

PostPosted: Wed Jul 23, 2008 9:44 pm    Post subject: Reply with quote

Quote:
Code (Copy):
Random, Key, 1, 4
Key := (Key = 1 ? "Left" : (Key = 2 ? "Right" : (Key = 3 ? "Down" : "Up")))

Told yeah
_________________
http://www.spider-games77.piczo.com
Join the Elite few...
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Endusa



Joined: 09 May 2008
Posts: 21

PostPosted: Wed Jul 23, 2008 10:04 pm    Post subject: Reply with quote

Thanks for your help. However, I dont no why, the game doest recibe de keys...
It recibes clicks, send, {f2 up} {f2 down}, etc...
but i canīt make the caracter to move...
I try something easy like
x::
Send, {up}
sleep, 300
Send, {up}
return

but nothing......any idea of whats going on?
Back to top
View user's profile Send private message
SpiderGames



Joined: 09 Jun 2008
Posts: 284
Location: Canada

PostPosted: Wed Jul 23, 2008 10:06 pm    Post subject: Reply with quote

Try SendInput
_________________
http://www.spider-games77.piczo.com
Join the Elite few...
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
[VxE]



Joined: 07 Oct 2006
Posts: 1128

PostPosted: Wed Jul 23, 2008 10:51 pm    Post subject: Reply with quote

Code:
Sendmode, Input
SetKeyDelay, 10, 100
Keys = {Up},{down},{left},{right}
StringSplit, key, keys, `,
Loop
{
   Random, key, 1, %key0%
   Send, % "{blind}" key%key%
   Sleep 1000
}

_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 311
Location: Calgary, AB, Canada

PostPosted: Wed Jul 23, 2008 11:05 pm    Post subject: Reply with quote

From what I read a while ago in the docs, SendPlay seems to be the preferable method of input when it comes to games, while SendInput is preferable for everything else. Maybe try SendPlay.
Back to top
View user's profile Send private message MSN Messenger
Endusa



Joined: 09 May 2008
Posts: 21

PostPosted: Thu Jul 24, 2008 2:06 am    Post subject: Reply with quote

thanks all of you...we solve it....the way of doing it was with sentmode, event. So the code is like this:

Code:

x::

Sendmode, event

Send, {f10 down}{f10 up}
SetKeyDelay, 10, 100
Keys = {Up},{down},{left},{right}
StringSplit, key, keys, `,
Loop,
{
   Random, key, 1, %key0%
   Send, % "{blind}" key%key%
   Sleep 1000
}

Back to top
View user's profile Send private message
Endusa



Joined: 09 May 2008
Posts: 21

PostPosted: Thu Jul 24, 2008 2:25 am    Post subject: Reply with quote

okay, I want to complate things now....I just want that when random chose a direction, for ejemple, "up", it pressed 4 times conticutive.....su it coud be in a random way something like this:

up,up,up,up,down,down,down,down,left,left,left,left,down,down,down,down,up,up,up,up,right,right,right,right,
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1128

PostPosted: Thu Jul 24, 2008 3:30 am    Post subject: Reply with quote

Code:
Keys = {Up 4},{down 4},{left 4},{right 4}

_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 908
Location: The Interwebs

PostPosted: Thu Jul 24, 2008 3:32 am    Post subject: Reply with quote

Code:

x::

Sendmode, event

Send, {f10 down}{f10 up}
SetKeyDelay, 10, 100
Keys = {Up},{down},{left},{right}
StringSplit, key, keys, `,
Loop,
{
   Random, key, 1, %key0%
   Send, % "{blind} {" key%key% " 4}"
   Sleep 1000
}
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group