Snake

Ask gaming related questions
snakebeater123
Posts: 3
Joined: 02 Oct 2019, 07:30

Snake

02 Oct 2019, 07:38

Hi everyone

I have a certain knowledge about programming, but not the level required for this.

I want to make a script that simulates some keypresses.

It is for the game snake, so I would like to write a script that makes my snake make rows so I would be able to go on unlimited.

The snakes start in the middle, so go up until the roof and then starts making rows. When he is down go up again and repeat everything

I hope you could help me,

Kind regards
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

Re: Snake

02 Oct 2019, 13:05

@snakebeater123 Let's assume you move the snake to with W A S D (you need to create your own times too)

This how you should start: Send // Sleep // Loop

Code: Select all

Send, {w} 	;Send key up
Sleep, 1000 ;Wait until send another key  (Now you are in top of the field)
Send, {d}   ;Send key to the right
Sleep, 1000 ;Now you are in the right top corner
Send, {s}   ;Going down again
Sleep, 50   ;You can skip this time if you're going really fast
Send, {a}   ;Sending the snake to the left
Sleep, 2000 ;Reach the left border of the field
Send, {s}   ;Going down again
Sleep, 50   ;Dejavu - you're repeating this
Send, {d}   ;The same as before but sending the snake to the right

;Need to add more moves until you reach the starting point again or you find a point where a loop is needed.
You need a Loop to repeat it.

You can read the documentation on how to do it, also I recommend to use Pulover's Macro Creator to register the keys and just apply a simple loop.
Image
snakebeater123
Posts: 3
Joined: 02 Oct 2019, 07:30

Re: Snake

03 Oct 2019, 05:01

Thank you, this is my code now, but I get a fault in the 6th line, I don't know whats wrong

Send, {Left} ;Send key left
Sleep, 1000 ;Wait until send another key (Now you are in top of the field)
Send, {Up} ;Send key to the top
Sleep, 1000 ;Now you are in the left top corner
Send, {Right};Now you are in the top right corner
Sleep, 2000;
Loop, 10
{
Loop, 10
{
Send, {Down} ;Going down again
Sleep, 50 ;You can skip this time if you're going really fast
Send, {Left} ;Sending the snake to the left
Sleep, 2000 ;Reach the left border of the field
Send, {Down} ;Going down again
Sleep, 50 ;Dejavu - you're repeating this
Send, {Right} ;The same as before but sending the snake to the right
Sleep, 2000;
}
Send, {Down} ;Going down ones again
Sleep, 50 ;
Send, {Left} ;Sending the snake to the left
Sleep, 2000 ;Reach the left border of the field totally down
Send, {Up};
Sleep, 2000; Reach top left
}
snakebeater123
Posts: 3
Joined: 02 Oct 2019, 07:30

Re: Snake

03 Oct 2019, 05:07

http jongenschirobalegem.be /duvelnacht/wedstrijd_noscroll Broken Link for safety

this is the program
gregster
Posts: 3379
Joined: 30 Sep 2013, 06:48

Re: Snake

03 Oct 2019, 05:30

snakebeater123 wrote:
03 Oct 2019, 05:01
Thank you, this is my code now, but I get a fault in the 6th line, I don't know whats wrong
If you use ; to do an inline-comment, you have to leave at least one space/tab between the end of the command and/or its parameters and the ;
So use

Code: Select all

Sleep, 2000 
; or
Sleep, 2000 ;
instead of Sleep, 2000;

Btw, in AHK you don't need a ; at the end of each line, if you don't have an inline-comment...

There are more lines that will also do something else than you expect, I guess:

Code: Select all

Send, {Right};Now you are in the top right corner
This literally sends the string ;Now you are in the top right corner after a press of the right arrow key. Again, a space in front of the ; would help to make it a comment: Send, {Right} ;Now you are in the top right corner

More lines with similar problems:

Code: Select all

Send, {Up};
Sleep, 2000; Reach top left
Please use [code][/code] tags next time, if you post code. It creates these nice codeboxes...

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 40 guests