I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: Hop on January 12, 2016, 01:12:44 AM

Title: Back to hub key?
Post by: Hop on January 12, 2016, 01:12:44 AM
Hey I'm trying to have a hub room at the end of my game where you can revisit screens if you wish. After reaching the hub room I want the player to be able to press a key and return to the hub at anytime. I was trying to use a persistent key press object, but it just broke my game. So how would I implement something like this? An example would be being able to go back in bmxbandit's game Meltdown to do needle or fight a boss by pressing backspace.

I'm using Yoyo's Studio Engine.

Thanks!
Title: Re: Back to hub key?
Post by: Derf on January 12, 2016, 05:51:03 AM
Put a keyboard press event for whatever key you want in the world object and put code to the effect of this:

Code: [Select]
with(objPlayer){
     instance_destroy();
}

room_goto(rHub);
Title: Re: Back to hub key?
Post by: Hop on January 12, 2016, 09:40:46 AM
How do I make it so that the key only works after you've been to the hub before though?
Title: Re: Back to hub key?
Post by: Kyir on January 12, 2016, 10:22:41 AM
Do you already have some sort of secret/item array in place in your code? If so, you just set one value of it to true whenever you enter the hub and check if that value is true before executing the code upon key press.
Title: Re: Back to hub key?
Post by: xElectricZz on January 12, 2016, 04:19:16 PM
Here: https://pastebin.com/K3ypy0xF (https://pastebin.com/K3ypy0xF)

I hope that works for you.
Title: Re: Back to hub key?
Post by: Hop on January 12, 2016, 06:27:27 PM
Thanks for the replies!

ElectricZz I got the main function of being able to warp back to the room after you've been there working properly however the only way I was able to achieve this was by removing the lines of codes your guide says to put into scrLoadGame and scrSaveGame. I'm assuming that those two keep it so you can warp back after you reload your game. When I add those two lines of code It works fine till I press 'R' or try and reload and it will say "Save Invalid". Then it boots me back to the main title. Starting a new game works fine though. Is there a specific area in the script I need to place it?
Title: Re: Back to hub key?
Post by: Kyir on January 12, 2016, 06:51:34 PM
I misread your problem. Not entirely sure what's wrong, but if it functions fine when you start a new game file is there really an issue?
Title: Re: Back to hub key?
Post by: Hop on January 12, 2016, 07:52:38 PM
Yeah because if you reset or reload the game boots you back to main menu and won't let you load it again and if I don't have the code in the saves you lose the ability to warp back to the hub when you reload.
Title: Re: Back to hub key?
Post by: Kyir on January 12, 2016, 08:37:28 PM
Okay, I see what you mean. Assuming you're using the YoYo Engine, I'd recommend just making use of the built-in secret array if custom code isn't working.

Make an object in the hub room with the create code:
 global.saveSecretItem[1] = true;

Then check if that's true before executing the code you're using to bring the player back. Something like:
// Event for whatever key you want pressed
if global.saveSecretItem[1] = true {
player.room = [whatever the hub room's name is];}

Assuming I'm reading the code in the engine right, this is already built into it. The only thing is that the player will need to save once after entering the hub for that variable to save.
Title: Re: Back to hub key?
Post by: Hop on January 12, 2016, 09:44:46 PM
Ok so now its working and remembers the variable upon reset. However for whatever reason when I press "w" to warp back it warps me to the position I am currently in rather than where the start player object is resulting in being stuck in walls and such.
Title: Re: Back to hub key?
Post by: Kyir on January 12, 2016, 10:38:33 PM
Oh, I have no idea how those objects work. I'd remove it and add this to the warping code:
player.x = 400
player.y = 300

That would go to the center of the room, but just change it to whatever you want.
Title: Re: Back to hub key?
Post by: Hop on January 13, 2016, 01:06:27 AM
Finally got it working I think. Thanks!