Hi,
Well, I'm using this module (from Bernie) to get my character to walk when you press the up, down, left and right buttons. But I ran into several problems:
1] I want my character to only walk north, south, west and east. So not diagonal. How can I get my characters to walk that way? Also: If the player-character walks to an object to examine it, can it be done with cursors in a way so the character walks only in my preferred directions (N,S,W,E and NOT diagonal)?
2] I also want other key functions to be done:
a} Talk/interact/examine an object/person/place when I press the "x"-button when I'm standing next to it (Do I have to use hotspots or regions?).
b} Is it possible to confirm an action with the "x"-button and cancel an action with the "z"-button?
c} How do you make buttons selectable by moving a cursor controlled by a keyboard (like in the Anna game) when you have a GUI opened?
Thanks,
Yurina
P.S.: If you know the answers: I do have to say I use AGS 2.7. A lot of people gave me codes for earlier/later versions, so I say this again.
http://americangirlscouts.org/agswiki/index.php/Coding_Contest
One of the coding contests was about keyboard control and could help you with 2]a}.
1)
(NOTE: I've never used Bernie's module so I've no idea if this'll actually work, but it should.)
You'll need to find these lines in the module (86 - 92, assuming you haven't altered anything):
if ((IsInterfaceEnabled()==1)&&(IsGamePaused()==0)) {
if (IsKeyPressed(377)==1) {right=1;}
if (IsKeyPressed(375)==1) {left=1;}
if (IsKeyPressed(380)==1) {down=1;}
if (IsKeyPressed(372)==1) {up=1;}
}
And change them so left/right movement won't be triggered if up or down are pressed, and vis versa, something like (untested):
if ((IsInterfaceEnabled()==1)&&(IsGamePaused()==0)) {
if (IsKeyPressed(377)==1) {if (up == 0 && down == 0) right=1;}
if (IsKeyPressed(375)==1) {if (up == 0 && down == 0) left=1;}
if (IsKeyPressed(380)==1) {if (left == 0 && right == 0) down=1;}
if (IsKeyPressed(372)==1) {if (left == 0 && right == 0) up=1;}
}
2)
a) What Steve said. (http://americangirlscouts.org/agswiki/index.php/Coding_Contest)
b) Not sure what you mean. Would something like this suggestion from Akumayo (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23869.msg295606#msg295606) help?
c) mouse.SetPosition(x,y) (http://www.adventuregamestudio.co.uk/manual/Mouse.SetPosition.htm)
Also, you'd need to add conditions to the module to control the mouse, rather than the character. I think the (IsGamePaused()==0) could be used for this, since a PopupModal GUI pauses the game. E.g.:
if ((IsInterfaceEnabled()==1)&&(IsGamePaused()==0)) {
// Blah Blah - existing keyboard control stuff goes here
}
else if ((IsInterfaceEnabled()==1)) {
if (IsKeyPressed(377)==1) {if (mouse.x < system.viewport_width) mouse.SetPosition(mouse.x+1, mouse.y);}
if (IsKeyPressed(375)==1) {if (mouse.x > 0) mouse.SetPosition(mouse.x-1, mouse.y);}
if (IsKeyPressed(380)==1) {if (mouse.y < system.viewport_height) mouse.SetPosition(mouse.x, mouse.y+1);}
if (IsKeyPressed(372)==1) {if (mouse.y > 0) mouse.SetPosition(mouse.x, mouse.y-1);}
}
Just remember to turn the cursor on/off as needed (mouse.Visible property).
You'll probably also need to do some coding to make a keypress act like a mouse click. Come to think of it, that might be an answer for 2b, too - make the X and Y keys act like pressing OK/Cancel buttons on a GUI. (It might also be in one of the Coding Comp entries.)
2) For the talking you must make sure you are close to a NPC. So when the x button is pressed you can call a function that first tests 1) if you are next to a NPC and 2) you are facing that NPC. You don't need hotspots nor regions for this.
It was discussed here last: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=13649.120
b) Yes. For the appropriate GUI if pressed confirm you open the new gui or action with a Wait() command and cancel would do the same but close the gui or go to a previous gui, all the time setting your cursor to the correct location. Not sure what you mean too. To make the entire interface keyboard controlled for me in Kludden meant lots of lines of code in the repeatedly exe function with a state variable indicating which gui is being accessed (inventory, stats, equipment, battle, save, etc) so I might have done it wrong.
I did the same as buloght when I made Anna. I made a variable that knew what menu you were looking at and what part was higlighted and used repeatedly execute to detect key presses and change the menu. It was a fast but fairly messy way of making a keyboard-controlled menu.
I have a new question ready: Is it possible for me to make a character run instead of walk when I press e.g. the up-arrow and the shift-key at the same time? If so, what is the codenumber of the shift-key?
thanks in advance,
~Yurina
You should just need to add another check, using IsKeyPressed, e.g.:
if (keycode == 372) { // Up arrow
if (IsKeyPressed(403) ){ // Left Shift
//RUN
}
else {
// WALK
}
}
Ah, I get it.
Thanks Ashen!
~Yurina