Jump to content


Photo

Warping between rooms?


  • Please log in to reply
28 replies to this topic

#1 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 04 April 2012 - 08:08 PM

Hi, I'm making a side-scrolling adventure game that consists of a number of large rooms, with the view following the player character inside those rooms. Everything outside the view of the character is deactivated.

I'm looking for a way to make it so that my character can 'warp' between rooms in the game whenever he's at a statue. So, if my character goes to statue A in room 1, i want him to warp to statue X in room 2. If he goes to statue B in room 1, I want him to warp to statue Y in room 2. The problem is, I don't know how to specifically tell the game where I want the character to end up when he moves between rooms. The program is probably confused too because I already have places where I've set the character inside these rooms. Can I find a way to not do this? I'm just very confused about this whole thing.

Here's what I've tried: In the "press a" event for the character it checks if there's a statue in front of him. If so, he warps to whatever room the statue corresponds to. I can get my character out of the main room fine with this method, he just warps to wherever I placed him in the next room. But when I try to warp back to the first room using the same method, the screen flashes between a bunch of different views before I see the character just falling through the blackness outside the game area.

Any help would be greatly appreciated, this is really stalling my progress!

A big problem
  • 0

#2 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 04 April 2012 - 08:27 PM

Well we can't help unless you post all related code sooo... :)
  • 0

#3 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 04 April 2012 - 08:42 PM

It's all pretty simple, just

Key Press Event for A-key Key:

if at relative position (-16,0) there is object Air_Statuette
go to room Metemestra with transition effect
else
if at relative position (16,0) there is object Jungle_Statuette
go to room Jungle with transition effect
else
if at relative position (5,0) there is object Mountaintop_Statuette
go to room room0 with transition effect
else
if at relative position (-5,0) there is object Mountaintop_Statuette
go to room room0 with transition effect



I just don't get how to make the character go to a specific place in a room.

Edited by BoronBananez, 04 April 2012 - 08:42 PM.

  • 0

#4 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1051 posts
  • Version:GM8.1

Posted 04 April 2012 - 08:55 PM

Maybe instead of placing the character in each room, make the player object Persistent and then change the instance's coordinates.
  • 0

#5 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 04 April 2012 - 09:00 PM

I hope your character is persistent.....

well you can make a variable called warp (or w/e) and assign values to it:
0 = inactive
1 = statue type a
2 = statue type b
ect


Then when you activate a statue add a line of code: warp = statue type (the number you associate with the statue)

in the step event of the the character put:
switch (warp)
{
case 1: warp = 0
x = statue1.x
y = statue1.y; break;
case 2: ect
}

Edited by kupo15, 04 April 2012 - 09:00 PM.

  • 0

#6 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 05 April 2012 - 04:33 AM

THANK you guys, all of this helps a ton. How does this work when moving from one room to another? I'm using the icons instead of gml, and they only let you move between rooms. Would I just put a separate action giving the character coordinates within the new room?
  • 0

#7 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 05 April 2012 - 05:08 AM

using my code above you simply need to put my code in the step event. It will only trigger the code when you activate a warp (the game will check every frame to see if you activated one) and when you do activate one, it will warp you to the coors of the statue in the current then deactivate the code so that you are aren't constantly warping thus getting stuck. So the code automatically gets the coors of the object of the state that is in the room. If you have more than one of the same statue type in the room then it needs to be tweaked.

WHen I said assign values to your statue types I mean in your mind, not actually coding it btw

Edited by kupo15, 05 April 2012 - 05:09 AM.

  • 0

#8 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 05 April 2012 - 03:31 PM

using my code above you simply need to put my code in the step event. It will only trigger the code when you activate a warp (the game will check every frame to see if you activated one) and when you do activate one, it will warp you to the coors of the statue in the current then deactivate the code so that you are aren't constantly warping thus getting stuck. So the code automatically gets the coors of the object of the state that is in the room. If you have more than one of the same statue type in the room then it needs to be tweaked.

WHen I said assign values to your statue types I mean in your mind, not actually coding it btw



Thanks! But I still don't understand how you warp between rooms using specific coordinates...
  • 0

#9 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 05 April 2012 - 04:29 PM

// in create of STATUE OBJ (IS there just one object with subimages?)
warp = 1 // if multiple objects assign your warp values to the different statues here

// step
if keyboard_check_pressed(BUTTON) and point_distance(x,y,PLAYER.x,PLAYER.y) < 32 // w/e distance you want
PLAYER.warp = warp



// in the step event of the the character put: 

switch (warp)
{
case 1: warp = 0
x = statue1.x
y = statue1.y; break;
case 2: ect
}

maybe I don't understand your question. Is it not working or it is but you want the logic behind it? Confused

Edited by kupo15, 05 April 2012 - 08:47 PM.

  • 1

#10 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 07 April 2012 - 04:59 PM

// in create of STATUE OBJ (IS there just one object with subimages?)
warp = 1 // if multiple objects assign your warp values to the different statues here

// step
if keyboard_check_pressed(BUTTON) and point_distance(x,y,PLAYER.x,PLAYER.y) < 32 // w/e distance you want
PLAYER.warp = warp



// in the step event of the the character put: 

switch (warp)
{
case 1: warp = 0
x = statue1.x
y = statue1.y; break;
case 2: ect
}

maybe I don't understand your question. Is it not working or it is but you want the logic behind it? Confused



Oh, it just looks to me like that only takes into account warping within a room, not moving between rooms. But then I'm still new to Game Maker. And no, I haven't had enough free time to try implementing it yet.
  • 0

#11 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 07 April 2012 - 07:00 PM

No it will because you will have an instance of the object warp statue in it. Because it is in the step event it is always looking for a warp statue within the room you are in. So once you warp to the new room it will find the new warp statue and use that
  • 1

#12 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 13 April 2012 - 04:36 PM

No it will because you will have an instance of the object warp statue in it. Because it is in the step event it is always looking for a warp statue within the room you are in. So once you warp to the new room it will find the new warp statue and use that


Oh, awesome! Thank you so much. I'll try it out when I get a chance.
  • 0

#13 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 16 April 2012 - 09:50 PM

No it will because you will have an instance of the object warp statue in it. Because it is in the step event it is always looking for a warp statue within the room you are in. So once you warp to the new room it will find the new warp statue and use that



I tried it out, but I'm getting an error. I'm trying to warp from 'Air_Statuette' to 'Mountaintop_Statuette', but I get this:

ERROR in
action number 51
of Step Event
for object Char:

Error in code at line 4:
x = Mountaintop_Statuette.x
^
at position 28: Unknown variable x


In this case, Mountaintop_Statuette is in a different room than Air_Statuette. Oh... I have it in the game so that everything outside of the current view is deactivated. Could the game be failing to recognize Mountaintop_Statuette because it's deactivated? I'm not sure otherwise.
  • 0

#14 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 16 April 2012 - 11:23 PM

Probably so then you should put if instance_exists() before the warping code so that if it doesn't exist it won't error. Because you have multiple objects for the warp you will have to
if instance_exists() || instance_exists || etc for each warp statue object.

This is why I would probably code it so that I only have one warp object that handles this all but thats just me :)
  • 0

#15 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 23 April 2012 - 09:11 PM

Probably so then you should put if instance_exists() before the warping code so that if it doesn't exist it won't error. Because you have multiple objects for the warp you will have to
if instance_exists() || instance_exists || etc for each warp statue object.

This is why I would probably code it so that I only have one warp object that handles this all but thats just me :)


I still don't understand how that fixes it. If the program doesn't think the object exists now (because it's deactivated or whatever), how would this help? I'm using this code in the step event of the character to deactivate stuff:

instance_activate_all()
instance_deactivate_region(view_xview-50,view_yview- 50,view_wview+100,
view_hview+100,0,1)

Do you know how I'd add an exception?

And well, if it's easier to do it with one warp object, I'm game.

Edited by BoronBananez, 23 April 2012 - 09:17 PM.

  • 0

#16 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 24 April 2012 - 12:32 AM

yea that would be a problem. Maybe try if !OBJECTWARP {deactivate code}?
  • 0

#17 _254583

_254583

    GMC Member

  • New Member
  • 32 posts

Posted 24 April 2012 - 05:49 AM


Probably so then you should put if instance_exists() before the warping code so that if it doesn't exist it won't error. Because you have multiple objects for the warp you will have to
if instance_exists() || instance_exists || etc for each warp statue object.

This is why I would probably code it so that I only have one warp object that handles this all but thats just me :)


I still don't understand how that fixes it. If the program doesn't think the object exists now (because it's deactivated or whatever), how would this help? I'm using this code in the step event of the character to deactivate stuff:

instance_activate_all()
instance_deactivate_region(view_xview-50,view_yview- 50,view_wview+100,
view_hview+100,0,1)

Do you know how I'd add an exception?

And well, if it's easier to do it with one warp object, I'm game.


To add an exception, all you would have to do is activate the objects you want to remain active, after your deactivation code. Then even though the code is deactivating everything, it will then activate just the few objects that you wish to keep active. The code for that is:

instance_activate_object(OBJECT_NAME);

  • 1

#18 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 07 May 2012 - 08:16 PM

Well I'm still having problems. Now when I even get near the object Mountaintop_statuette, it gives me this error:

ERROR in
action number 51
of Step Event
for object Char:

Error in code at line 4:
x = Air_Statuette.x
^
at position 20: Unknown variable x


And this is the full offending piece of code:

switch (warp)
{
case 1: warp = 1
x = Air_Statuette.x
y = Air_Statuette.y; break;
}


If it helps, here's what I put into the step event of the Mountaintop_statuette:

if keyboard_check_pressed("A") and point_distance(x,y,Char.x,Char.y) < 32
Char.warp = 1


Again, thank you all so much for your help. I'm just lost with this. The only thing I can think of is that the Air_Statuette is still deactivated somehow... here's the full deactivation code too, just for good measure:

instance_activate_all()
instance_deactivate_region(view_xview-50,view_yview- 50,view_wview+100,
view_hview+100,0,1)
instance_activate_object(Air_Statuette);
instance_activate_object(Jungle_Statuette);
instance_activate_object(Mountaintop_Statuette);
  • 0

#19 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 07 May 2012 - 11:03 PM

Must be because its not in the room. Did you do what I said about checking if the object is there? And you are sticking with multiple objects instead of instances? :/
  • 0

#20 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 11 May 2012 - 07:16 PM

Must be because its not in the room. Did you do what I said about checking if the object is there? And you are sticking with multiple objects instead of instances? :/



Oh, actually I forgot to check that. Here's the code now:

switch (warp)
{
case 1: warp = 1
if instance_exists(Air_Statuette)
x = Air_Statuette.x
y = Air_Statuette.y; break;
}

And I'm still getting this error message whenever I approach Mountaintop_Statuette

ERROR in
action number 51
of Step Event
for object Char:

Error in code at line 6:
y = Air_Statuette.y; break;
^
at position 20: Unknown variable y

Which is interesting, because it seems to have no problem with Air_Statuette.x. Right? I'm still so iffy on this GML thing...


And if you mean that I'm using a bunch of totally different objects as statues, then yeah, I'm doing that.
  • 0

#21 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 11 May 2012 - 07:39 PM

Simple you forgot to include {}
When you check "if" something only the next line gets included in that check unless you add {}
if instance_exists(Air_Statuette)
{
x = Air_Statuette.x
y = Air_Statuette.y; 
}
break; // make sure break is outside the {}

Edited by kupo15, 11 May 2012 - 07:40 PM.

  • 0

#22 pwyskowski

pwyskowski

    GMC Member

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

Posted 12 May 2012 - 08:22 AM

Hi, I'm making a side-scrolling adventure game that consists of a number of large rooms, with the view following the player character inside those rooms. Everything outside the view of the character is deactivated.

I'm looking for a way to make it so that my character can 'warp' between rooms in the game whenever he's at a statue. So, if my character goes to statue A in room 1, i want him to warp to statue X in room 2. If he goes to statue B in room 1, I want him to warp to statue Y in room 2. The problem is, I don't know how to specifically tell the game where I want the character to end up when he moves between rooms. The program is probably confused too because I already have places where I've set the character inside these rooms. Can I find a way to not do this? I'm just very confused about this whole thing.

Here's what I've tried: In the "press a" event for the character it checks if there's a statue in front of him. If so, he warps to whatever room the statue corresponds to. I can get my character out of the main room fine with this method, he just warps to wherever I placed him in the next room. But when I try to warp back to the first room using the same method, the screen flashes between a bunch of different views before I see the character just falling through the blackness outside the game area.

Any help would be greatly appreciated, this is really stalling my progress!

A big problem


Hi,

The approach I would take would be to create a global set of variables at the start of the program that define the starting X and Y positions for the player. (Lets call them WarpX and WarpY)
Also, instead of placing the player object in the room design, create the player object in the creation code of the room using the global X and Y variables you set up. (Note:Room cannot be persistent for this to work properly)
When you switch between rooms using the warp statues, have the statue set those global variables WarpX and WarpY before switching rooms.
Then when the room opens up, the player will be in the proper place.

I put together an example of this technique in action. It uses a "warp portal" for jumping between rooms as well as "exit objects" for moving up/down/left/right between rooms.
GM8 Warp Example (EXE)

Sometime later today, I will get the gm81 file uploaded with a PDF explaining how everything works.

I hope this helps. :cool:

-Paul
  • 1

#23 mr.men

mr.men

    GMC Member

  • New Member
  • 14 posts
  • Version:Unknown

Posted 12 May 2012 - 01:17 PM

I don't think you need to have the y= and x= in your code I think you can just say air_statuette.y and air_statuette.x
but I am also just a beginning gamer so I could be wrong.
  • 0

#24 pwyskowski

pwyskowski

    GMC Member

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

Posted 12 May 2012 - 10:47 PM

Hi Again,

Here is the gm81 file and a PDF with some direction on how to use this system.

GM8.1 Warp Exit / Directional Exit Example

I hope this helps. :cool:

-Paul
  • 1

#25 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 15 May 2012 - 08:23 PM

To kupo15:

I changed my code to this:

switch (warp)
{
case 1: warp = 1
if instance_exists(Air_Statuette)
{
x = Air_Statuette.x
y = Air_Statuette.y;
}
break;
}

And kept everything else the same, but now when I press A around the statue, nothing happens. Maybe it just can't check for an object outside the room?


And pwykowski, that looks really promising. I think I'll try implementing that too. Thanks!
  • 0

#26 kupo15

kupo15

    GMC Member

  • GMC Member
  • 497 posts
  • Version:GM8.1

Posted 16 May 2012 - 03:46 AM

no idea lol youll gonna have to send me the file or something
  • 0

#27 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 05 July 2012 - 10:44 PM

So I have to say, this has worked better than anything else I've tried so far. I'm having one problem though, which I can't seem to fix. What happens is when I try to warp from one specific room to another, I seem to be warping into the same exact spot in both rooms at the same time, so the game tries to mix the two together. I find objects from both rooms, in the same coordinates they are in their respective rooms, but in one room at the same time.

I'll post the relevant code so you can maybe see what I did wrong...

In the title screen object creation event-

globalvar WarpDestination, WarpX, WarpY;

In the title screen press a event-

WarpRoom=Cygnus_Temple;
global.WarpX=1952;
global.WarpY=1136;
transition_kind=20;
room_goto(WarpRoom);

In the Cygnus_Temple room creation code-

instance_create(global.WarpX,global.WarpY,Char);
instance_create(Char.x,Char.y,Player_Health_Controller);
Templegrounds_Templeinside_L.MyWarpRoom=In_Cygnus_Temple;
Templegrounds_Templeinside_R.MyWarpRoom=In_Cygnus_Temple;
Temple_Fall_Warp.MyWarpRoom=Temple_Fall;

(where I'm having problems is that last one, the Temple_Fall_Warp object seems to be taking me to a mix of the Temple_Fall and Cygnus_Temple rooms)

In the Temple_Fall room creation code-

instance_create(global.WarpX,global.WarpY,Char);
instance_create(Char.x,Char.y,Player_Health_Controller);
Templefall_Cave_Warp.MyWarpRoom=Beginning_Cave;
Templefall_Forest_Warp.MyWarpRoom=Forest_Room;

In the Temple_Fall_Warp object collision event with the Character (Char)-

global.WarpX=928;
global.WarpY=704;
WarpRoom=MyWarpRoom;
transition_kind=14;
room_goto(WarpRoom);

And in the creation event for the Temple_Fall_Warp object-

var MyWarpRoom;


I've tried literally everything I logically know how to do to fix this, but I come up with zilch. Any ideas?

Hi Again,

Here is the gm81 file and a PDF with some direction on how to use this system.

GM8.1 Warp Exit / Directional Exit Example

I hope this helps. :cool:

-Paul


  • 0

#28 BoronBananez

BoronBananez

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 07 July 2012 - 10:32 PM

Some more info if anyone wants to help- I've been futzing around and I figured out that whatever room I set the game to go to after the title screen becomes the room that every other room I warp to becomes melded with. Still haven't found out how or why...
  • 0

#29 pwyskowski

pwyskowski

    GMC Member

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

Posted 06 October 2012 - 03:06 AM

@BoronBananez

Sorry I haven't been on for a while. If you haven't figured out the problem yet, I think I see what is going on here.

Since you used the collision event to trigger the warping between rooms, the character touches the WarpObject in one room and then is Warped into the WarpObject in the other room.

This triggers the collision event with that WarpObject and sends the character back to the other room, causing an infinite loop of Warping back and forth.

I would suggest using another method/event to trigger the Warping such as particular keypress like I did in the example where it will check for a collision upon that keypress.

-Paul
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users