Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tailgunner on Thu 01/04/2010 12:59:55

Title: How can I move the character with keyboard?
Post by: Tailgunner on Thu 01/04/2010 12:59:55
Hi everybody, i'm sorry for this stupid question but i really don't know how to use the new AGS!

So, my question is the same of the topic's subject  ;D :  I want move the character with the keyboard and i don't know how to do. There is a script or something like that? Because in the manual i didn't find anything, maybe i didn't search well.

And.. sorry for my really bad english, but i'm italian.  :D Thank you for the attenction!
Title: Re: How can I move the character with keyboard?
Post by: Crimson Wizard on Thu 01/04/2010 13:05:20
Create a game using Default template.
There's KeyboardMovement module in it. Check it.
(It already works in games made from Default template. but ofc you can copy it to other projects as well).
Title: Re: How can I move the character with keyboard?
Post by: Tailgunner on Thu 01/04/2010 13:06:17
Thank you very much! Now i'll check it!  ;)
Title: Re: How can I move the character with keyboard?
Post by: Tailgunner on Thu 01/04/2010 13:13:21
I've tried but it doesn't work.

I exported the scripts from the Defaul Template to the Verb Coin template and i could only move the mouse with keyboard, but not the character! There is something that i have to edit in the scripts?
Title: Re: How can I move the character with keyboard?
Post by: Crimson Wizard on Thu 01/04/2010 13:38:51
Hmm... they could be incompatible without some changes... let's see.

Ok, I got it.

In GlobalScript.asc find this inside on_key_press function:


  if (keycode==GetASCIINumber(LeftArrowKey)) mouse.SetPosition(mouse.x - 5, mouse.y);
 if (keycode==GetASCIINumber(RightArrowKey)) mouse.SetPosition(mouse.x + 5, mouse.y);
 if (keycode==GetASCIINumber(UpArrowKey)) mouse.SetPosition(mouse.x, mouse.y - 5);
 if (keycode==GetASCIINumber(DownArrowKey)) mouse.SetPosition(mouse.x, mouse.y + 5);


and either comment or delete it.
Title: Re: How can I move the character with keyboard?
Post by: Tailgunner on Thu 01/04/2010 13:57:19
I've tried to delete it but it doesn't work. Now i can't move the mouse with the keyboard and this it's ok, but i can't move the character too! They are both moved by mouse! I don't know if you understand, because my english is veeery bad and i'm sorry for it. :(
Title: Re: How can I move the character with keyboard?
Post by: Matti on Thu 01/04/2010 14:06:55
I'm not sure, but maybe the keyboard movement is disabled per default.

Put one of these lines into the gamestart section of the global script:


KeyboardMovement.SetMode(eKeyboardMovement_Tapping);
KeyboardMovement.SetMode(eKeyboardMovement_Pressing);


The pressing mode means that the character moves as long as an arrow key is pressed.
The tapping mode means that the character starts to walk once a key is pressed and stops walking as soon as the key is pressed again.

To disable the keyboard movement again call this:


KeyboardMovement.SetMode(eKeyboardMovement_None);
Title: Re: How can I move the character with keyboard?
Post by: Crimson Wizard on Thu 01/04/2010 14:13:28
Aah! Certainly. Mr. Matti is correct.

This is what is put in default template in game_start function:


KeyboardMovement.SetMode(eKeyboardMovement_Tapping);


QuoteI don't know if you understand, because my english is veeery bad and i'm sorry for it.
I understand everything you say, don't worry  ;)
Title: Re: How can I move the character with keyboard?
Post by: Danman on Thu 01/04/2010 15:15:26
I got this working. But exporting the KeyboardMovement_102 Module out of the Default game.  Then importing it in my own game.

Then putting this in the Game.start() function

KeyboardMovement.SetMode(eKeyboardMovement_Tapping);

As Matti and Crimson Wizard explained.

It worked well for me
Hope this helps  ;D

Edit: Sorry Matti for misspelling your name . :P
Title: Re: How can I move the character with keyboard?
Post by: Matti on Thu 01/04/2010 15:28:48
Quote from: Danman on Thu 01/04/2010 15:15:26
As Matty and Crimson Wizard explained.

With an i please ;) It's pronounced Mu-tea by the way.
Title: Re: How can I move the character with keyboard?
Post by: Danman on Thu 01/04/2010 16:12:20
Oh OK sorry Matti. Changed it now
Title: Re: How can I move the character with keyboard?
Post by: Tailgunner on Thu 01/04/2010 23:20:14
Ok thank you all now it works!  ;)