Author Topic: Buttons, idles and load screen  (Read 1788 times)

Re: Buttons, idles and load screen
« Reply #20 on: 16 Oct 2021, 12:56 »
Ooh
« Last Edit: 16 Oct 2021, 13:15 by Peegee »

Re: Buttons, idles and load screen
« Reply #21 on: 16 Oct 2021, 13:14 »
I don't have the problem to load because I am leaving from a loading room. I further simplified, removed my first load variable from the screen.

The real problem, what with "SaveGameSlot (1," room 1 initial state ");" and "ResetRoom (1);", to save and reload, the software is not able to reset neither the characters nor the variables, nor the contents of the inventory. Is this normal?

Re: Buttons, idles and load screen
« Reply #22 on: 16 Oct 2021, 14:10 »
The real problem, what with "SaveGameSlot (1," room 1 initial state ");" and "ResetRoom (1);", to save and reload, the software is not able to reset neither the characters nor the variables, nor the contents of the inventory. Is this normal?

You're mixing two separate methods: ResetRoom does not reload your save, it resets only the room you were in. To reload a save use RestoreGameSlot.

There's an example posted by Khris some time ago:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=59511.msg636640201#msg636640201

Re: Buttons, idles and load screen
« Reply #23 on: 17 Oct 2021, 07:48 »
Hello, when I put this command (to load the level) I have a conflict.

---------------------------------------------------------------------------
function oDec01_Interact()
{

  RestoreGameSlot(1);
 
  cGob1.SetAsPlayer();
 
  player.Transparency=0;
  cGob2.Transparency=0;
  cGob3.Transparency=0;
 
  player.ChangeRoom(1, 129, 171, eDirectionDown);
  cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163, eDirectionDown);

   player.Clickable=true;
   cGob2.Clickable=true;
   cGob3.Clickable=true;
---------------------------------------------------------------------------
 
Conflict:Cannot run this command, since since ther was a restoreGameSlot command already queued to run in "room103.asc, line 6 ( Line 6 is RestoreGameSlot1)

I don't understand where the conflict is, if I remove that:

-----------------------------------------------------------------------
player.ChangeRoom(1, 129, 171, eDirectionDown);
-----------------------------------------------------------------------
 I enter the level but everything is blocked.

Obviously the conflict is with the player.ChangeRoom. It is also there, to launch the game:

--------------------------------------------------------------------------------
function oJouer_AnyClick()
{
object[0].SetView(95);
object[0].Animate(0, 3, eOnce);
 
player.Transparency = 0;
player.ChangeRoom(1, 129, 171, eDirectionDown);
-----------------------------------------------------------------------------


Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Buttons, idles and load screen
« Reply #24 on: 17 Oct 2021, 10:22 »
Again, it's the same problem.

You can't restore a save game and change the room in the same function.

What you need to do:

- In the Menu room: put your exit code:

Code: Adventure Game Studio
  1. function oDec01_Interact()
  2. {
  3.   cGob1.SetAsPlayer(); //
  4.  
  5.   player.Transparency=0;
  6.   cGob2.Transparency=0;
  7.   cGob3.Transparency=0;
  8.  
  9.    player.Clickable=true;
  10.    cGob2.Clickable=true;
  11.    cGob3.Clickable=true;
  12.  
  13.   cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  14.   cGob3.ChangeRoom(1, 89, 163, eDirectionDown);
  15.   player.ChangeRoom(1, 129, 171, eDirectionDown); // note: player character exists the room last, every time!
  16. }
  17.  

Now on ROOM 1 script:

Code: Adventure Game Studio
  1. function room_Load()
  2. {
  3.    if (Game.DoOnceOnly("Save level 1")) SaveGameSlot (1," room 1 initial state "); // saves the game level the first time you enter
  4.    else RestoreGameSlot(1); // It reads the saved game every single time you enter this room again
  5. }
  6.  

However, you also said that the reason you can't used rooms 301 and above is that you don't want to reset every time, so here's a variation of the code:

Code: Adventure Game Studio
  1. function room_Load()
  2. {
  3.    if (Game.DoOnceOnly("Save level 1")) SaveGameSlot (1," room 1 initial state "); // saves the game level the first time you enter
  4.    else if (hasFinishedLevel1) return;  // This will do nothing (not reset the room) in case the player has finished level 1 (hasFinishedLevel1 is a bool variable that is set to false at start and changed to true once the player has finished level 1)
  5.    else RestoreGameSlot(1); // It reads the saved game every single time you enter this room again AND the above line is false
  6. }
  7.  

Note that you can have as many else if as you need in order to do meet whatever conditions you need.

Also: What is your native language? This is a pretty international forum, and maybe someone here can help explain to you in your native language.  ;)

« Last Edit: 17 Oct 2021, 10:25 by Cassiebsg »
There are those who believe that life here began out there...

Re: Buttons, idles and load screen
« Reply #25 on: 18 Oct 2021, 16:20 »
Yeah, saving and restoring the game doesn't really work "in between" other commands. When you call those, the engine waits for the game being idle first.

If you want to run commands after a game was restored, you need to use the global on_event function. However, it shouldn't really be necessary to run commands if you set up everything before saving the game, because restoring it will restore that exact state.

Re: Buttons, idles and load screen
« Reply #26 on: 18 Oct 2021, 18:16 »
Looks like your system is working flawlessly! Great!
Many thanks !

What you say is correct, compared to save / restore, because in other levels, I have rooms below level. Will they also be reset if we save when entering the main level?

I'm not done with the load room:

1- I only have to display the object which allows to launch the restoration when I save the level. What is the command to display an object in another room?

2- In my load room, I have to prevent the inventory from being displayed. I manage not to display the personal selection medallion but not the inventory. I would like to understand why it shows up in my game levels and not in my title pages.

My native language is French.

 ;)

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Buttons, idles and load screen
« Reply #27 on: 18 Oct 2021, 23:18 »
1: Objects exist only in the room they are created. If you want to have a button that you can hide/show in all rooms/levels, then I suggest you create a GUI and place it there. If you want to continue using objects you can, but you'll have to create that object from scratch in every room.

If you mean that you want to see that object when you load the room, then just add oName.Visible=true; to your room load function. (oName is of course, your object name).

2: To answer this question, we need to know what template you are using, if any. But basic concept is that you turn off the GUI's visibility. gGuiName.Visible=false; However, if you are using a template, the template might have code to make it active even if you turn it off. Therefore, we need this info.

There are several Frenchmen (and women) in this forum, and I believe there's even a French AGS forum. I can't write proper French, but I can read it.
so there's god opportunity for help in French.
There are those who believe that life here began out there...

Re: Buttons, idles and load screen
« Reply #28 on: 22 Oct 2021, 07:41 »
Ok, great, with that I can manage. Thanks    PG

Re: Buttons, idles and load screen
« Reply #29 on: 22 Oct 2021, 10:15 »
Hello. Indeed, in my loading room, the inventory is displayed anyway, even with the function:

gInventoryBar.Visible = false;

I am using BASS initially.

Re: Buttons, idles and load screen
« Reply #30 on: 22 Oct 2021, 15:22 »
Hello. In fact, I am not doing at all with the saving of level 2. It works to reload the level with the saving, he puts the characters back in place and the character says his intro phrase. But I have an additional sub-level room (only one of the characters goes there), and when I leave it, the characters must have a different positioning and the character must not say anything. I put a boolean variable "ArriveeBateau". It worked before but not anymore with this function:

if (Game.DoOnceOnly ("Save level 1")) SaveGameSlot (1, "room 1 initial state");

You told me about this function:

else if (hasFinishedLevel1) return;

... that I do not understand well (especially the "return"). I put my variable like this:

   else if (Arriveebateau == true) return;
... but it always ends up putting the game back in the starting position (code which is in the AfterFadein). So Currently, I have this (the variable "Dec2Saved" is used to display the object to load in the loading room):

------------------------------------------------------------

function room_Load()
{
 Dec2Saved=true;
 
    cGob1.Transparency=0;
cGob1.SetAsPlayer();

cGob2.Transparency=0;
cGob2.FaceDirection(eDirectionDown);

cGob3.Transparency=0;
cGob3.FaceDirection(eDirectionDown);
cGob1.Clickable=true;
cGob2.Clickable=true;
cGob3.Clickable=true;

hCabine.Enabled=false;

RemoveWalkableArea(2);

hotspot[8].Enabled=false;

   cGamin1.FaceDirection(eDirectionDown);
   cGamin1.ChangeView(20);
 
aVent_faible.Play(eAudioPriorityLow, eRepeat);

  if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
 
  else if (Arriveebateau==true) return;
}
--------------------------------------------------------------------
And in the AfterFadeIn:

--------------------------------------------------------------------
function room_AfterFadeIn()
{
 if (Arriveebateau==false)
{
  Wait(40);
aGob1Talk.Play (eAudioPriorityHigh,  eRepeat);
  player.FaceDirection(eDirectionDown);
  player.Say("Voici le Palamède,[de la marine aérienne[de notre bon roi Angoulafre.");
  aGob1Talk.Stop();
  Wait(40);
   player.FaceDirection(eDirectionRight);
   
   cGob2.Transparency=0;
cGob2.FaceDirection(eDirectionDown);

cGob3.Transparency=0;
cGob3.FaceDirection(eDirectionDown);
cGob1.Clickable=true;
cGob2.Clickable=true;
cGob3.Clickable=true;

cGob2.ChangeRoom(2, 347, 766, eDirectionDown);
cGob3.ChangeRoom(2, 432, 785, eDirectionDown);

}
----------------------------------------------------------------------
It's a hassle, and again, I don't know how I would reset the sub-level?

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Buttons, idles and load screen
« Reply #31 on: 22 Oct 2021, 15:51 »
I'm not sure what you mean by "sub-level".

But
Code: Adventure Game Studio
  1.  if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
  2.  else if (Arriveebateau==true) return; // this line is currently not doing anything.
  3.  

The return; means "do nothing and end the function". You only need this one, if you have a condition after it, like else that will do something else every single time all the above are false (note, that you can also have as many else if as you need).

If you want to "reset" the level, then you need to RestoreGameSlot(2);. Would that happen when the if is false?
If so, try this:

Code: Adventure Game Studio
  1.  if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
  2.  else if (Arriveebateau) return; // you don't need to == when it´s a bool.
  3.  else RestoreGameSlot(2); // this will restore the game if the above are false
  4.  

Or, since at the moment you don't really need a line that does nothing, you can just check if the bool Arriveebateau is false:

Code: Adventure Game Studio
  1.  if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
  2.  else if (!Arriveebateau) RestoreGameSlot(2); // Placing a ! in front of a a bool means you are checking if it's false. And if it's false, then restore the game slot. And since there are no "else" bellow the function will end here, meaning it will not restore if Arriveebateau is true.
  3.  

Just a note/tip, I always make my bools be a question, so I can automatic reply yes/no in my head. It's also useful to differentiate from ints or strings.

So, I would have named my bool hasArrivedToBoat.... And now I know exactly if the answer is yes or no.  ;)

Note: you can use the # button to add the code tag, or just write [ code=ags ] (without the spaces), paste your code, and then finish it with  [ /code ]. It'll look so much better for us to read your code.  ;)
« Last Edit: 22 Oct 2021, 15:54 by Cassiebsg »
There are those who believe that life here began out there...

Re: Buttons, idles and load screen
« Reply #32 on: 23 Oct 2021, 08:12 »
Hello, thank you for your reply.
What I mean by sub level: It is one more room, where only one of the 3 characters enters, and when he leaves, all the characters are positioned elsewhere than at the entrance to the main level. I will also have to save what happens in this room, and that it is also reinitialized when we load the main room.

Here is what I currently have in the room load of level2:

Code: Adventure Game Studio
  1.  
  2. function room_Load()
  3. {
  4.  
  5.   Dec2Saved=true;
  6.  
  7.     cGob1.Transparency=0;
  8. cGob1.SetAsPlayer();
  9.  
  10. cGob2.Transparency=0;
  11. cGob2.FaceDirection(eDirectionDown);
  12.  
  13. cGob3.Transparency=0;
  14. cGob3.FaceDirection(eDirectionDown);
  15. cGob1.Clickable=true;
  16. cGob2.Clickable=true;
  17. cGob3.Clickable=true;
  18.  
  19. hCabine.Enabled=false;
  20.  
  21. RemoveWalkableArea(2);
  22.  
  23. hotspot[8].Enabled=false;
  24.  
  25.    cGamin1.FaceDirection(eDirectionDown);
  26.    cGamin1.ChangeView(20);
  27.  
  28. aDesperate_potato.Stop();
  29. aVent_faible.Play(eAudioPriorityLow, eRepeat);
  30.  
  31.  if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
  32.  else if (!Arriveebateau) RestoreGameSlot(2);
  33. }
  34.  

In the AfterFadein : (the variables are there to exit the sub level, to say that I have already arrived in the boat, and that the second character is either at the top, at the bottom.
function room_AfterFadeIn()

Code: Adventure Game Studio
  1. {
  2.  if (Arriveebateau==false)
  3. {
  4.   Wait(40);
  5. aGob1Talk.Play (eAudioPriorityHigh,  eRepeat);
  6.   player.FaceDirection(eDirectionDown);
  7.   player.Say("Voici le Palamède,[de la marine aérienne[de notre bon roi Angoulafre.");
  8.   aGob1Talk.Stop();
  9.   Wait(40);
  10.    player.FaceDirection(eDirectionRight);
  11.    
  12.    cGob2.Transparency=0;
  13. cGob2.FaceDirection(eDirectionDown);
  14.  
  15. cGob3.Transparency=0;
  16. cGob3.FaceDirection(eDirectionDown);
  17. cGob1.Clickable=true;
  18. cGob2.Clickable=true;
  19. cGob3.Clickable=true;
  20.  
  21. cGob2.ChangeRoom(2, 347, 766, eDirectionDown);
  22. cGob3.ChangeRoom(2, 432, 785, eDirectionDown);
  23.    
  24. }
  25.  if (Arriveebateau==true)
  26. {
  27.     cGob2.Transparency=0;
  28. cGob2.FaceDirection(eDirectionDown);
  29.  
  30. cGob3.Transparency=0;
  31. cGob3.FaceDirection(eDirectionDown);
  32. cGob1.Clickable=true;
  33. cGob2.Clickable=true;
  34. cGob3.Clickable=true;
  35.  
  36. cGob1.ChangeRoom(2, 268, 639);
  37.  
  38.  if (Gob2Haut==false)
  39. {
  40. cGob1.ChangeRoom(2, 268, 639);
  41. cGob2.ChangeRoom(2, 493, 650);
  42. cGob3.ChangeRoom(2, 613, 725);
  43. }
  44. if (Gob2Haut==true)
  45. {
  46. cGob1.ChangeRoom(2, 268, 639);
  47. cGob2.ChangeRoom(2, 602, 292);
  48. cGob3.ChangeRoom(2, 613, 725);
  49. }  
  50. }
  51. }
  52.  
  53.  

I have two problems:
- He always gives me the characters in the first position of arrival on the boat, even when I leave the sub level.

- The backup system works, I can reload level 2. But if I reload level 1, and I try to reload level 2 afterwards, the object in the loading room that allows me to launch the backup has disappeared. (object that I display thanks to the variable Dec2Saved = true;)


« Last Edit: 23 Oct 2021, 09:00 by Peegee »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Buttons, idles and load screen
« Reply #33 on: 23 Oct 2021, 22:00 »
I think you need to stop referring to "level 1" and "level 2"... since there is no "level" in AGS it only makes sense to you, and we need to keep having to figure out what you are actually referring to.

So, if level 1 = room 1 and level 2 = room 2, please say "room 2" instead of "level 2". :) Otherwise please explain (same room, different room configuration?)

The way you currently have room_load setup up does the following:

Sets everything up.
Saves the game slot 2 the first time you enter the room.
Restores the saved game slot 2 and "erases" everything you did before (but that you had saved anyway).

But you never setup your characters differently in case Arriveebateau==true.

And I'm confused, in which room are you? 1? And the characters you are sending to room 2, who's the player character?

I'm not sure what Gob2Haut does and where it's setup, but in a bool  you only have false or true, this means that you don't need to check if it's true and then check again if it's false.

So you just need to check one for one of the conditions, and finish with an else.
Code: Adventure Game Studio
  1. if (Gob2Haut==true) // do stuff
  2. else // do other stuff
  3.  
There are those who believe that life here began out there...

Re: Buttons, idles and load screen
« Reply #34 on: 25 Oct 2021, 08:35 »
Hello ! I'm trying to explain the context to you better (for the next room, I would avoid the "sub-levels"!).

 The 3 characters arrive on a boat, room 2, they are positioned in the foreground. There is a cabin, room 3, where only the main goblin, cGob1, can access. When he comes out of the cabin, the 3 characters must have a different location from the start.
This is why I test if they have already arrived on the boat to position them correctly (I give cGob1 its position in the cabin exit code and in the AfterFadeIn). But with the backup system, they always get back to the starting position.
 
Complication, the first 2 goblins, 1 and 2, access by a mechanism at the top of the boat. That's why I have to test if cGob2 is at the top of the boat (Gob2Haut == true) to position it correctly.

The good news is that when I reload level (2), apparently the cabin room (3) is reset too.

Second problem, I put this variable: Dec2Saved = true; to signal in my loading page to display the object that will allow me to load room 2. It works, except that if I load room 1 in the meantime, the object to load room 2 disappears in the loading page. The reverse is also true.

Thanks for your help.

Re: Buttons, idles and load screen
« Reply #35 on: 25 Oct 2021, 09:04 »
Saving the game doesn't just save the current room, it saves the entire game's state, including all other rooms (except room numbers 300+). It works exactly like save games work in other games.
If you want to reset room states independently you cannot use save games (or rather, it's pointless).

As for keeping track of more complex stuff: use ints instead of bools, or check multiple bools at the same time.
You can also use  player.PreviousRoom  to check if room 2 was entered from the cabin room or from elsewhere.

Re: Buttons, idles and load screen
« Reply #36 on: 03 Nov 2021, 17:21 »
Hello, actually I don't even need to save the levels. I just need to restart a room in its initial state. I try with "ResetRoom (1)" but it doesn't reset.

Re: Buttons, idles and load screen
« Reply #37 on: 03 Nov 2021, 17:27 »
I just need to restart a room in its initial state. I try with "ResetRoom (1)" but it doesn't reset.

Could you elaborate on that, did nothing happen at all, or some particular things did not reset?

Also, like I mentioned before, if you need a room to reset each time you re-enter it, you may simply make it non-state-saved room by assigning a number above 300.

Re: Buttons, idles and load screen
« Reply #38 on: 03 Nov 2021, 17:42 »
He enters the room, he throws what there is in the After fade in, but he does not reset anything (neither the variables, nor the positions of characters or objects).
Rooms numbered from 300, I can't because I have a level made up of 2 rooms, anyway I don't think you can change the room number along the way.

Re: Buttons, idles and load screen
« Reply #39 on: 03 Nov 2021, 17:44 »
You can; exit the editor and rename the room files.
« Last Edit: 04 Nov 2021, 11:02 by Khris »