Author Topic: Back to hub key?  (Read 3569 times)

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Back to hub key?
« 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!

Derf

  • Wannabe
  • Posts: 23
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Firefox 43.0 Firefox 43.0
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #1 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);

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #2 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?

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #3 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.

xElectricZz

  • Wannabe
  • Posts: 14
  • ECH
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 42.0 Firefox 42.0
    • View Profile
    • Twitch Page
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #4 on: January 12, 2016, 04:19:16 PM »
Here: https://pastebin.com/K3ypy0xF

I hope that works for you.
Discord - Electric#6878

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #5 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?

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #6 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?
« Last Edit: January 12, 2016, 06:58:11 PM by Kyir »

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #7 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.

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #8 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.
« Last Edit: January 12, 2016, 08:40:06 PM by Kyir »

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #9 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.

Kyir

  • The Kid
  • Posts: 293
  • Normal Guy
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #10 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.

Hop

  • Wannabe
  • Posts: 43
  • HopPros on Twitch
  • OS:
  • Mac OS X 10.9.5 Mac OS X 10.9.5
  • Browser:
  • Chrome 47.0.2526.106 Chrome 47.0.2526.106
    • View Profile
  • Playstyle: Keyboard
Re: Back to hub key?
« Reply #11 on: January 13, 2016, 01:06:27 AM »
Finally got it working I think. Thanks!