Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: xerca on Mon 04/10/2010 20:33:08

Title: Getting a room's width or height [SOLVED]
Post by: xerca on Mon 04/10/2010 20:33:08
Hi. I tried anything I could to get the width and height of a room which is not the "current room"(so this means the player is not in that room), but I couldn't. Isn't there a way?

"room[1]" or "room(1)" doesn't work and I don't know what else I can do.
Title: Re: Getting a room's width or height
Post by: GarageGothic on Mon 04/10/2010 20:56:02
Not without switching to that room, no.
Title: Re: Getting a room's width or height
Post by: xerca on Mon 04/10/2010 21:04:27
:(. then my "changing room in a more realistic way function" will not work
Title: Re: Getting a room's width or height
Post by: GarageGothic on Mon 04/10/2010 21:22:36
Well, you could store all the room widths/heights in a struct or array that you refer to, but then you either have to enter those values manually or iterate through all rooms on startup to gather the data. If you explain what you're trying to do, perhaps we can suggest another workaround. (For instance, why do you need the height/width for a room that is not currently being displayed? What are you using the values for?)
Title: Re: Getting a room's width or height
Post by: Gilbert on Tue 05/10/2010 04:35:04
I don't know what your "changing room in a more realistic way function" is about, but can you work around this by using on_event() with the event eEventEnterRoomBeforeFadein? Is this absolute necessary to have the dimension of another room known before changing to it?
Title: Re: Getting a room's width or height
Post by: xerca on Tue 05/10/2010 20:34:41
I don't know if I can explain it properly but it's a simple function:

function odadegis(int gidilen, int yon)
{
if(yon==1){
  player.Walk(player.x, 0, eBlock);
  player.ChangeRoom(gidilen, player.x, Room.Height);
}
if(yon==2){
  player.Walk(Room.Width, player.y, eBlock);
  player.ChangeRoom(gidilen, 0, player.y);
}
if(yon==3){
  player.Walk(player.x, Room.Height, eBlock);
  player.ChangeRoom(gidilen, player.x, 0);
}
if(yon==4){
  player.Walk(0, player.y, eBlock);
  player.ChangeRoom(gidilen, Room.Width, player.y);
}

So, what it does is; for example you have room1 and room2 which are next to each other. You write odadegis(2,2) at room_LeaveLeft() (2 for the room number and 2 for the direction 1-up, 2-left, etc.). If player walks off the left edge, this makes the player walk to room.width and then change the room to room2, x=0 y=player.y. There is no problem for this but when it comes to use room.width or room.height in player.ChangeRoom, I can't do it because I need the other room's values.

I wrote this code in a short time before going to bed so I didn't think if it was really correct or not but when I tested it while it worked in rooms with same width/height it didn't work with different widths/heights. At first I didn't use any function but when I added more and more rooms to the game I felt that I need a function.

By the way, I have another function which works well. I just write odayagir(); at room_AfterFadeIn() and it makes the player walk to mmm... I'll just paste it.


function odayagir()
{
if(player.x==0){ player.Walk(50, player.y, eBlock, eAnywhere);}
else if(player.y==0){ player.Walk(player.x, 110, eBlock, eAnywhere);}
else if(player.x==Room.Width){ player.Walk(Room.Width-50, player.y, eBlock, eAnywhere);}
else if(player.y==Room.Height){ player.Walk(player.x, Room.Height-50, eBlock, eAnywhere);}
}


So, those two functions were meant to work together to walk the player from room to room and not to just teleport him.

I'm sure a workaround could be found by thinking on it a little bit. I can of course add two more int variables to the function for width and height value of the next room so I can write them manually.. but it is not much easier than just copying or writing a normal code for that.

I'm not very good at programming... But I like to learn new things at it. Those are my second and third functions. The first one was another simple function and worked flawlessly :).

Sorry if I couldn't explain it properly because when I try to write in English it always gets longer and longer than it needs to be.
Title: Re: Getting a room's width or height
Post by: xerca on Tue 05/10/2010 20:40:58
Quote from: Gilbet V7000a on Tue 05/10/2010 04:35:04
I don't know what your "changing room in a more realistic way function" is about, but can you work around this by using on_event() with the event eEventEnterRoomBeforeFadein? Is this absolute necessary to have the dimension of another room known before changing to it?

I thought about using "player.move" in BeforeFadein but I don't know if it would work nice... Though I don't remember why I didn't try it.
Title: Re: Getting a room's width or height
Post by: monkey0506 on Wed 06/10/2010 01:42:07
Is there a reason you would even need to use Move in BeforeFadeIn? Character.x and Character.y are writable as long as Character.Moving is false.
Title: Re: Getting a room's width or height
Post by: xerca on Wed 06/10/2010 09:41:36
Quote from: monkey_05_06 on Wed 06/10/2010 01:42:07
Is there a reason you would even need to use Move in BeforeFadeIn? Character.x and Character.y are writable as long as Character.Moving is false.
oh.. well. I didn't know that. they sound like very read-only to me. If I can do it, I'll write "solved" right away.

edit: Alright I did it. Thanks to anybody who have bothered reading my messages and answering them.
Title: Re: Getting a room's width or height [SOLVED]
Post by: monkey0506 on Wed 06/10/2010 10:30:04
The reason they're lowercased isn't to indicate that they're read-only. It's really only for backward compatibility of the scripts. And if you read the manual entry on the properties it tells you that you can change it, but not if the Moving property is true. So..even if you think you know what the manual says, taking a second look can always help. ;)