Character stops moving after entering a new room and a few other questions

Started by Goldenrod111, Sat 07/02/2009 15:25:24

Previous topic - Next topic

Goldenrod111

I haven't posted for a while, and have just read the "This Forum is For/Not For:"s. "If you ask when the next version is coming out, you will be slapped silly with a moist trout." ;D

Anyway, I am using the Keyboard Movement module that comes in the default game teplate, though I brought it into a game using the emply template, and might be missing some things that I need to have in the global script. My character can move nicely, but he stops moving when he goes into another room. As I want to create the illusion that the rooms are continuous, this is a relitively large problem. I am using the Pressing Mode, but currently the player has to let go of the button and then press it again to move.

Secondly, is there any way to restrict the movement of the character to just four directions (up, down, left, and rigt) with the module, preferably having the player turn in the direction of the second key when it is pressed? (I have less sprites to draw if there is a way to do this ;), butI might decide to make them anyway and make the game a bit more realistic.)

Thirdly, is there any way to make the character run (6 seems to be a good speed in the character editor) when the left shift button is pressed, and walk (speed 3) otherwise?

Finally, to help create the feeling that almost the entire thing is one big room I added some pixels from the next room so the background would scroll to keep the player in the middle of the screen, but I was figuring in having a GUI at the bottom of the screen, and forgot that the GUI didn't change the size of the rest of the screen. Is there any way for the GUI (which should always be open) to reduce the avalible screen area?

I know that some of the questions relating to the arrow keys were already discussed on different threads, but they were from before the Keyboard Movement module, and I thought that there might be another way that I can do it now.

Edit: I have found another problem. I am currently testing the game with two rooms, one located "north" of the other, and am switching between the two with player.ChangeRoomAutoPosition. This works, but after the player takes a step after reentering room 1 he gets flung back to room 2. I attempted to use the following code (properly linked to in the room properties and also tested with <) to reset his position, but it doesn't work.
Code: ags

function room_Load()
{
  if (player.y == Room.TopEdge){
    player.y = Room.TopEdge + 2;
  }
}

Also, is there any way to set the area with which the player tests the walkable areas?

Pumaman

Quote from: Goldengamer111 on Sat 07/02/2009 15:25:24
I am using the Keyboard Movement module that comes in the default game teplate, though I brought it into a game using the emply template, and might be missing some things that I need to have in the global script. My character can move nicely, but he stops moving when he goes into another room. As I want to create the illusion that the rooms are continuous, this is a relitively large problem. I am using the Pressing Mode, but currently the player has to let go of the button and then press it again to move.

There's a global function called on_event that you can add to the global script like this:

function on_event(EventType event, int data)
{
}

See this manual page for the possible EventTypes.
You could handle the Leave Room and Enter Room events here to check and restart the character moving, if you need it to happen globally.

If you only want it to work in one room, just put a player.Walk command in the Player Enters Screen After Fadein event.

QuoteSecondly, is there any way to restrict the movement of the character to just four directions (up, down, left, and rigt) with the module, preferably having the player turn in the direction of the second key when it is pressed? (I have less sprites to draw if there is a way to do this ;), butI might decide to make them anyway and make the game a bit more realistic.)

If you open up the Keyboard Movement script, there is a section with this:

int KeyboardMovement_KeyDownRight = 381; // PgDn (numpad)
int KeyboardMovement_KeyUpRight = 373; // PgUp (numpad)
int KeyboardMovement_KeyDownLeft = 379; // End (numpad)
int KeyboardMovement_KeyUpLeft = 371; // Home (numpad)

The easiest thing is just to change all those numbers to 0 so that it won't pick up the diagonal key presses.

QuoteThirdly, is there any way to make the character run (6 seems to be a good speed in the character editor) when the left shift button is pressed, and walk (speed 3) otherwise?

You can use IsKeyPressed(403) to check if left shift is pressed, and change the character's movement speed accordingly. You can't change the speed while the character is moving, so you'd have to do StopMoving, change the movement speed, then do another Walk command.

QuoteFinally, to help create the feeling that almost the entire thing is one big room I added some pixels from the next room so the background would scroll to keep the player in the middle of the screen, but I was figuring in having a GUI at the bottom of the screen, and forgot that the GUI didn't change the size of the rest of the screen. Is there any way for the GUI (which should always be open) to reduce the avalible screen area?

Well, rooms will always have the entire screen area available, but you can simply ignore the part of the screen that will be covered by the GUI. The room backgrounds are compressed and a completely empty area will hardly take up any space.

QuoteEdit: I have found another problem. I am currently testing the game with two rooms, one located "north" of the other, and am switching between the two with player.ChangeRoomAutoPosition. This works, but after the player takes a step after reentering room 1 he gets flung back to room 2. I attempted to use the following code (properly linked to in the room properties and also tested with <) to reset his position, but it doesn't work.

Well, ChangeRoomAutoPosition places the character 1 pixel within the room edge, so that code will probably not get used.  However, as long as he is moving away from the edge, you shouldn't find it flipping back to the old room.  What resolution is your game?

Goldenrod111

Quote from: Pumaman on Sat 07/02/2009 23:32:14
There's a global function called on_event that you can add to the global script like this:

function on_event(EventType event, int data)
{
}

See this manual page for the possible EventTypes.
You could handle the Leave Room and Enter Room events here to check and restart the character moving, if you need it to happen globally.

If you only want it to work in one room, just put a player.Walk command in the Player Enters Screen After Fadein event.

I would like it to happen globally, but I unfortunately don't know enough code to make this work. Also, the only EventType listed on that page for when the player enters the room happens before the fade in, which wouldn't work here.

Quote
If you open up the Keyboard Movement script, there is a section with this:

int KeyboardMovement_KeyDownRight = 381; // PgDn (numpad)
int KeyboardMovement_KeyUpRight = 373; // PgUp (numpad)
int KeyboardMovement_KeyDownLeft = 379; // End (numpad)
int KeyboardMovement_KeyUpLeft = 371; // Home (numpad)

The easiest thing is just to change all those numbers to 0 so that it won't pick up the diagonal key presses.

That does stop the player from being able to go diagonally when those keys are pressed, but the character does still move at an angle when two arrow keys are pressed. This wasn't that important, though, and I will just make a few more sprites.

Quote
You can use IsKeyPressed(403) to check if left shift is pressed, and change the character's movement speed accordingly. You can't change the speed while the character is moving, so you'd have to do StopMoving, change the movement speed, then do another Walk command.

Sounds good, and very similar to another thread that I read, but how would I restart the Walk command from the Keyboard Module, as that doesn't specify any coordonates (that I can see)?

Quote
Well, rooms will always have the entire screen area available, but you can simply ignore the part of the screen that will be covered by the GUI. The room backgrounds are compressed and a completely empty area will hardly take up any space.

I thought I would have to do something like that, but it shouldn't be any trouble.

Quote
Well, ChangeRoomAutoPosition places the character 1 pixel within the room edge, so that code will probably not get used.  However, as long as he is moving away from the edge, you shouldn't find it flipping back to the old room.  What resolution is your game?

I wonder what the problem is. I am using the 640 x 480 resolution, but my background for that room is 800 x 1024, and my character is 13 x 17, and, if it matters, has a transparent row of pixels on the bottom of the sprite.

Thanks for helping me this far!

Pumaman

Quote from: Goldengamer111 on Sun 08/02/2009 01:11:23
I would like it to happen globally, but I unfortunately don't know enough code to make this work. Also, the only EventType listed on that page for when the player enters the room happens before the fade in, which wouldn't work here.

Well, rather than me giving you a load of script that you don't understand, for now maybe the easiest thing is if you simply put a player.WalkStraight command in the Player Enters Screen event of each room. Then, as you get more confident with AGS scripting, you can move this out into the global script.

Quote
That does stop the player from being able to go diagonally when those keys are pressed, but the character does still move at an angle when two arrow keys are pressed. This wasn't that important, though, and I will just make a few more sprites.

Well, if you want to stick to 4-directional sprites, you can simply set the "DiagonalLoops" property on the character to False in the character editor.

Quote
Sounds good, and very similar to another thread that I read, but how would I restart the Walk command from the Keyboard Module, as that doesn't specify any coordonates (that I can see)?

Well, for straight keyboard movement it actually uses the WalkStraight command. For example, to move the player to the right, you can just do:

player.WalkStraight(player.x + 1000, player.y, eNoBlock);

the +1000 is arbitrary, it basically just sends him as far to the right of his current position as possible.

Quote
I wonder what the problem is. I am using the 640 x 480 resolution, but my background for that room is 800 x 1024, and my character is 13 x 17, and, if it matters, has a transparent row of pixels on the bottom of the sprite.

Thanks for reporting this, I think this is actually a bug in AGS. The ChangeRoomAutoPosition command is usually used for backwards compatibility when upgrading old games, and it does seem to have this problem with games at 640x400 and higher.

This should be fixed in the new 3.1.2 release, see this thread:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36781.0

Goldenrod111

Thanks for the code. I know that it is more work, but I hope that this will solve the problem. About the global scripting, though, I think it would be more of an "I haven't learned this yet" than an "I don't understand this", as, for me, reading the script is only slightly harder than reading a book (good job with that!), and, just as long as the code isn't too complex, I should be able to figure out what it is doing by reading it.

I know about the "DiagonalLoops" property, but I would rather make more sprites instead of only using four directions. It shouldn't be too hard, just a bit more work.

I noticed that the ChangeRoomAutoPosition problem was solved in 3.1.2 R3, but I wasn't able to download it, as my computer thinks that the file is "AGS-3.1.2[1]", with ".2[1]", instead of .exe, being the type of the file. However, I have

Again, thanks for all the help!

Edit: Is there any way for a character's BlockingWidth and BlockingHeight (or something like them) to be used to test for walkable areas, instead of just using the bottom-middle pixel?

Pumaman

QuoteThanks for the code. I know that it is more work, but I hope that this will solve the problem. About the global scripting, though, I think it would be more of an "I haven't learned this yet" than an "I don't understand this", as, for me, reading the script is only slightly harder than reading a book (good job with that!), and, just as long as the code isn't too complex, I should be able to figure out what it is doing by reading it.

Ok, well there are various ways to accomplish what you want, but one possibility would be to check which way the character is facing when they enter a new room, and automatically move them in that direction. Something like this (note, untested):

function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein)
  {
     if (player.Loop == 0) player.WalkStraight(player.x, player.y + 1000, eNoBlock);
     else if (player.Loop == 1) player.WalkStraight(player.x - 1000, player.y, eNoBlock);
     else if (player.Loop == 2) player.WalkStraight(player.x + 1000, player.y, eNoBlock);
     else if (player.Loop == 3) player.WalkStraight(player.x, player.y - 1000, eNoBlock);
  }
}

QuoteI noticed that the ChangeRoomAutoPosition problem was solved in 3.1.2 R3, but I wasn't able to download it, as my computer thinks that the file is "AGS-3.1.2[1]", with ".2[1]", instead of .exe, being the type of the file.

Strange ... you should just be able to rename it to ".exe" and it should work, in that case.

QuoteEdit: Is there any way for a character's BlockingWidth and BlockingHeight (or something like them) to be used to test for walkable areas, instead of just using the bottom-middle pixel?

Currently not -- normal practice is to draw the walkable areas slightly smaller to compensate for this.

Goldenrod111

Quote from: Pumaman on Sun 08/02/2009 23:16:01
Ok, well there are various ways to accomplish what you want, but one possibility would be to check which way the character is facing when they enter a new room, and automatically move them in that direction. Something like this (note, untested):

function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein)
  {
     if (player.Loop == 0) player.WalkStraight(player.x, player.y + 1000, eNoBlock);
     else if (player.Loop == 1) player.WalkStraight(player.x - 1000, player.y, eNoBlock);
     else if (player.Loop == 2) player.WalkStraight(player.x + 1000, player.y, eNoBlock);
     else if (player.Loop == 3) player.WalkStraight(player.x, player.y - 1000, eNoBlock);
  }
}

Thanks! That seems like it might work, though I am not sure about the way that the code calls that before the fade in (I haven't been able to test it yet either).

Quote
Strange ... you should just be able to rename it to ".exe" and it should work, in that case.

That worked, and I now have my very own copy of AGS 3.1.2.80.

Quote
Currently not -- normal practice is to draw the walkable areas slightly smaller to compensate for this.

Ok, I will do that, though it might be a good idea to include something like that in a future release ;).

On a side note, how would I add the game to Vista's Game Explorer? The documentation tells me to run the executable, through the installer, with -registergame, but how would I accomplish that?

Pumaman

Quote from: Goldengamer111 on Mon 09/02/2009 14:24:04
Thanks! That seems like it might work, though I am not sure about the way that the code calls that before the fade in (I haven't been able to test it yet either).

It should be fine in Before Fadein because it's using eNoBlock. If you tried to make a blocking call there it wouldn't work -- but all it's doing is telling the character to start moving -- it's not actually going to try and wait for him to do so.

Quote
On a side note, how would I add the game to Vista's Game Explorer? The documentation tells me to run the executable, through the installer, with -registergame, but how would I accomplish that?

Depends on what installer software you use to distribute your game. The instructions for your installer software should tell you how to run executables.

Goldenrod111

Quote from: Pumaman on Mon 09/02/2009 23:52:30
It should be fine in Before Fadein because it's using eNoBlock. If you tried to make a blocking call there it wouldn't work -- but all it's doing is telling the character to start moving -- it's not actually going to try and wait for him to do so.

Ok, that's good to know. Thanks!

Quote
Depends on what installer software you use to distribute your game. The instructions for your installer software should tell you how to run executables.

So there isn't any way to create an installer with AGS? Is there a certain program that you would recommend?

Finally, I am trying to export a function (it didn't appear in the list of avalible functions when I tried to put it into a room) from a new script I created, but I get an error. I want to be able to set some ints (representing percentages, placed in the new script) from the room scripts. Am I going about this the wrong way?
Code: ags

export function SetPercents (int Percent20_1, int Percent20_2, int Percent20_3, int Percent15, int Percent10, int Percent5, int Percent4, int Percent1);

Quote
MyScript.asc(23): Error (line 23): invalid export symbol 'int'

Pumaman

Quote from: Goldengamer111 on Tue 10/02/2009 13:42:26
So there isn't any way to create an installer with AGS? Is there a certain program that you would recommend?

No, AGS doesn't include any sort of installer -- it would take months to write an AGS Installer system, and there's no real point since there are plenty of good ones out there.

AGS itself uses Inno Setup as its installer, which is a free one that you might want to use.

Quote
Finally, I am trying to export a function (it didn't appear in the list of avalible functions when I tried to put it into a room) from a new script I created, but I get an error. I want to be able to set some ints (representing percentages, placed in the new script) from the room scripts. Am I going about this the wrong way?

Don't use the "export" keyword with functions. Just write the function normally, and then put an import statement in the .ASH header for that script. See here for a brief description:
http://www.adventuregamestudio.co.uk/manual/Calling%20global%20functions%20from%20local%20scripts.htm

Goldenrod111

Quote from: Pumaman on Tue 10/02/2009 22:18:32
AGS itself uses Inno Setup as its installer, which is a free one that you might want to use.

Thanks! I know that this is probably not the right place to ask this, but how would I include the -registergame with it?

Quote
Don't use the "export" keyword with functions. Just write the function normally, and then put an import statement in the .ASH header for that script.

Great! It it works now, thanks!

I can finally see the end of this thread ;D

Pumaman

Quote from: Goldengamer111 on Wed 11/02/2009 14:29:25
Thanks! I know that this is probably not the right place to ask this, but how would I include the -registergame with it?

Yeah, this is more a question for the Inno Setup forums, but it'd be something like:

[Run]
Filename: "{app}\game.exe"; Parameters: "-registergame"

[UninstallRun]
Filename: "{app}\game.exe"; Parameters: "-unregistergame"

QuoteGreat! It it works now, thanks!

Glad to hear it!

Goldenrod111

This should be the last question ;D. I am making a Pokemon-like game, and want the player to encounter an enemy, at a random level between a max and a min that I specify, in a certain area (different regions, numbers 1 and 2), and have different ones apear at different percentages. I want to be able to put something like "SetEnemPer(72, eWalk, 5, 40, 90);" in the top of the room script, the 72 being the type of enemy, eWalk being the method, 5 and 40 being the maxmium and minimum levels, respectively, and 90 being the percent chance of encountering that enemy in that room. I will call another function to make use of the variables set by this function (repeated for each type of enemy that the player can encounter in that room). I believe I can do this, but the biggest hurdle that I have run into is the fact that I do not know how many types of enemies will be in each room. For instance, one room might only contain one enemy, while another might contain twenty. How would I do this, and still be able to access the percentage, type, and level?

Trent R

If I correctly get what you're saying.... you might want to keep an array or struct filled with that type of data.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Goldenrod111

Quote from: Trent R on Thu 12/02/2009 22:44:46
If I correctly get what you're saying.... you might want to keep an array or struct filled with that type of data.


~Trent
That would be the best way, but I am not sure how I would accomodate the different numbers of enemies per room.

SMF spam blocked by CleanTalk