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
  • 412 posts

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
  • 1028 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
  • 412 posts

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
  • 412 posts

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
  • 412 posts

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
  • 412 posts

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
  • 412 posts

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
  • 412 posts

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
  • 412 posts

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users