I have been hiting my head against the wall for a couple of hours now.
I have just finally got the AGS controller working.
I cannot get it to assign the movement buttons or the action button (Z) from my keyboard. I'm using the Keyboard Module 102.
I've only managed to do it by triggering the direct animations onto the pad itself, which is a totally dumb way of doing it, and limiting ofc. :-[
I'm thinking perhaps i need to import the scripts into the global script and then do something..I just don't know what syntax i'm looking for, at all.
The manual unfortunaly does not have a section on the basic usages of the AGS controller :~(
Edit: I'm using isKeyPressed not On_Key_Press, maybe that's the issue?!
I mean looking at the scripts it does look like the ASCII or the eLeftArrow has been replaced with the modules own nicknames. ???
Still that don't explain why i get no action with simulate eKeyZ. (roll). Just like always i'm misinterpreting AGS features. Hence the user description AGS n00b.
GlobalScript.asc
if (gamepad.GetAxis(0) < -20)
Game.SimulateKeyPress(KeyboardMovement_KeyLeft); //or eKeyLeftArrow, or (for action button attempts) eKeyZ or 90...Out of ideas.
Can you post the definition of this KeyboardMovement_KeyLeft ? From the module's script or header, not sure where it is defined.
Also please always tell where exactly (what script module / function) do you have this code you posted.
EDIT: Ah. By the way, I made an experiment with the KeyboardMovement module that comes with Sierra-template, and found one scenario that could be a problem.
There are two key modes with it: Key Tapping mode and Key Pressed mode. Key Tapping mode means that pressing same key second time will make character stop moving. Because gamepad may send axis signals repeatedly, this may be received as multiple key presses in a row, and character will begin walking and stop walking immediately.
QuoteCan you post the definition of this KeyboardMovement_KeyLeft ? From the module's script or header, not sure where it is defined.
That was just an example, that didn't work. It's not defined anywhere else then in the keyboard module 102's script. Since i've imported that script. That's all i've done.
I don't know if this is what you look for when you say defined, but here is how i've "defined" the Z button. Is it wrong?
I've also tried to add this code into the global script/header, but no success. I'm doing something wrong, clearly.
As for definition for the leftarrow otherwise all i can say is that yeah it's the keyboard modules script working. I'm not assigning anything different to them.
All i do is "check for loops" if player is turned there, that happens, etc.
That code is coming from a custom script called Actions, that i'm working on. i have NOTHING in Actions.Ash tho.
Actions.asc
//Actions.asc
if (IsKeyPressed(eKeyZ)) //PUNCH BUTTON HERE COMES THE MESS; Här börjar RÖRAN :DDDDDDDDD!
{
if (cAxl.Loop==2 || cAxl.Loop==3 || cAxl.Loop==4 || cAxl.Loop==5) //RIGHT PUNCH HIT, All loops are RIGHT/positioned player v_Axl_WalkAction
{
cAxl.Animate (10, 0, eOnce, eNoBlock);
cAxl.SetIdleView(5, 0);
cAxl.Baseline=0;
}
else if (cAxl.IdleView==5) //RIGHT-PUNCH - Empty in the Air Punch, No Target Hit.
{
cAxl.UnlockView();
cAxl.Animate (10, 0, eOnce, eNoBlock);
cAxl.SetIdleView(5, 0);
cAxl.Baseline=0;
}
else if (cAxl.IdleView==4) //LEFT-PUNCH - Empty in the Air Punch, No Target Hit.
{
cAxl.UnlockView();
cAxl.Animate (11, 0, eOnce, eNoBlock);
cAxl.SetIdleView(4, 0);
cAxl.Baseline=0;
}
Edit: Crimson, i'm using Pressing mode btw!
Is this perhaps what you mean?
// Main script for module 'KeyboardMovement'
//****************************************************************************************************
// DEFINITIONS
//****************************************************************************************************
#define DISTANCE 10000// distance player walks in Tapping mode before he stops
enum KeyboardMovement_Directions {
eKeyboardMovement_Stop,
eKeyboardMovement_DownLeft,
eKeyboardMovement_Down,
eKeyboardMovement_DownRight,
eKeyboardMovement_Left,
eKeyboardMovement_Right,
eKeyboardMovement_UpLeft,
eKeyboardMovement_Up,
eKeyboardMovement_UpRight
//eKeyboardMovement_Punch,
};
//****************************************************************************************************
// VARIABLES
//****************************************************************************************************
// keycodes as variables for future key customization functions (static variables?):
int KeyboardMovement_KeyDown = 380; // down arrow
int KeyboardMovement_KeyLeft = 375; // left arrow
int KeyboardMovement_KeyRight = 377; // right arrow
int KeyboardMovement_KeyUp = 372; // up arrow
int KeyboardMovement_KeyDownRight = 381; // PgDn (numpad)
int KeyboardMovement_KeyUpRight = 373; // PgUp (numpad)
int KeyboardMovement_KeyDownLeft = 379; // End (numpad)
int KeyboardMovement_KeyUpLeft = 371; // Home (numpad)
int KeyboardMovement_KeyStop = 376; // 5 (numpad)
KeyboardMovement_Modes KeyboardMovement_Mode = eKeyboardMovement_None; // stores current keyboard control mode (disabled by default)
KeyboardMovement_Directions KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; // stores current walking direction of player character
//****************************************************************************************************
// USER FUNCTIONS
//****************************************************************************************************
//====================================================================================================
static function KeyboardMovement::SetMode(KeyboardMovement_Modes mode) {
KeyboardMovement_Mode = mode;
}
//====================================================================================================
// key customization functions here
//====================================================================================================
//****************************************************************************************************
// EVENT HANDLER FUNCTIONS
//****************************************************************************************************
Controller*gamepad;
//====================================================================================================
int _dx, _dy;
int left_frames, right_frames, up_frames, down_frames;
function repeatedly_execute() {
//--------------------------------------------------
// Pressing mode
//--------------------------------------------------
if ((IsGamePaused() == true) || (KeyboardMovement_Mode != eKeyboardMovement_Pressing) || (IsInterfaceEnabled() == false) || (player.on == false)) return 0;
// if game is paused, module or mode disabled, interface disabled or player character hidden, quit function
bool left, up, right, down;
if (IsKeyPressed(KeyboardMovement_KeyUpLeft)) { up = true; left = true; }
if (IsKeyPressed(KeyboardMovement_KeyUp)) up = true;
if (IsKeyPressed(KeyboardMovement_KeyUpRight)) { up = true; right = true; }
if (IsKeyPressed(KeyboardMovement_KeyRight)) right = true;
if (IsKeyPressed(KeyboardMovement_KeyDownRight)) { down = true; right = true; }
if (IsKeyPressed(KeyboardMovement_KeyDown)) down = true;
if (IsKeyPressed(KeyboardMovement_KeyDownLeft)) { down = true; left = true; }
if (IsKeyPressed(KeyboardMovement_KeyLeft)) left = true;
if (IsKeyPressed(KeyboardMovement_KeyStop)) { up = false; left = false; down = false; right = false; }
if (left) left_frames++; else left_frames = 0;
if (right) right_frames++; else right_frames = 0;
if (left && right) {
left = left_frames < right_frames;
right = !left;
}
if (up) up_frames++; else up_frames = 0;
if (down) down_frames++; else down_frames = 0;
if (up && down) {
up = up_frames < down_frames;
down = !up;
}
int dx = right * DISTANCE - left * DISTANCE;
int dy = down * DISTANCE - up * DISTANCE;
if (dx != _dx || dy != _dy) player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates
_dx = dx; _dy = dy;
}
//====================================================================================================
function on_key_press(int keycode) {
//--------------------------------------------------
// Tapping mode
//--------------------------------------------------
if ((IsGamePaused() == true) || (KeyboardMovement_Mode != eKeyboardMovement_Tapping) || (IsInterfaceEnabled() == false) || (player.on == false)) return 0;
// if game is paused, module or mode disabled, interface disabled or player character hidden, quit function
KeyboardMovement_Directions newdirection; // declare variable storing new direction
// get new direction:
if (keycode == KeyboardMovement_KeyDownRight) newdirection = eKeyboardMovement_DownRight; // if down-right key pressed, set new direction to Down-Right
else if (keycode == KeyboardMovement_KeyUpRight) newdirection = eKeyboardMovement_UpRight;
else if (keycode == KeyboardMovement_KeyDownLeft) newdirection = eKeyboardMovement_DownLeft;
else if (keycode == KeyboardMovement_KeyUpLeft) newdirection = eKeyboardMovement_UpLeft;
else if (keycode == KeyboardMovement_KeyDown) newdirection = eKeyboardMovement_Down;
else if (keycode == KeyboardMovement_KeyLeft) newdirection = eKeyboardMovement_Left;
else if (keycode == KeyboardMovement_KeyRight) newdirection = eKeyboardMovement_Right;
else if (keycode == KeyboardMovement_KeyUp) newdirection = eKeyboardMovement_Up;
else if (keycode == KeyboardMovement_KeyStop) newdirection = eKeyboardMovement_Stop; // if stop key pressed, set to stop player character
if (newdirection != KeyboardMovement_CurrentDirection) { // if new direction is different from current direction
if (newdirection == eKeyboardMovement_Stop) player.StopMoving(); // if new direction is the Stop command, stop movement of player character
else { // if new direction is NOT the Stop command
int dx, dy; // declare variables storing new walk coordinates
if (newdirection == eKeyboardMovement_DownRight) {
dx = DISTANCE;
dy = DISTANCE;
}
else if (newdirection == eKeyboardMovement_UpRight) {
dx = DISTANCE;
dy = -DISTANCE;
}
else if (newdirection == eKeyboardMovement_DownLeft) {
dx = -DISTANCE;
dy = DISTANCE;
}
else if (newdirection == eKeyboardMovement_UpLeft) {
dx = -DISTANCE;
dy = -DISTANCE;
}
else if (newdirection == eKeyboardMovement_Down) {
dx = 0;
dy = DISTANCE;
}
else if (newdirection == eKeyboardMovement_Left) {
dx = -DISTANCE;
dy = 0;
}
else if (newdirection == eKeyboardMovement_Right) {
dx = DISTANCE;
dy = 0;
}
else if (newdirection == eKeyboardMovement_Up) {
dx = 0;
dy = -DISTANCE;
}
player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates
}
KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction
}
else { // if new direction is same as current direction
player.StopMoving(); // stop player character
KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; // update current direction
}
}
//====================================================================================================
function on_event(EventType event, int data) {
if (event == eEventLeaveRoom) KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop;
}
//====================================================================================================
Please tell what template do you use for your game. For instance, Sierra template comes with its own KeyboardMovement module, so first thing is to double check that it don't conflict with the one you imported.
Quote from: Crimson Wizard on Thu 29/10/2020 18:01:19
Please tell what template do you use for your game. For instance, Sierra template comes with its own KeyboardMovement module, so first thing is to double check that it don't conflict with the one you imported.
Omg, i don't even know! :-[ I deleted most of the scripts. Is there anyway i can see anywhere what it is?
I do believe this actually is the sierra template tho, but most of the times i've used the Thumbleweed template.
Scripts i'm using. PPcollision & Keyboard Movement 102. From my eyes nothing is conflicting..I've already tried different keyboard scripts together before, and it was no issue.
So i lean towards what you've said in the previous post..
Globalscript.asc
Controller*gamepad;
function game_start()
{
gamepad = Controller.Open(0);
cAxl.SetIdleView(2, -30);
cEnemy1.SetIdleView(3, -30);
Mouse.ControlEnabled=false;
Mouse.Visible=false;
KeyboardMovement.SetMode(eKeyboardMovement_Pressing);
// set KeyboardMovement movement mode
}
// put anything you want to happen every game cycle in here
//JOYSTICK PLUGIN CONTROLLER BUTTONS
//11 = Start Button
//8 - Select Button
//7 - Trigger Right 1
//6 - Trigger Left 1
//5 - Trigger Right 2
//4 - Trigger Left 2
//3 - Square/Fyrkant
//2 - Cross/Kryss
//1 - Circle
//0 - Triangle/Trekant
function repeatedly_execute()
{
if (gamepad.GetAxis(0) < -20)
Game.SimulateKeyPress(90);
if (gamepad.GetAxis(0) > 20)
{
cAxl.x++;
}
else if (gamepad.IsButtonDownOnce(3)) //RIGHT Hit
{
cAxl.Animate (10, 0, eOnce, eNoBlock);
cAxl.SetIdleView(5, 0);
cAxl.Baseline=0;
cAxl.Animate(10, 0, eOnce, eNoBlock);
}
Enemy1_HealthBar(); //Checkar Enemy1's hälsa.
cEnemy1.FollowCharacter(cAxl);
if (Enemy_Type1_Death_Count==3) //Set this to however many enemies of the TYPE1 you want to show up..
{
cEnemy1.Clickable=true;
cEnemy1.SetIdleView(3, 0);
cEnemy1.LockViewFrame(3, 0, 0);
cEnemy1.UnlockView(eKeepMoving);
cEnemy1.SetIdleView(3, 0);
cEnemy1.Transparency=0;
Signal_Got_Hit=0;
cEnemy1.ChangeRoom(2);
gSignal_Healthbar.Visible=false;
Is_Enemy1_In_Storage=false;
Go_Next_Round();
}
if (Is_Enemy1_In_Storage==true && Enemy_Type1_Death_Count==2)
{
//Display ("DEATHCOUNT - 2 (TIME FOR LEFT SIDE ACTION");
Enemy_Type1_Respawn_LEFT();
Is_Enemy1_In_Storage=false;
}
else if (Is_Enemy1_In_Storage==false)
{
}
else if (Is_Enemy1_In_Storage==true && Enemy_Type1_Death_Count==1)
{
// Display ("DEATHCOUNT - 1 (TIME FOR RIGHT SIDE ACTION");
Enemy_Type1_Respawn_RIGHT();
Is_Enemy1_In_Storage=false;
}
Player_Actions();
}
function repeatedly_execute_always()
{
}
// put here all enemy animations, hit's death animations, etc in here.
function late_repeatedly_execute_always()
{
Trashcan_Beater();
Signal_Hit_Ground();
Enemy1_HealthBar(); //Checkar Enemy1's hälsa.
cEnemy1.FollowCharacter(cAxl);
if (Enemy_Type1_Death_Count==3) //Set this to however many enemies of the TYPE1 you want to show up..
{
cEnemy1.Clickable=true;
cEnemy1.SetIdleView(3, 0);
cEnemy1.LockViewFrame(3, 0, 0);
cEnemy1.UnlockView(eKeepMoving);
cEnemy1.SetIdleView(3, 0);
cEnemy1.Transparency=0;
Signal_Got_Hit=0;
cEnemy1.ChangeRoom(2);
gSignal_Healthbar.Visible=false;
Is_Enemy1_In_Storage=false;
Go_Next_Round();
}
if (Is_Enemy1_In_Storage==true && Enemy_Type1_Death_Count==2)
{
//Display ("DEATHCOUNT - 2 (TIME FOR LEFT SIDE ACTION");
Enemy_Type1_Respawn_LEFT();
Is_Enemy1_In_Storage=false;
}
else if (Is_Enemy1_In_Storage==false)
{
}
else if (Is_Enemy1_In_Storage==true && Enemy_Type1_Death_Count==1)
{
// Display ("DEATHCOUNT - 1 (TIME FOR RIGHT SIDE ACTION");
Enemy_Type1_Respawn_RIGHT();
Is_Enemy1_In_Storage=false;
}
Signal_Hit_Ground();
}
// c
function dialog_request(int param) {
}
function on_key_press(eKeyCode keycode)
{
if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
if (keycode == eKeyF9) RestartGame(); // F9
if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx"); // F12
if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
//if (keycode == eKeyZ) Player_Actions();
}
function gPlayer_Healthbar_OnClick(GUI *theGui, MouseButton button)
{
}
function b_Player_Health_OnClick(GUIControl *control, MouseButton button)
{
}
Quote from: Olleh19 on Thu 29/10/2020 18:04:25
Omg, i don't even know! :-[ I deleted most of the scripts. Is there anyway i see anywhere what it is?
I do believe this actually is the sierra template tho, but most of the times i've used the Thumbleweed template.
Well, if you deleted most scripts, that may not be a problem anymore.
Quote from: Crimson Wizard on Thu 29/10/2020 18:08:03
Quote from: Olleh19 on Thu 29/10/2020 18:04:25
Omg, i don't even know! :-[ I deleted most of the scripts. Is there anyway i see anywhere what it is?
I do believe this actually is the sierra template tho, but most of the times i've used the Thumbleweed template.
Well, if you deleted most scripts, that may not be a problem anymore.
I'm confused. Am i totally off in the syntax, or should the things i wrote out "work" in theory? ???
102 is the old keyboard movement script, but perhaps that is still inside the Tumbleweed template.
Quote from: Crimson Wizard on Thu 29/10/2020 17:46:11Key Tapping mode means that pressing same key second time will make character stop moving. Because gamepad may send axis signals repeatedly, this may be received as multiple key presses in a row, and character will begin walking and stop walking immediately.
One of the changes in the replacement version was to fix the stuttering caused by this, although I only tested against the keyboard repeat rate.
I made an experiment with Pressing mode, and SimulateKeyPress does not cause character to move at all. I don't yet know why, maybe SimulateKeyPress is not suitable for this for some reason, as in, IsKeyPressed does not detect this simulation (although, I wondered if it should).
I'd have to investigate how engine works more closely to find this out. But for you, I would suggest to don't use "SimulateKeyPress" in this case, but add controller checks directly inside movement module.
For example, where it sais:
if (IsKeyPressed(KeyboardMovement_KeyLeft)) left = true;
Replace with:
if (IsKeyPressed(KeyboardMovement_KeyLeft) || gamepad.GetAxis(0) < -20) left = true;
Quote from: morganw on Thu 29/10/2020 18:12:05
102 is the old keyboard movement script, but perhaps that is still inside the Tumbleweed template.
Quote from: Crimson Wizard on Thu 29/10/2020 17:46:11Key Tapping mode means that pressing same key second time will make character stop moving. Because gamepad may send axis signals repeatedly, this may be received as multiple key presses in a row, and character will begin walking and stop walking immediately.
One of the changes in the replacement version was to fix the stuttering caused by this, although I only tested against the keyboard repeat rate.
IF, i've used the thumblweed template. Those scripts are DELETED inside this project. If that makes things worse, or better. I dont know!
Thanks for the code Crimson. However i get a nullpoint referenced with it. I don't know what i'm doing wrong.
I replaced it like you've said.
Edit: What should be called in the rep exec then?
Probably why i get null point...
Edit again: Wait, so what you are saying is I HAVE TO replace ALL isKeyPressed with On_key_pressed is that what you are saying??
I actually should have done this a couple of days ago, i've just been lazy. I "scripted it wrong" to start with, until i realised the "best way" is to use On_Key_press for the type of game i'm doing right now.
Quote from: Olleh19 on Thu 29/10/2020 18:21:48
Edit again: Wait, so what you are saying is I HAVE TO replace ALL isKeyPressed with On_key_pressed is that what you are saying??
What... this is absolutely not what I was saying. Also, you can't just replace IsKeyPressed with on_key_pressed, they are things so different that are not replaceable...
I was suggesting to ADD "gamepad.GetAxis" condition to each "IsKeyPressed(KeyboardMovement_xxx)" condition inside the keyboard movement module.
But, first of all, I dont know what "gamepad" is, but hoped you know since you are using it elsewhere. Can you explain then, what is this "gamepad" variable, and how do you declare or get it?
EDIT: oh, nevermind, I found it in your script, you define this in GlobalScript.asc.
Ok, I need to think how to let keyboard module use this variable...
Quote from: Crimson Wizard on Thu 29/10/2020 18:27:22
Quote from: Olleh19 on Thu 29/10/2020 18:21:48
Edit again: Wait, so what you are saying is I HAVE TO replace ALL isKeyPressed with On_key_pressed is that what you are saying??
What... this is absolutely not what I was saying. Also, you can't just replace IsKeyPressed with on_key_pressed, they are things so different that are not replaceable...
I was suggesting to ADD "gamepad.GetAxis" condition to each "IsKeyPressed(KeyboardMovement_xxx)" condition inside the keyboard movement module.
But, first of all, I dont know what "gamepad" is, but hoped you know since you are using it elsewhere. Can you explain then, what is this "gamepad" variable, and how do you declare or get it?
EDIT: oh, nevermind, I found it in your script, you define this in GlobalScript.asc.
Ok, I need to think how to let keyboard module use this variable...
Oh, sorry i confused you with someone else. Sorry! I was told earlier to use On_Key_press for the action button instead. My bad!
Thank you very much for trying to help out in a tough situation(!)
Ohh, I've read the KeyboardMovement script you posted, and there is already "Controller*gamepad;" line added there. But gamepad is not initialized anywhere inside that module, this is why you are getting null pointer errors.
So, what you need to do is to find that line in the module (KeyboardMovement102.asc), and add following code right below it:
function game_start()
{
gamepad = Controller.Open(0);
}
I hope that will work, but dont know if this is correct to call Controller.Open(0) two times (because you also have same thing in GlobalScript). But let's try that first, and see if it works.
Quote from: Olleh19 on Thu 29/10/2020 18:35:26
I was told earlier to use On_Key_press for the action button instead.
This is situation-dependent. IsKeyPressed is used when you have to check for keys being held continiously, while on_key_press function is used to detect occasional key presses.
I'm sorry. I should have "cleaned up" ofc all my "attempts" that's why you have Gamepad all over the place, and "open".
I'll try your suggestions now, i'll edit once done.
Edit: Ok, i mean what should i call now in repeatedly execute??
if (gamepad.GetAxis(0) < 20)
{
Display ("");
}
HAHA, ofc i get nothing, i didnt type anyrthing! (laugh)
Quote from: Olleh19 on Thu 29/10/2020 18:41:42
Edit: Ok, i mean what should i call now in repeatedly execute??
if (gamepad.GetAxis(0) < 20)
{
Display ("");
}
I don't get anything happening with Display, it ended working now, it seems.
Umm, so you are testing whether controller works by placing Display? First of all, I then suggest to put some actual text there, because Display with empty string will probably not be displayed at all. Something like "Display("TEST")".
Please tell, if using controller makes this message appear?
Yes, it does it was a mistake, i'm laughing out loud!
But i wonder what to call in the function KeyboardMovement_KeyLeft(); etc
Edit: yes, im testing it because before when i got null points previously those showed up no matter what action was in the button. So i usually try display or player.say...Bad way to test things? :-[
Ok, so, have you tried adding the code I suggested above, into the keyboardmovement module?
I'm not sure at which point you are currently.
Quote from: Crimson Wizard on Thu 29/10/2020 18:51:39
Ok, so, have you tried adding the code I suggested above, into the keyboardmovement module?
I'm not sure at which point you are currently.
// Main script for module 'KeyboardMovement'
//****************************************************************************************************
// DEFINITIONS
//****************************************************************************************************
#define DISTANCE 10000// distance player walks in Tapping mode before he stops
enum KeyboardMovement_Directions {
eKeyboardMovement_Stop,
eKeyboardMovement_DownLeft,
eKeyboardMovement_Down,
eKeyboardMovement_DownRight,
eKeyboardMovement_Left,
eKeyboardMovement_Right,
eKeyboardMovement_UpLeft,
eKeyboardMovement_Up,
eKeyboardMovement_UpRight
//eKeyboardMovement_Punch,
};
//****************************************************************************************************
// VARIABLES
//****************************************************************************************************
// keycodes as variables for future key customization functions (static variables?):
int KeyboardMovement_KeyDown = 380; // down arrow
int KeyboardMovement_KeyLeft = 375; // left arrow
int KeyboardMovement_KeyRight = 377; // right arrow
int KeyboardMovement_KeyUp = 372; // up arrow
int KeyboardMovement_KeyDownRight = 381; // PgDn (numpad)
int KeyboardMovement_KeyUpRight = 373; // PgUp (numpad)
int KeyboardMovement_KeyDownLeft = 379; // End (numpad)
int KeyboardMovement_KeyUpLeft = 371; // Home (numpad)
int KeyboardMovement_KeyStop = 376; // 5 (numpad)
KeyboardMovement_Modes KeyboardMovement_Mode = eKeyboardMovement_None; // stores current keyboard control mode (disabled by default)
KeyboardMovement_Directions KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; // stores current walking direction of player character
//****************************************************************************************************
// USER FUNCTIONS
//****************************************************************************************************
//====================================================================================================
static function KeyboardMovement::SetMode(KeyboardMovement_Modes mode) {
KeyboardMovement_Mode = mode;
}
//====================================================================================================
// key customization functions here
//====================================================================================================
//****************************************************************************************************
// EVENT HANDLER FUNCTIONS
//****************************************************************************************************
Controller*gamepad;
//====================================================================================================
function game_start()
{
gamepad = Controller.Open(0);
}
int _dx, _dy;
int left_frames, right_frames, up_frames, down_frames;
function repeatedly_execute() {
//--------------------------------------------------
// Pressing mode
//--------------------------------------------------
if ((IsGamePaused() == true) || (KeyboardMovement_Mode != eKeyboardMovement_Pressing) || (IsInterfaceEnabled() == false) || (player.on == false)) return 0;
// if game is paused, module or mode disabled, interface disabled or player character hidden, quit function
bool left, up, right, down;
if (IsKeyPressed(KeyboardMovement_KeyUpLeft)) { up = true; left = true; }
if (IsKeyPressed(KeyboardMovement_KeyUp)) up = true;
if (IsKeyPressed(KeyboardMovement_KeyUpRight)) { up = true; right = true; }
if (IsKeyPressed(KeyboardMovement_KeyRight)) right = true;
if (IsKeyPressed(KeyboardMovement_KeyDownRight)) { down = true; right = true; } //I'll add the rest later if this works ofc!
if (IsKeyPressed(KeyboardMovement_KeyDown)) down = true;
if (IsKeyPressed(KeyboardMovement_KeyDownLeft)) { down = true; left = true; }
if (IsKeyPressed(KeyboardMovement_KeyLeft) || gamepad.GetAxis(0) > 20) left = true;
if (IsKeyPressed(KeyboardMovement_KeyStop)) { up = false; left = false; down = false; right = false; }
if (left) left_frames++; else left_frames = 0;
if (right) right_frames++; else right_frames = 0;
if (left && right) {
left = left_frames < right_frames;
right = !left;
}
if (up) up_frames++; else up_frames = 0;
if (down) down_frames++; else down_frames = 0;
if (up && down) {
up = up_frames < down_frames;
down = !up;
}
int dx = right * DISTANCE - left * DISTANCE;
int dy = down * DISTANCE - up * DISTANCE;
if (dx != _dx || dy != _dy) player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates
_dx = dx; _dy = dy;
}
//====================================================================================================
function on_key_press(int keycode) {
//--------------------------------------------------
// Tapping mode
//--------------------------------------------------
if ((IsGamePaused() == true) || (KeyboardMovement_Mode != eKeyboardMovement_Tapping) || (IsInterfaceEnabled() == false) || (player.on == false)) return 0;
// if game is paused, module or mode disabled, interface disabled or player character hidden, quit function
KeyboardMovement_Directions newdirection; // declare variable storing new direction
// get new direction:
if (keycode == KeyboardMovement_KeyDownRight) newdirection = eKeyboardMovement_DownRight; // if down-right key pressed, set new direction to Down-Right
else if (keycode == KeyboardMovement_KeyUpRight) newdirection = eKeyboardMovement_UpRight;
else if (keycode == KeyboardMovement_KeyDownLeft) newdirection = eKeyboardMovement_DownLeft;
else if (keycode == KeyboardMovement_KeyUpLeft) newdirection = eKeyboardMovement_UpLeft;
else if (keycode == KeyboardMovement_KeyDown) newdirection = eKeyboardMovement_Down;
else if (keycode == KeyboardMovement_KeyLeft) newdirection = eKeyboardMovement_Left;
else if (keycode == KeyboardMovement_KeyRight) newdirection = eKeyboardMovement_Right;
else if (keycode == KeyboardMovement_KeyUp) newdirection = eKeyboardMovement_Up;
else if (keycode == KeyboardMovement_KeyStop) newdirection = eKeyboardMovement_Stop; // if stop key pressed, set to stop player character
if (newdirection != KeyboardMovement_CurrentDirection) { // if new direction is different from current direction
if (newdirection == eKeyboardMovement_Stop) player.StopMoving(); // if new direction is the Stop command, stop movement of player character
else { // if new direction is NOT the Stop command
int dx, dy; // declare variables storing new walk coordinates
if (newdirection == eKeyboardMovement_DownRight) {
dx = DISTANCE;
dy = DISTANCE;
}
else if (newdirection == eKeyboardMovement_UpRight) {
dx = DISTANCE;
dy = -DISTANCE;
}
else if (newdirection == eKeyboardMovement_DownLeft) {
dx = -DISTANCE;
dy = DISTANCE;
}
else if (newdirection == eKeyboardMovement_UpLeft) {
dx = -DISTANCE;
dy = -DISTANCE;
}
else if (newdirection == eKeyboardMovement_Down) {
dx = 0;
dy = DISTANCE;
}
else if (newdirection == eKeyboardMovement_Left) {
dx = -DISTANCE;
dy = 0;
}
else if (newdirection == eKeyboardMovement_Right) {
dx = DISTANCE;
dy = 0;
}
else if (newdirection == eKeyboardMovement_Up) {
dx = 0;
dy = -DISTANCE;
}
player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates
}
KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction
}
else { // if new direction is same as current direction
player.StopMoving(); // stop player character
KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; // update current direction
}
}
//====================================================================================================
function on_event(EventType event, int data) {
if (event == eEventLeaveRoom) KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop;
}
//====================================================================================================
SUCCESS! It actually works.
I'm surprised. I thought i had to do syntax in the repeatedly???
Now with the Action Button on the keyboard Z, still tho.
Thats its own "function" i guess, its not part of the keyboard module. alltho i ofc would like it to be.
Quote from: Olleh19 on Thu 29/10/2020 18:56:32
I'm surprised. I thought i had to do syntax in the repeatedly???
You probably should check for controller axes in repeatedly_execute. What "syntax" are you refering to?
Quote from: Olleh19 on Thu 29/10/2020 18:56:32
Now with the Action Button on the keyboard Z, still tho.
Thats its own "function" i guess, its not part of the keyboard module. alltho i ofc would like it to be.
I don't understand what you mean here though.
if (gamepad.GetAxis(0) < -20) \
{
do stuff
}
That type of "function" where you clearly should add forexample i guess the left button, but its not being used now, its been solved another way, which interests me.
So what i mean is here is that version of the button im going to use for the Z assigned keyboard.
As the example from the ags controller thread on here:
if (gamepad.IsButtonDownOnce(11))
{
//click on Z button to get a punch.."guess working again"
}
my Z button is in the Actions. This type of code not posting the whole code, no point in doing that.. Then i "get it". I hope....
Actions.Asc
if (IsKeyPressed(eKeyZ)) //PUNCH BUTTON HERE COMES THE MESS; Här börjar RÖRAN :DDDDDDDDD!
{
if (cAxl.Loop==2 || cAxl.Loop==3 || cAxl.Loop==4 || cAxl.Loop==5) //RIGHT PUNCH HIT, All loops are RIGHT/positioned player v_Axl_WalkAction
{
Here's my take: https://pastebin.com/raw/8CKW9FAY
Works fine for me with the template I found the KM 1.02 module in, the 3.43 Sierra one.
I also chose a smaller angle for diagonal walking, this a) fits the perspective better and b) causes AGS to use the sideviews.
Quote from: Khris on Thu 29/10/2020 19:06:00
Here's my take: https://pastebin.com/raw/8CKW9FAY
Works fine for me with the template I found the KM 1.02 module in, the 3.43 Sierra one.
I also chose a smaller angle for diagonal walking, this a) fits the perspective better and b) causes AGS to use the sideviews.
I replaced the entire script (guessing that was your idea). I get a error Parse error unexpect joystick line 60:
Edit: I think perhaps your script is based on the old joystick plugin???
I've tried editing it, but i still get errors..
Yeah, it's the one by WyZ from August 2010. Didn't know there's a newer version?
If you link me to the newer version, I'll fix the script.
Quote from: Khris on Thu 29/10/2020 19:25:00
Yeah, it's the one by WyZ from August 2010. Didn't know there's a newer version?
If you link me to the newer version, I'll fix the script.
https://www.adventuregamestudio.co.uk/forums/index.php?topic=57129.0
Edit: I'm getting a scary vibe now, using Crimsons version my Left button completely flips out. It just moves constantly to the left, when the right button works perfectly fine.
I hope my controller isn't broken. Have to try it on my laptop..
Edit Again: tried an emulator, my controller is fine. Something is not doing it in the code..Whatever that is!
Right, here's the version for the AGSController.dll plugin: https://pastebin.com/raw/G8RwyhBA
Regarding the character moving on its own, my left stick is pretty severely off the center if I don't touch it, at about -3000, -7000. That's why I set the dead zone to +/- 10000 in my script. The maximum value is +/- 32768 though, so that's not a problem.
Quote from: Khris on Thu 29/10/2020 19:59:30
Right, here's the version for the AGSController.dll plugin: https://pastebin.com/raw/G8RwyhBA
Regarding the character moving on its own, my left stick is pretty severely off the center if I don't touch it, at about -3000, -7000. That's why I set the dead zone to +/- 10000 in my script. The maximum value is +/- 32768 though, so that's not a problem.
Ahh, that's great to hear.
Undefined token 'iblGameName' i get tho.
edit: i just deleted, works perfectly, amazing job Khris!
Right, I was debugging the axis values handling :-D
Glad it's working now!
SOLVED: I've just put it in the wrong place. I was not thinking correctly i believe. I tried to run ekeyZ || gamepad but outside the function in repeately, it should ofc have been INSIDE the function Player_Actions()
Thank god!
The original problem was: The IsKeyPressed Z will NOT assign to the gamecontroller, but the solution is now added.
Problem 2 Solved: How to get Gamepad to work for a Custom scripts functions:
To get it to work in your own Custom scripts. This i did not get to work first either, it's just trial & error, but it turns out you need to pretty much "clone" the globalscript first lines. You need to add this to get the gamepad working inside the custom script:
//top of your custom script.asc before all other functions are introduced, just like in your globalscript...
Controller*gamepad;
function game_start()
{
gamepad = Controller.Open(0);
}
//Global script.asc
Controller*gamepad;
function game_start()
{
//This is NOT for the custom script solution, this is a a separate solution. If you want the gamepad to work in Globalscript only and dont care about doing your Custom functions in other scripts.
gamepad = Controller.Open(0);
cAxl.SetIdleView(2, -30);
cEnemy1.SetIdleView(3, -30);
Mouse.ControlEnabled=false;
Mouse.Visible=false;
KeyboardMovement.SetMode(eKeyboardMovement_Pressing);
// set KeyboardMovement movement mode
}
function Player_Actions() //here is the function..It's declared (if that is what it's called in Globalscript.ash
{
{
player.Say "(This would work if i push the Square button on my gamecontroller");
cAxl.Baseline=1000; // This makes him hit in the face, or else the punches get's behind the enemy's Body.
cEnemy1.Baseline=1; //Try to make this based on Enemy's Y positions instead, so it calculates where it can hit and not..
if (IsKeyPressed(eKeyZ) || gamepad.IsButtonDownOnce(3)) //PUNCH BUTTON - Here is the solution. gamepad needed to be in the actual function NOT OUTSIDE IT in the globalscript; DOH!!!
{
if (cAxl.Loop==2 || cAxl.Loop==3 || cAxl.Loop==4 || cAxl.Loop==5) //RIGHT PUNCH HIT, All loops are RIGHT/positioned player v_Axl_WalkAction
{
cAxl.Animate (10, 0, eOnce, eNoBlock);
cAxl.SetIdleView(5, 0);
cAxl.Baseline=0;
}