I can't find any sort of tutorial for this?

K

KaelaOpalheart

Guest
It's a bit obscure so I'm not surprised I can't find the answer, but I need to find out how to do this, please. I've been building a practice game project in partnership with a friend who tells me what to figure out how to include, and so far we have a 2d topdown maze, and at the end there's an object that teleports you to a brief platformer level, and at the end I put a flag to declare you won when you reach it. Except now he wants me to change it so the flag instead returns you to the first room, and the part I need help with is, after you return, he wants the object that teleported you to be gone, making the platformer room inaccessible after. On a random guess I added an instance destroy of the object in question to the flag's actions for after the return to previous room part, hoping it wouldn't try to destroy that instance until after reaching the topdown room, but nah, it seems to still be looking in the platformer room for the object, which of course isn't there, so that didn't work. But now I wouldn't have any idea what code to add or inside what object. Any help please, anyone? =) Thanks.
 
You'd have to show use your code, but if I understand correctly, then I suggest you try putting the instance destroy part before the go to room line.

It seems weird, but the instance will still run all the rest of the code (and the destroy event) before it is actually destroyed. If you do it before you change rooms then the instance will be destroyed. But without code to go off of, I'm pretty sure that actually is the problem you're having.

Also, you won't find a tutorial for this because that's a highly specific task that only needs to be done every once in a while. You'll learn how to do that sort of stuff by becoming more proficient at GML by itself. What you're doing isn't specialized or anything, you just need more general practice with coding.
 
K

KaelaOpalheart

Guest
Thanks for the suggestion! I gave it a try and switched the order, and sadly, no, it didn't work. I didn't really think it would work to put the action to destroy an object in the topdown room, into another object in the platform room, I was just hoping on a guess to connect it to the room transfer. That not working though, I would think that the code would need to go into something in the topdown room itself, since that's where the object that needs to be destroyed is, but then I'm not sure how to connect it to the event of the player re-entering the topdown room specifically when returning from the platformer room and not just upon starting the game (which starts in the topdown room for now). That's what I'm guessing now, is I'd need to connect it to when that specifically occurs, and THEN destroy the object. And even aside from not knowing the code to do that, I'm also not sure if that should go, say, in the player, in the object to be destroyed, or in just some sprite-less object sitting in the room.

*edit* I wouldn't mind showing you the code, but I'm not really sure *what* to show. Most everything's pretty basic at this point. Even the teleporter is just, upon collision with this specific thing, go to this specified next room. I am not sure what code to display here.

*second edit* wait are you saying to tell the object to destroy itself WHEN it first sends the player to the platformer? and then when returning, it should still be destroyed?? I didn't think of that. I guess I assumed that the room would be recreated from scratch each time you enter it, thus recreating the same object all over again? Huh. I'll go try that instead!
 
K

KaelaOpalheart

Guest
Heh. Nope! Though I think I'm getting closer? I got this:
FATAL ERROR in
action number 3
of Step Eventobj_teleporter
for object obj_topdown_player:

local variable __b__(100001, -2147483648) not set before reading it.
at gml_Object_obj_topdown_player_CollisionEvent_10_3 (line 7) - if __b__

Sounds like I need to set another bit of code first, in order to make this work?

There's no actual code directly in the teleporter object btw. The teleport itself is currently just the player having a collision event with the teleporter that specifies the next room. I moved the destroy instance action into that event and got that error when trying to teleport to the platformer.
 
E

Edmanbosch

Guest
Thanks for the suggestion! I gave it a try and switched the order, and sadly, no, it didn't work. I didn't really think it would work to put the action to destroy an object in the topdown room, into another object in the platform room, I was just hoping on a guess to connect it to the room transfer. That not working though, I would think that the code would need to go into something in the topdown room itself, since that's where the object that needs to be destroyed is, but then I'm not sure how to connect it to the event of the player re-entering the topdown room specifically when returning from the platformer room and not just upon starting the game (which starts in the topdown room for now). That's what I'm guessing now, is I'd need to connect it to when that specifically occurs, and THEN destroy the object. And even aside from not knowing the code to do that, I'm also not sure if that should go, say, in the player, in the object to be destroyed, or in just some sprite-less object sitting in the room.

*edit* I wouldn't mind showing you the code, but I'm not really sure *what* to show. Most everything's pretty basic at this point. Even the teleporter is just, upon collision with this specific thing, go to this specified next room. I am not sure what code to display here.

*second edit* wait are you saying to tell the object to destroy itself WHEN it first sends the player to the platformer? and then when returning, it should still be destroyed?? I didn't think of that. I guess I assumed that the room would be recreated from scratch each time you enter it, thus recreating the same object all over again? Huh. I'll go try that instead!
You can use a global variable for weather the platformer level is cleared or not, and for the room start event of your teleport object add some code that checks if the platformer level was cleared, and will destroy the teleport object if true. If you want it to be permanent(be in affect even after the game is closed) you would want to save the variable's value into an .ini file.
 
K

KaelaOpalheart

Guest
You can use a global variable for weather the platformer level is cleared or not, and for the room start event of your teleport object add some code that checks if the platformer level was cleared, and will destroy the teleport object if true. If you want it to be permanent(be in affect even after the game is closed) you would want to save the variable's value into an .ini file.
Oh nifty! I think I understand how to do that. Thanks, I'll go give that a try =D
 
K

KaelaOpalheart

Guest
Ok. So, that didn't work either. I already have a spriteless "room stuff" object in the topdown room to play music. I added to it a line of code in the create event with

global.platformer_cleared =0

if global.platformer_cleared = 1 {
instance_destroy(obj_teleporter)
}

and in the flag in the platformer room's flag I wrote

global.platformer_cleared = 1

alongside the collision event to send the player back. But, the teleporter was still there.

Any insight what I did wrong?
 
E

Edmanbosch

Guest
Ok. So, that didn't work either. I already have a spriteless "room stuff" object in the topdown room to play music. I added to it a line of code in the create event with

global.platformer_cleared =0

if global.platformer_cleared = 1 {
instance_destroy(obj_teleporter)
}

and in the flag in the platformer room's flag I wrote

global.platformer_cleared = 1

alongside the collision event to send the player back. But, the teleporter was still there.

Any insight what I did wrong?
The problem is that you set it to 0 right before you do the check, meaning that it will never be 1. You should initialize the global variable at the start of the game so that you won't be initializing it to 0 before the check.

Also, I'd recommend to use true/false instead of 0/1. It doesn't really change the functionality, but it looks a lot cleaner and is more readable.
 
K

KaelaOpalheart

Guest
The problem is that you set it to 0 right before you do the check, meaning that it will never be 1. You should initialize the global variable at the start of the game so that you won't be initializing it to 0 before the check.

Also, I'd recommend to use true/false instead of 0/1. It doesn't really change the functionality, but it looks a lot cleaner and is more readable.
Oh, I see your point. Silly me, I added that if statement in the create part too, not in like, a step or something :p But where should I put the global variable initialization? What kind of event? I guess there might be an obvious one but I'm not fully familiar with them all yet.

Either way. I truly appreciate all the help and I'll go search for a better version of this. :D
 
K

KaelaOpalheart

Guest
It worked! It worked! I found the Game Start event in Other, and put the variable in there. Then put the If statement into a step event. teleported to the platform and back. The teleporter WAS GONE! Thank you so much everyone :D :D :D
 
E

Edmanbosch

Guest
Oh, I see your point. Silly me, I added that if statement in the create part too, not in like, a step or something :p But where should I put the global variable initialization? What kind of event? I guess there might be an obvious one but I'm not fully familiar with them all yet.

Either way. I truly appreciate all the help and I'll go search for a better version of this. :D
Not an object event, rather in the creation code of the very first room of the game. This will guarantee it will be initialized.

It worked! It worked! I found the Game Start event in Other, and put the variable in there. Then put the If statement into a step event. teleported to the platform and back. The teleporter WAS GONE! Thank you so much everyone :D :D :D
Glad you got it working.
 
Top