Buttons, idles and load screen

Started by Peegee, Mon 11/10/2021 14:57:25

Previous topic - Next topic

Peegee

#20
Ooh

Peegee

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?

Crimson Wizard

Quote from: Peegee on Sat 16/10/2021 13:14:14
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

Peegee

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

#24
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: ags

function oDec01_Interact()
{
  cGob1.SetAsPlayer(); //
 
  player.Transparency=0; 
  cGob2.Transparency=0;
  cGob3.Transparency=0;
 
   player.Clickable=true; 
   cGob2.Clickable=true;
   cGob3.Clickable=true;

  cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163, eDirectionDown);
  player.ChangeRoom(1, 129, 171, eDirectionDown); // note: player character exists the room last, every time!
}


Now on ROOM 1 script:

Code: ags

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


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: ags

function room_Load() 
{
   if (Game.DoOnceOnly("Save level 1")) SaveGameSlot (1," room 1 initial state "); // saves the game level the first time you enter
   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)
   else RestoreGameSlot(1); // It reads the saved game every single time you enter this room again AND the above line is false
}


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.  ;)

There are those who believe that life here began out there...

Khris

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.

Peegee

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

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...

Peegee

Ok, great, with that I can manage. Thanks    PG

Peegee

Hello. Indeed, in my loading room, the inventory is displayed anyway, even with the function:

gInventoryBar.Visible = false;

I am using BASS initially.

Peegee

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

#31
I'm not sure what you mean by "sub-level".

But
Code: ags

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


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: ags

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


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: ags

 if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
 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.


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.  ;)
There are those who believe that life here began out there...

Peegee

#32
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: ags


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);
 
aDesperate_potato.Stop();
aVent_faible.Play(eAudioPriorityLow, eRepeat);

 if (Game.DoOnceOnly("Save level 2")) SaveGameSlot (2," room 2 initial state ");
 else if (!Arriveebateau) RestoreGameSlot(2);
}


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: ags

{
 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);
   
}
 if (Arriveebateau==true)
{
    cGob2.Transparency=0;
cGob2.FaceDirection(eDirectionDown);

cGob3.Transparency=0;
cGob3.FaceDirection(eDirectionDown);
cGob1.Clickable=true;
cGob2.Clickable=true;
cGob3.Clickable=true;
  
cGob1.ChangeRoom(2, 268, 639);
  
 if (Gob2Haut==false)
{
cGob1.ChangeRoom(2, 268, 639);
cGob2.ChangeRoom(2, 493, 650);
cGob3.ChangeRoom(2, 613, 725);
}
if (Gob2Haut==true)
{
cGob1.ChangeRoom(2, 268, 639);
cGob2.ChangeRoom(2, 602, 292);
cGob3.ChangeRoom(2, 613, 725); 
}  
}
}



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;)



Cassiebsg

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: ags

if (Gob2Haut==true) // do stuff
else // do other stuff
There are those who believe that life here began out there...

Peegee

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.

Khris

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.

Peegee

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.

Crimson Wizard

Quote from: Peegee on Wed 03/11/2021 17:21:30I 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.

Peegee

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.

Khris

#39
You can; exit the editor and rename the room files.

SMF spam blocked by CleanTalk