Jump to content


Photo

Changing Room set an instance to another position


  • Please log in to reply
7 replies to this topic

#1 meromero

meromero

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 06 August 2012 - 04:47 AM

The problem i have is that i created an object that follows diferent paths depending on the room he is in (this is not the current room, it's a variable that keep track of the room he is suposed to be). When it reaches the end of the path, he changes room variable and start another path. This DOES NOT change the actual room, it's more like an NPC u have to follow with his own "room" variable. If the current room and the room the object is in are the same then the object is visible and he sarts to move, if they are not the same then he is not visible and he doesn't move.

I know it's a bit of a mess and that my english is awful but here is my problem

When the I reach the end of the room and change to the next room room, the objects jump to another position for no reason. I have no idea how to make this work this is the code

if (path_position = 1){
    if habitacionComp = room7c && visto{
        x = 40;
        y = 240;
        habitacionComp = room8c
        path_start(comp2Path,0,0,1)
    }
    if habitacionComp = room8c {
                
    }
}else{
    if habitacionComp = room7c && !collision_line(x,y,jugador.x,jugador.y,solido,0,1) && point_distance(x, y, jugador.x, jugador.y) < 200 && !visto{
        visto = true
        path_start(comp1Path,2,0,1)
    }    
}

if (habitacionComp = room){
    visible = true;
    path_speed = 2;
}else{
    visible = false;
    path_speed = 0;
}

i tried changing the x and y by myself and to make a path that starts in those particular x and y, and it works until i change the room, then it jumps to another random position
  • 0

#2 Debels

Debels

    GMC Member

  • GMC Member
  • 1997 posts
  • Version:GM:Studio

Posted 06 August 2012 - 05:58 AM

Well didn't really read your full code, but i can offer you a quick solution:

When changing room
global.last_room=room;
//The code you use to move to the next room
In the event room start
switch (global.last_room){
      case room1://or the room you want
            x=20;//Or the x you want
            y=20;//or the y you want
      break;
}

and you can keep adding cases and such.
  • 0

#3 Mr B

Mr B

    GMC Member

  • GMC Member
  • 172 posts

Posted 06 August 2012 - 06:00 AM

Are the path coordinates set to absolute or relative?
  • 0

#4 meromero

meromero

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 06 August 2012 - 03:30 PM

Well didn't really read your full code, but i can offer you a quick solution:

When changing room

global.last_room=room;
//The code you use to move to the next room
In the event room start
switch (global.last_room){
      case room1://or the room you want
            x=20;//Or the x you want
            y=20;//or the y you want
      break;
}

and you can keep adding cases and such.


the problem i have is that the room this object is and the room i'm currently playing are not necesary the same, so i cant simply use the room start event to set the position because if u leave the room and then come back the object should be in a diferent position of the path.

Are the path coordinates set to absolute or relative?


i tryed with the 2 options and in the two cases the object is always send to the (0,0) position ate the begining of the path for no reason =S
  • 0

#5 Debels

Debels

    GMC Member

  • GMC Member
  • 1997 posts
  • Version:GM:Studio

Posted 06 August 2012 - 04:47 PM

the problem i have is that the room this object is and the room i'm currently playing are not necesary the same, so i cant simply use the room start event to set the position because if u leave the room and then come back the object should be in a diferent position of the path.

This code works perfectly in the test i made :confused:
  • 0

#6 meromero

meromero

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 07 August 2012 - 02:31 AM


the problem i have is that the room this object is and the room i'm currently playing are not necesary the same, so i cant simply use the room start event to set the position because if u leave the room and then come back the object should be in a diferent position of the path.

This code works perfectly in the test i made :confused:


i tried that i made a code like this

    switch (habitacionComp){
        case room8c :
            x = 300
            y = 300
    }

but it stills jumps to another position (i think it was 117,-56 or something like that) when i enter the room "room8c" for the first time, after that if i leave and re-enter it starts to work and send him to the 300,300 position

i still have no idea why does GM change de position to that =(
  • 0

#7 Debels

Debels

    GMC Member

  • GMC Member
  • 1997 posts
  • Version:GM:Studio

Posted 07 August 2012 - 02:34 AM



the problem i have is that the room this object is and the room i'm currently playing are not necesary the same, so i cant simply use the room start event to set the position because if u leave the room and then come back the object should be in a diferent position of the path.

This code works perfectly in the test i made :confused:


i tried that i made a code like this

    switch (habitacionComp){
        case room8c :
            x = 300
            y = 300
    }

but it stills jumps to another position (i think it was 117,-56 or something like that) when i enter the room "room8c" for the first time, after that if i leave and re-enter it starts to work and send him to the 300,300 position

i still have no idea why does GM change de position to that =(

Hmm that's strange, is room8c your initial room?
  • 0

#8 meromero

meromero

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 07 August 2012 - 10:31 PM




the problem i have is that the room this object is and the room i'm currently playing are not necesary the same, so i cant simply use the room start event to set the position because if u leave the room and then come back the object should be in a diferent position of the path.

This code works perfectly in the test i made :confused:


i tried that i made a code like this

    switch (habitacionComp){
        case room8c :
            x = 300
            y = 300
    }

but it stills jumps to another position (i think it was 117,-56 or something like that) when i enter the room "room8c" for the first time, after that if i leave and re-enter it starts to work and send him to the 300,300 position

i still have no idea why does GM change de position to that =(

Hmm that's strange, is room8c your initial room?


my initial room is room1a. I think the problem is that i start a path in room7c, then change to room8c and the object is suposed to follow the same path from the same position, but for some reason it uses the path as if the initial position of the path was (0,0) in the new room.

i made it as you said with a switch(habitacionComp) in the "start room" event. So any time you enter the same room as the object it restarts the path, it's not what i wanted, but it's the best i have :confused:

if (habitacionComp = room) {
    switch(habitacionComp){
        case room8c : path_start(comp2Path,2,0,1)
    }  
}  

if the object starts a path in room8c and then i move to room7c (and modify the code to allow the object to still be visible and to move while in diferent rooms) it follows the path BUT as if the path started from the cordinates (0,0)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users