Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: slufan on Sun 10/11/2019 23:51:57

Title: Player change room [SOLVED]
Post by: slufan on Sun 10/11/2019 23:51:57
Hello again

As I said in my first post, I have been using AGS for only a few days and, although most of the problems presented to me I have been able to solve them with the help and documentation, there are things I do not know how to solve them.
In my game there is a mini-spider that follows the player through the rooms, but in certain rooms I would like to stay in it and the player could move between rooms without the mini-spider following.
When both spiders enter a room the code works perfectly, but when it does only the player I am not able to return to the room where the mini-spider is without giving me an error.
I leave the code I use in the two rooms to see if anyone can help me.

Code to room 10
Code (ags) Select

function room_FirstLoad()
{
  cSpider.Walk(278, 133, eBlock, eWalkableAreas);
  cMiniSpider.EnterRoom(10, 330, 135, eDirectionLeft);
  cMiniSpiderWalk(251, 138, eBlock, eAnywhere);
}

function room_LeaveTop()
{
  if (HasPlayerBeenInRoom(11)) {
    cSpider.Transparency=30;
    cSpider.Transparency=60;
    cSpider.Transparency=100;
    cSpider.ChangeRoom(11, 10, 117, eDirectionRight);
  }
  else
    cSpider.Transparency=30;
    cSpider.Transparency=60;
    cSpider.Transparency=100;
    cMiniSpider.Walk(164, 92, eBlock, eWalkableAreas);
    cMiniSpider.Transparency=30;
    cMiniSpider.Transparency=60;
    cMiniSpider.Transparency=100;
    cSpider.ChangeRoom(11, 10, 117, eDirectionRight);
}


Code to room 11
Code (ags) Select

function room_FirstLoad()
{
  cSpider.Transparency=0;
  cSpider.Walk(16, 117, eBlock, eAnywhere);
}

function room_AfterFadeIn()
{
  cMiniSpider.Transparency=0;
  cMiniSpider.EnterRoom(11, 0, 117, eDirectionRight);
  cMiniSpider.Walk(76, 122, eBlock, eAnywhere);
}


When the player goes back to room 10 it makes it alone, the MinISpider stays in room 11, but when I try to go back to room 11 the game crash and give this error "MoveCharacter: character is not in current room"
Its like the HasBeenPlayerInRoom function are not working correctly because player has really been in room 11.

Thanks in advance.
Title: Re: Player change room
Post by: Khris on Mon 11/11/2019 00:27:32
A simple way to check which code runs is to insert something like  Display("player has been in room 11");  in your blocks.

I'm not sure what's causing the error, can you tell us exactly which line is mentioned in the error message? I assume line 20 in the first snippet?
Title: Re: Player change room
Post by: slufan on Mon 11/11/2019 09:58:38
I have add the line "Display("I've been here before"); in the first part of the room_LeaveTop function.
When players enter firts time in the room don't display nothing, when player enter for second time in the room shows "I've been here before" but still get the error message.
The line mentioned in the error message is line 20 of first snippet.

Thanks
Title: Re: Player change room
Post by: CaptainD on Mon 11/11/2019 10:31:18
The problem might be that you don't have the ELSE function (lines 17-26) encapsulated with {}. 
Title: Re: Player change room
Post by: Khris on Mon 11/11/2019 12:57:05
Ha, I completely missed that thanks to the flawless indentation :)

Btw, I guess those .Transparency lines are supposed to fade out the sprites but it won't work like that. As I'm sure you have noticed, the sprite simply turns invisible immediately. You'll want a loop with a  Wait(1);  inside to have a visible fade (and use a custom function for that in order to avoid tons of duplicate code).
Title: Re: Player change room
Post by: Laura Hunt on Mon 11/11/2019 13:30:37
Quote from: Khris on Mon 11/11/2019 12:57:05
Ha, I completely missed that thanks to the flawless indentation :)

Btw, I guess those .Transparency lines are supposed to fade out the sprites but it won't work like that. As I'm sure you have noticed, the sprite simply turns invisible immediately. You'll want a loop with a  Wait(1);  inside to have a visible fade (and use a custom function for that in order to avoid tons of duplicate code).

(Or use the Tween module.)
Title: Re: Player change room
Post by: slufan on Mon 11/11/2019 15:39:50
Quote from: CaptainD on Mon 11/11/2019 10:31:18
The problem might be that you don't have the ELSE function (lines 17-26) encapsulated with {}.

Ok thats it, now works fine.

Thank you.
Title: Re: Player change room
Post by: slufan on Mon 11/11/2019 15:42:05
Quote from: Khris on Mon 11/11/2019 12:57:05
Ha, I completely missed that thanks to the flawless indentation :)

Btw, I guess those .Transparency lines are supposed to fade out the sprites but it won't work like that. As I'm sure you have noticed, the sprite simply turns invisible immediately. You'll want a loop with a  Wait(1);  inside to have a visible fade (and use a custom function for that in order to avoid tons of duplicate code).

Yes you're right, it turns invisible immediately. I'll try Wait(1); and see what happens.

Thank you.
Title: Re: Player change room
Post by: CaptainD on Mon 11/11/2019 21:30:24
Quote from: slufan on Mon 11/11/2019 15:39:50
Quote from: CaptainD on Mon 11/11/2019 10:31:18
The problem might be that you don't have the ELSE function (lines 17-26) encapsulated with {}.

Ok thats it, now works fine.

Thank you.

I'm not often the person who manages to answer anyone's questions on here!  Glad it works.  ;-D