Jibble

Author Topic: Player change room  (Read 136 times)

Player change room
« on: 10 Nov 2019, 23:51 »
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: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3.   cSpider.Walk(278, 133, eBlock, eWalkableAreas);
  4.   cMiniSpider.EnterRoom(10, 330, 135, eDirectionLeft);
  5.   cMiniSpiderWalk(251, 138, eBlock, eAnywhere);
  6. }
  7.  
  8. function room_LeaveTop()
  9. {
  10.   if (HasPlayerBeenInRoom(11)) {
  11.     cSpider.Transparency=30;
  12.     cSpider.Transparency=60;
  13.     cSpider.Transparency=100;
  14.     cSpider.ChangeRoom(11, 10, 117, eDirectionRight);
  15.   }
  16.   else
  17.     cSpider.Transparency=30;
  18.     cSpider.Transparency=60;
  19.     cSpider.Transparency=100;
  20.     cMiniSpider.Walk(164, 92, eBlock, eWalkableAreas);
  21.     cMiniSpider.Transparency=30;
  22.     cMiniSpider.Transparency=60;
  23.     cMiniSpider.Transparency=100;
  24.     cSpider.ChangeRoom(11, 10, 117, eDirectionRight);
  25. }
  26.  

Code to room 11
Code: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3.   cSpider.Transparency=0;
  4.   cSpider.Walk(16, 117, eBlock, eAnywhere);
  5. }
  6.  
  7. function room_AfterFadeIn()
  8. {
  9.   cMiniSpider.Transparency=0;
  10.   cMiniSpider.EnterRoom(11, 0, 117, eDirectionRight);
  11.   cMiniSpider.Walk(76, 122, eBlock, eAnywhere);
  12. }
  13.  

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.

Khris

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Player change room
« Reply #1 on: Yesterday at 00:27 »
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?
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Player change room
« Reply #2 on: Yesterday at 09:58 »
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

Re: Player change room
« Reply #3 on: Yesterday at 10:31 »
The problem might be that you don't have the ELSE function (lines 17-26) encapsulated with {}. 

Khris

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Player change room
« Reply #4 on: Yesterday at 12:57 »
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).
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Player change room
« Reply #5 on: Yesterday at 13:30 »
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.)

Re: Player change room
« Reply #6 on: Yesterday at 15:39 »
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.

Re: Player change room
« Reply #7 on: Yesterday at 15:42 »
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.

Re: Player change room
« Reply #8 on: Yesterday at 21:30 »
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