Restarting the game, resetting the label!

Started by Atelier, Sun 14/06/2009 11:09:49

Previous topic - Next topic

Atelier

Hullo.

So far I've come across heaps of problems with my project. Here's what's happening:


  • For my one room game I have three themes.
  • These three themes take the form of different background frames which you can change by pressing 1, 2, or 3.
  • I have created a simple label GUI to appear in a certain place in the room, whatever the theme.
  • In my room script, under the room_Load function, I have got 250 different phrases that are randomly selected when the player enters.
  • The phrase that gets selected appears in the label.
  • I want the player to be able to change the text in the label so they get another random phrase.

Now, this last point I have been able to do with no problems. To change the theme, I am using the restart function to restart the game. Since it is only a one room game, it restarts at the very beginning of the game before the phrase is selected. I'm using this because I cannot use resetroom, as the player can't reset the room they're in.

My problem starts when the player changes the theme. The text in the label stays as it is, which is fine, but if you want to get another phrase and continue using that theme you have to press the space bar (which is the button to restart.) This means it restarts the game at the very beginning again, and although it gives a new phrase, it changes from the theme the player chose and uses the default theme.

To stop this happening, I have entered the second line under the button's code.

Code: ags
function on_key_press()
{
   if (keycode == 2) SetBackgroundFrame(2);
   SetRestartPoint();
}


Now, whenever the player changes theme it sets that theme as the restart point so it continues to use that every time the players restarts. BUT this is where the problem continues. The phrase in the label is stuck as it was when you changed theme, and restarting doesn't change the phrase. Then, it doesn't matter it you re-change themes - the phrase is stuck until you close the game.

I have tried having the three themes as separate rooms, but this doesn't work for another reason. How would I reselect the phrase every time the game reloads? I've tried various different things but it never works for something or another is wrong. I probably haven't explained as well as I should have, but I'd appreciate any help at the moment.

Thanks! :)

GuyAwesome

If you're changing the restart point, aren't you effectively saving the game at that point? That is, anything that should be reset, won't be, so I'm not sure what they point of restarting would be after that.

Couple of possibilities:
Renumber the game room to something 300+. These rooms are 'non-state saving' - when you leave and re-enter them (or in this case ChangeRoom to themselves), they reset to how they were when the game first loaded. BUT other in game things, like global variables, don't reset so you could store the current theme (background frame) to a variable and set the frame in room_Load. This might also help with your other question, about Restarting the game, not the music. Since the room is being reloaded, the phrase should be regenerated. Moving the player to an empty black-backgrounded room where they're not visible, resetting the main room and immediately moving them back might work too. It should just look like a longer than usual room transition.
Or, use the way NsMn suggested in that topic, and save/read back the background frame as well as the music position.
You could create an auto save at the beginning of the game, and restore that rather than using RestartGame. Then use on_event to have the phrase generated for eEventRestoreGame.

Oh, or I suppose you could just make the button to change the random phrase different from the one to reset the room :) There'll be others, but those are just off the top of my head. What're some of the things you've tried, and how did they go wrong?

Atelier

#2
Thanks, this has been really helpful. I've decided to use your suggestion of global variables; but I might need some help making this.

I've set up a global variable of int type, called it background_frame and set the default value to 0. In my room script, under room_Load, I've put something along the lines of this...

Code: ags
function room_Load()
{
   if (background_frame == 0) SetBackgroundFrame(0);
   if (background_frame == 1) SetBackgroundFrame(1);
   if (background_frame == 2) SetBackgroundFrame(2);
}


I guess I have to assign the value of background frame when the player leaves the room (and so resets it), and this needs to be done in room_Leave. What coding do I need to check the background frame and assign it as a number to background_frame, or have I got this all wrong?

Thanks. :)

Edit: I've just noticed the GetBackgroundFrame(); function. How do I use this to check it?

GuyAwesome

#3
It should be simply
Code: ags

function room_Leave() {
  background_frame = GetBackgroundFrame();
}

I was thinking you'd set the variable when you changed the frame, but your way makes more sense. (And save a bit of typing.)

Quote
I've set up a global variable of int type, called it background_frame and set the default value to 0.
Because of the way you've said this, I'm guessing you've used the 'Global Variables' pane in the editor? If you've done that, or created an int in the global script and exported/imported it (the old fashioned way ;)), it should work fine. The important thing is that it's global, as I think room based ints will be reset along with the room making it a bit of a waste of time.

EDIT:
Just caught your edit, fortunately it doesn't change my reply. You can probably ignore the second paragraph, I'm just trying to pre-empt any future problems with the variable...

Atelier

Woo! It works! Thanks for your help, otherwise it would have been a boring one-theme room... :)

Khris

Without having read all the rest, this:

Quote from: AtelierGames on Sun 14/06/2009 14:02:28
Code: ags
  if (background_frame == 0) SetBackgroundFrame(0);
  if (background_frame == 1) SetBackgroundFrame(1);
  if (background_frame == 2) SetBackgroundFrame(2);

can be done using just
  SetBackgroundFrame(background_frame);
(provided the variable holds a valid value at all times)

GuyAwesome

Oh yeah, I missed that. I don't think it's possible for background_frame to have an invalid value (defaults to 0, and is only changed to GetBackgroundFrame()), so that'll work.

Having just seen the production thread, I'm guessing this is for Block PAD? I'm wondering why you need to bother with the resetting/restarting the room just (I'm assuming) to change the phrase - it seems like it just adds complications (most of which you've solved now, admittedly :)).

Atelier

I've only got 38 lines of code in my global script, 6 of which is a fancy green header ;), so it's not too bad now that you solved the problems for me. Oh, and I've used Khris' suggestion, so thanks for that too.

SMF spam blocked by CleanTalk