Change to different room according to which view the character is in (syntax)

Started by Snirpa, Fri 14/02/2014 05:56:18

Previous topic - Next topic

Snirpa

I have a room with a lake which you cannot cross. The only way to cross the lake is to find a hovercraft. So once the character has the hovercraft and interacts it I change the view with the character inside the hovercraft. This is not a problem.

Now when the character goes back to the room with the lake I want them to be able to cross it, so I cloned that room and made the area above the lake a walkable area.
What I am trying to do, when the character leaves a room I want to write a conditional statement, based on which view my character has (for example, the character has now 'equipped' the hovercraft so he is in that view, thus when he leaves on the left edge, he will be sent to the cloned room, but if he still has the normal walking view, he will go to the original room which he cannot cross.

I have tried

Code: ags


function room_LeaveRight()
{
 if (cEgo.View == 1)){
cEgo.ChangeRoom(4, 43, 323);
else
cEgo.ChangeRoom(7, 43, 323);
 }
}



or

Code: ags


function room_LeaveRight()
{
 if (cEgo.View(1)){
cEgo.ChangeRoom(4, 43, 323);
else
cEgo.ChangeRoom(7, 43, 323);
 }
}


I'm new to coding - I just wish I knew how to set it up correctly.

;-D

Andail

Mind your brackets:

Code: ags


function room_LeaveRight()
{
  if (cEgo.View == 1){ // you had an extra closing parenthesis here
    cEgo.ChangeRoom(4, 43, 323);
  } // you didn't close the first if statement here
  else cEgo.ChangeRoom(7, 43, 323);
}



You either need to use { and } around the commands, unless it's only one and you can write it directly after the condition, like I did sfter the "else".


Intense Degree

Perhaps I am misunderstanding what you are trying to do but wouldn't it be simpler just to use the one room and then removing and restoring the walkable area across the lake depending on the character view?

Code: ags

function room_Load()
{
  if (cEgo.view == 1) RestoreWalkableArea(4); // replace 4 with the number of the walkable area over the lake
  else RemoveWalkableArea(4); // again replace 4 as above.  
}


Ghost

Quote from: Intense Degree on Fri 14/02/2014 11:37:17
but wouldn't it be simpler just to use the one room and then removing and restoring the walkable area across the lake depending on the character view?

Agreed, if the only difference between the rooms is a walkable area, using a carbon copy of that room is cumbersome. And if the player only ever travels over the lake and leaves the hovercraft then, you can even use the Walk command with the eAnywhere parameter, which allows a character to move outside of walkable areas.

SMF spam blocked by CleanTalk