Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: Peegee on Mon 11/10/2021 14:57:25

Title: Buttons, idles and load screen
Post by: Peegee on Mon 11/10/2021 14:57:25
Hello, newbie on this forum (by the way on all forums), I don't know is my technical questions will be well placed, thank you for helping me.
I started a game (for a few months) on AGS (great software!), Which will be called Gobliiins 5. I have some technical questions, there may be the solution in the manual but I do not understand everything, not perfect in English.

1- I am not very comfortable with GUI questions. On my "load a level" room, I would like to make a back button, but I don't see the button creation tool when I am on my room, what should I do?

2- For some actions, I prefer to hide a character and replace it with an object, but after a while the animated idle arrives, unexpectedly. How to deactivate idle momentarily?

3- When I load a level, if I start playing and load it again, I notice that it does not reset it. Is there a way for this or should I set the loading code to zero all items? I have very rich levels and dozens of variables.

Thanks in advance.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Mon 11/10/2021 15:27:23
Hello.

Quote from: Peegee on Mon 11/10/2021 14:57:25
1- I am not very comfortable with GUI questions. On my "load a level" room, I would like to make a back button, but I don't see the button creation tool when I am on my room, what should I do?

GUI are completely separate from the rooms, they are created in their GUI editor. You could make a GUI, make it not visible by default, display it in the particular room using script command (e.g. gGui.Visible = true) and hide back in "room leave" event (gGui.Visible = false).
But there are other ways to make "buttons", for example you may also make one using a room object.
What method to choose depends on what is more convenient for you, and how do you make your "load level" screen.

Quote from: Peegee on Mon 11/10/2021 14:57:25
2- For some actions, I prefer to hide a character and replace it with an object, but after a while the animated idle arrives, unexpectedly. How to deactivate idle momentarily?

Answering your question directly, that would be Character.SetIdleView function, passing -1 as the "view" parameter would deactivate it, and later you would need to call it again with a proper view number to turn it back.
But it seems the issue here is rather that the character is not hidden properly, or even that it's replaced with an object.
Regarding hiding, how do you currently do that, are you changing their view to something that contains empty sprites? Note there are several methods of hiding them, e.g. they may be moved outside of the room bounds, or have their Transparency set to 100.
Finally, what is the reason to replace character with an object? Characters are superior to an object, they can do everything that object does. It's likely there's a way to make character do what you need without replacing them.

Quote from: Peegee on Mon 11/10/2021 14:57:25
3- When I load a level, if I start playing and load it again, I notice that it does not reset it. Is there a way for this or should I set the loading code to zero all items? I have very rich levels and dozens of variables.

1. AGS rooms may be state-saving and non-state-saving. Currently this is chosen only by its number: room numbers 1-300 are saving their states, and room numbers above 300 are not.
You choose the room number when creating them, and also may change them anytime by editing their "Number" property while in the editor.
2. If you want to reset the room state only in particular case, there's ResetRoom script function. Note that it will only reset objects and variables belonging to that room, if you want to reset also global variables and characters, you would have to do so by hand.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Tue 12/10/2021 07:51:40
Hello, thanks for your reply.
  I still don't quite understand the GUI part. I learned this software thanks to a brilliant girl (author of Chaelle) who showed me everything, but the GUI remains mysterious, in any case I would not have done it just with the instructions.

Thank you for all those informations. Character.SetIdleView can be efficient, and change transparency too. Currently I'm using an empty spride view, it's not that great.

I sometimes replace the character with an object:
1- Because I can change its depth.
2- Because I couldn't figure out how to move it instantly.

In my loading page, it will actually be easier to create a "button" with an object. But I couldn't find the code to load the level.

So 2 questions:
How to move the character instantly?
What code to load a level, and have it reset each time?

Thanks in advance. PG
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Tue 12/10/2021 08:13:15
Quote from: Peegee on Tue 12/10/2021 07:51:40
I sometimes replace the character with an object:
1- Because I can change its depth.

Could you elaborate on this, what do you mean by "depth"?

Quote from: Peegee on Tue 12/10/2021 07:51:40
How to move the character instantly?

Characters have "x" and "y" properties, so you do simply
Code (ags) Select

cChar1.x = 100;
cChar1.y = 200;

or
Code (ags) Select

player.x = 100;
player.y = 200;

for simplicity if it's a player character.

Quote from: Peegee on Tue 12/10/2021 07:51:40
What code to load a level, and have it reset each time?

By "level", do you mean a room?
You load a new room using player.ChangeRoom command. You reset a room using ResetRoom command. But if you need the room to be reset every time you enter it. then simply give that room a number above 300, like I explained in my previous post.

There are also good video tutorials by densming which I usually recommend. They are a little old, but most of the things still match recent version:
Here's the link to the youtube playlist (https://www.youtube.com/watch?v=1Ml_DR76Cl4&list=PL21DB402CB4DAEAEF)
Title: Re: Buttons, idles and load screen
Post by: Khris on Tue 12/10/2021 08:20:49
Let me start with the easier stuff:

One of the characters is set as player character, and AGS loads a room if the player character is moved to that room. So the command to load a level is
Code (ags) Select
  player.ChangeRoom(room_number, x, y);
Simply use a y coordinate of -1 to completely hide the player character.
Using an empty view is one way to hide them but you can simply position them outside the room's coordinate range instead.

An easy way to reset a room is to save the game in the room's before fadein event (room_Load function) and simply restore that game at the appropriate point in time (for instance when a button is clicked).

Moving a character instantly can be done by changing their .x and .y directly:
Code (ags) Select
  cNpc.x = 123;
  cNpx.y = 45;


Not sure what you mean by depth though? Their baseline? Characters have one, too; it's at their feet but can be set manually to a different y coordinate.

As for GUIs: I remember having great respect for AGS's GUI system but the reason was primarily that I wasn't used to event based programming in general. It takes some getting used to, primarily because it means you have to keep writing functions that will be called by the engine, as opposed to writing the engine. Plus, these functions are going to run at arbitrary points in time. A good example of this is implementing key handling. The Sierra template for instance uses a bunch of GUIs, and ideally one should be able to close any of them by hitting the escape key. This is very simple with linear programming but in an event based environment all you have is a single on_key_press function that isn't tied to any GUI. Which means you need to check the state of your game, then act accordingly.
It just takes time and practice to wrap your head around this.
Although in the end, a GUI is just a rectangle hovering above your current room, and clicking a button runs a function. Creating your own quit game GUI for instance is very straightforward: the "cancel" button simply makes the GUI invisible again, and the "quit" button quits the game.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Tue 12/10/2021 09:36:21
Hello, thank you for the impeccable instant move feature!

What I meant by depth is the depth in z, the baseline for "front to back" questions. Apparently we can't change that on the characters, it's determined by the low point of the sprite. I just read your second answer, I don't see where we change that.

I can't use numbers from 300 because I have levels with multiple rooms, which don't need to be reset every time.
I redid a room load, with an object to launch room 1 with this code:
{
   ResetRoom (1);
 
player.Transparency = 0;
   cGob1.ChangeRoom (1, 129, 171);
   cGob1.FaceDirection (eDirectionDown);
   cGob2.ChangeRoom (1, 171, 166);
   cGob3.ChangeRoom (1, 89, 163);
}
(I have 3 characters) But it doesn't work, it doesn't reset when I reload the level a second time ...

Otherwise the tutorials in English are too difficult for me.

Sorry for the lines of code, I read that you have to put them a certain way but I didn't understand how.

PG
Title: Re: Buttons, idles and load screen
Post by: Khris on Tue 12/10/2021 10:56:49
Characters have a .Baseline (https://www.adventuregamestudio.co.uk/manual/ags46.htm#Character.Baseline) property you can use. Their .z coordinate is meant to do the opposite: keep their baseline at their y position while moving them up or down on the screen.

So it really depends on the situation. If your character is standing on a pedestal, you can either
a) position them at the pedestal's base coordinates, then use .z to draw them further up or
b) position them at the top of the pedestal but move down their baseline to the pedestal's base

As for resetting a room, again, save the game when the room loads, then restore the game. This is by far the easiest and most reliable way to reset your game to a previous state.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 13/10/2021 11:24:44
OK, thanks. For the baseline of characters, indeed I have already modified it for a fix character, impossible to find back where is this function. But anyway, you can't change it during the game, depending on the circumstances.

I hadn't understood to save the room before. But how do you do that? I did a room load and a object thumbnail to load the room. But how to save a room and put the save in this object?

  I know that I am a heavyweight but I have no programming skills, I am just an animator graphic designer.    PG
Title: Re: Buttons, idles and load screen
Post by: Khris on Wed 13/10/2021 13:02:26
You can change the baseline at any time during the game:
Code (ags) Select
  cSomeguy.Baseline = 123;

As for "object thumbnail" and "put the save in this object" I have no idea what you're referring to.

What I meant is basically
Code (ags) Select
function room_Load() {
  SaveGameSlot(101, "room x initial state");
}


To reset the room, call
Code (ags) Select
  RestoreGameSlot(101);
in an object interaction or button's onClick function or whenever you need. This will load save game #101, effectively resetting the room.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Thu 14/10/2021 09:32:51
Hello !

Ok for the baseline, practical.

But I don't understand the Slot issue. Where is the backup going?
I have a crash when I put the SaveGameSlot function on. I am in the title page, I am trying to launch level 1:

function hSuite2_AnyClick()
{

player.Transparency=0;
  cGob1.ChangeRoom(1, 129, 171);
cGob1.FaceDirection(eDirectionDown);
  cGob2.ChangeRoom(1, 171, 166);
  cGob3.ChangeRoom(1, 89, 163);
 
  cPatate.ChangeRoom(1,246, 229);
 
aZik01.Stop();

SaveGameSlot(1, "room 1 initial state");
}

Error message:SaveGameSlot:Cannot run this command, since there was a NewRoom command already queued to run in "room101,asc, line 17

I don't understand this command, what should I do?
Title: Re: Buttons, idles and load screen
Post by: Peegee on Thu 14/10/2021 09:47:33
Ok, sorry, it works better if I put it in the right place, in the room load of room 1.

Yes, it's starting to work better. The problem is complicated by the fact that I have 3 player characters. In any case, thank you for your patience. PG
Title: Re: Buttons, idles and load screen
Post by: Khris on Thu 14/10/2021 09:53:39
Changing the player character's room doesn't happen immediately, the command gets queued. The rest of the function runs, then AGS switches to the new room and runs its room_Load(), or whatever the "enters room before fadein" event is linked to.

This is why I deliberately put the SaveGameSlot command inside room_Load in my example code.

The error message is trying to tell you exactly what the problem is: saving a game should happen at a point where the game is idling, waiting for input. You're trying to save "during" a room transition.

room_Load is also the perfect spot to initialize your room, so move all relevant commands there.
Like this:

Code (ags) Select
function hSuite2_AnyClick() {
  // stop music and load room #1
  aZik01.Stop();
  player.ChangeRoom(1, 246, 229);
}


Now set up the room's initial state and queue saving it
Code (ags) Select
function room_Load() {

  // hide player character
  player.Transparency = 0;

  // position other characters in current room
  cGob1.ChangeRoom(player.Room, 129, 171, eDirectionDown);
  cGob2.ChangeRoom(player.Room, 171, 166);
  cGob3.ChangeRoom(player.Room, 89, 163);

  SaveGameSlot(1, "room 1 initial state");

}
Title: Re: Buttons, idles and load screen
Post by: Peegee on Thu 14/10/2021 11:14:18
To tell the truth I'm regressing ... He can no longer launch level 1, I have a black screen, and no error message ...



I understood the black screen ... I could not have player.ChangeRoom in hSuite2-any click AND cGob1.ChangeRoom in Room_load.
I have to put it only in hSuite2.

In any case it seems to work! Thanks a lot !!!   :-D       PG
Title: Re: Buttons, idles and load screen
Post by: Khris on Thu 14/10/2021 11:52:08
Please try to post relevant code.
room_Load runs before the screen fades in, so my guess is you put something in there which blocks the game.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Fri 15/10/2021 08:57:24
Hello, in fact it's always a hassle. He cannot reset the level properly, he cannot reset non-player characters. When I select one of the other two characters to go loader, it's worse.

Here is what there is at the loading level:

function oDec01_Interact()
{
  ResetRoom(1);
 
cGob1.Transparency=0;
cGob2.Transparency=0;
cGob3.Transparency=0;
  cGob1.ChangeRoom(1, 129, 171);
  cGob1.FaceDirection(eDirectionDown);
  cGob2.ChangeRoom(1, 171, 166);
    cGob1.FaceDirection(eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163);
    cGob1.FaceDirection(eDirectionDown);
  cGob1.Clickable=true;
   cGob2.Clickable=true;
    cGob3.Clickable=true;
}


Here is the room load, I put a variable to save only at the first entry in the level:


function room_Load()
{
if (Dec1one==false)
{
RemoveWalkableArea(2);
oFleur2.Clickable=false;


  cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163, eDirectionDown);
 
cPatate.ChangeRoom(1,246, 229);
cGamin1.ChangeRoom(1, 134, 431);

   SaveGameSlot(1, "room 1 initial state");
   
   Dec1one=true;
   
   if (player==cGob2)
   
{
     cGob1.Transparency=0;
cGob2.Transparency=0;
cGob3.Transparency=0;
 
  cGob2.ChangeRoom(1, 171, 166);
    cGob1.FaceDirection(eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163);
    cGob1.FaceDirection(eDirectionDown);
  cGob1.SetAsPlayer();
 
  cGob1.ChangeRoom(1, 129, 171);
  cGob1.FaceDirection(eDirectionDown);
}
  if (player==cGob3)
   
{
     cGob1.Transparency=0;
cGob2.Transparency=0;
cGob3.Transparency=0;

  cGob2.ChangeRoom(1, 171, 166);
    cGob1.FaceDirection(eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163);
    cGob1.FaceDirection(eDirectionDown);
  cGob1.SetAsPlayer();
 
   cGob1.ChangeRoom(1, 129, 171);
  cGob1.FaceDirection(eDirectionDown);
}
}
else if (Dec1one==true)
{
RemoveWalkableArea(2);
oFleur2.Clickable=false;


  cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163, eDirectionDown);
 
cPatate.ChangeRoom(1,246, 229);
  cGamin1.ChangeRoom(1, 134, 431);
   
   if (player==cGob2)
   
{
     cGob1.Transparency=0;
cGob2.Transparency=0;
cGob3.Transparency=0;
 
  cGob2.ChangeRoom(1, 171, 166);
    cGob1.FaceDirection(eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163);
    cGob1.FaceDirection(eDirectionDown);
  cGob1.SetAsPlayer();
 
  cGob1.ChangeRoom(1, 129, 171);
  cGob1.FaceDirection(eDirectionDown);
}
  if (player==cGob3)
   
{
     cGob1.Transparency=0;
cGob2.Transparency=0;
cGob3.Transparency=0;

  cGob2.ChangeRoom(1, 171, 166);
    cGob1.FaceDirection(eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163);
    cGob1.FaceDirection(eDirectionDown);
  cGob1.SetAsPlayer();
 
   cGob1.ChangeRoom(1, 129, 171);
  cGob1.FaceDirection(eDirectionDown);
}
}
}
Title: Re: Buttons, idles and load screen
Post by: Cassiebsg on Fri 15/10/2021 17:55:44
Who's the player character?

Also, Khris already said that SaveGameSlot(1, "room 1 initial state"); runs last, so it should be the last line in your code.

You have a bunch of  cGob1.SetAsPlayer(); and  cGob1.ChangeRoom(1, 129, 171); after your save code. Since both run at the end of the function, you again have a conflict. And I think FaceCharacter is a block action. (you can set the direction the character should face inside the ChangeRoom).

Title: Re: Buttons, idles and load screen
Post by: Peegee on Sat 16/10/2021 08:49:35
Hello, in fact I have the 3 characters which are playable. So when I go to my load page, I don't know which one is playable, I put the 3 in transparent and not clickable.

  I will try to put the savegameslot last but I have a guy doing something at the very beginning, so I have to put it back every time ...

I will put the faceCharacter in the changeRoom. I'll keep you posted.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Sat 16/10/2021 09:24:15
Here is the simplified version of my room load. The variable is present so that it only saves the first time. Below is the code to start the backup. I don't have a conflict, if I don't put the ChangeRoom back, it won't start the reload. Currently, the movements between level 1 and the load page work, regardless of the character selected. The problem is always that he doesn't reinitialize the characters ...

RoomLoad:

function room_Load()
{
  if (Dec1one==false)
{
  RemoveWalkableArea(2);
  oFleur2.Clickable=false;


  cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163, eDirectionDown);
 
  cPatate.ChangeRoom(1,246, 229);
  cGamin1.ChangeRoom(1, 134, 431);

  Dec1one=true;

  SaveGameSlot(1, "room 1 initial state");
   

}
else if (Dec1one==true)
{
   RemoveWalkableArea(2);
   oFleur2.Clickable=false;

   cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
   cGob3.ChangeRoom(1, 89, 163, eDirectionDown);
 
  cPatate.ChangeRoom(1,246, 229);
  cGamin1.ChangeRoom(1, 134, 431);
   
}
}

Load:

function oDec01_Interact()
{
  ResetRoom(1);
 
  cGob1.SetAsPlayer();
 
  cGob1.Transparency=0;
  cGob2.Transparency=0;
  cGob3.Transparency=0;
 
  cGob1.ChangeRoom(1, 129, 171, eDirectionDown);
  cGob2.ChangeRoom(1, 171, 166, eDirectionDown);
  cGob3.ChangeRoom(1, 89, 163, eDirectionDown);

   cGob1.Clickable=true;
   cGob2.Clickable=true;
   cGob3.Clickable=true;


}
Title: Re: Buttons, idles and load screen
Post by: Cassiebsg on Sat 16/10/2021 10:01:57
If you only want to save the first time, you could try adding the save to First time player enters room function.
I'm not sure where you are coming from before you start the room (another room?). If you have another room to start the game and have the start menu, then you can just select all those Goblings and player character in the start menu room, and then you can safely save when you start the new room.

"NOTE: You cannot reset the current room (i.e. the room that the player is in)."

So if you already are in room 1, you can't reset it. Meaning that you do need to be in another room to run the Reset.

>> cGob1.ChangeRoom(1, 129, 171, eDirectionDown);

Since you have set cGob1 to be the player character before, this line should be last in your code. It doesn't really affect the way you wrote it, because AGS will still run it last, but for understanding what is happening and how the code is run, you should always write the code in the correct running order, so you don't have surprises later on when the game doesn't run the way you expect it to.

Image now if AGS didn't run this line last and run it in the order your wrote it... the moment this line was executed the player would change rooms and thus all lines afterwards would not be run. And you would be wondering where the other 2 goblins were and why you couldn't click on the one you did have.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Sat 16/10/2021 11:39:40
Quote from: Peegee on Sat 16/10/2021 08:49:35
Hello, in fact I have the 3 characters which are playable. So when I go to my load page, I don't know which one is playable, I put the 3 in transparent and not clickable.

AGS has a "player" word, which refers to the current player character. So, when you write a generic code that may be used for any character, you just do, for example:
Code (ags) Select

player.Transparency=0;
Title: Re: Buttons, idles and load screen
Post by: Peegee on Sat 16/10/2021 12:56:05
Ooh
Title: Re: Buttons, idles and load screen
Post by: Peegee on Sat 16/10/2021 13:14: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?
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Sat 16/10/2021 14:10:16
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
Title: Re: Buttons, idles and load screen
Post by: Peegee on Sun 17/10/2021 07:48:04
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);
-----------------------------------------------------------------------------

Title: Re: Buttons, idles and load screen
Post by: Cassiebsg on Sun 17/10/2021 10:22:14
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) Select

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

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

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

Title: Re: Buttons, idles and load screen
Post by: Khris on Mon 18/10/2021 16:20:44
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.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Mon 18/10/2021 18:16:12
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.

;)
Title: Re: Buttons, idles and load screen
Post by: Cassiebsg on Mon 18/10/2021 23:18:22
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.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Fri 22/10/2021 07:41:34
Ok, great, with that I can manage. Thanks    PG
Title: Re: Buttons, idles and load screen
Post by: Peegee on Fri 22/10/2021 10:15:15
Hello. Indeed, in my loading room, the inventory is displayed anyway, even with the function:

gInventoryBar.Visible = false;

I am using BASS initially.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Fri 22/10/2021 15:22:39
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?
Title: Re: Buttons, idles and load screen
Post by: Cassiebsg on Fri 22/10/2021 15:51:31
I'm not sure what you mean by "sub-level".

But
Code (ags) Select

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

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

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.  ;)
Title: Re: Buttons, idles and load screen
Post by: Peegee on Sat 23/10/2021 08:12:45
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) Select


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

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


Title: Re: Buttons, idles and load screen
Post by: Cassiebsg on Sat 23/10/2021 22:00:27
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) Select

if (Gob2Haut==true) // do stuff
else // do other stuff
Title: Re: Buttons, idles and load screen
Post by: Peegee on Mon 25/10/2021 08:35:11
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.
Title: Re: Buttons, idles and load screen
Post by: Khris on Mon 25/10/2021 09:04:02
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.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 17:21:30
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.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Wed 03/11/2021 17:27:40
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.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 17:42:57
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.
Title: Re: Buttons, idles and load screen
Post by: Khris on Wed 03/11/2021 17:44:14
You can; exit the editor and rename the room files.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Wed 03/11/2021 18:05:47
Quote from: Peegee on Wed 03/11/2021 17:42:57
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).

I'm sorry, I don't understand, what throws what in "After fade in"?... where in script exactly do you call ResetRoom?

Quote from: Khris on Wed 03/11/2021 17:44:14
You can; exit the editor and rename the room files.

You have to enter the room number in the room properties. Renaming room file on disk will make editor not find it next time, because it has room numbers written in the project file also.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 18:06:51
I cannot reset rooms every time I enter them because sometimes I enter a room which must have kept its previous state.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Wed 03/11/2021 18:22:41
I just quickly tested ResetRoom in AGS 3.5.1, and it appears working. There might be something else in your case that meddles with things. Maybe it never gets called, or there's something in room's script that changes object positions (just a guess)?

Quote from: Peegee on Wed 03/11/2021 17:42:57
neither the variables, nor the positions of characters or objects

Please note that only "room objects" are reset by ResetRoom. Characters are global objects and do not change their states. Also global variables are not changed, because they don't belong to particular room.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 18:23:11
I am in room1, I do some actions, then I go to a special room where I have items to start the save. There I put "player.ChangeRoom (1)" to go to the room and I put ResetRoom (1), I come back to my room1 but it didn't reset anything.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Wed 03/11/2021 18:24:20
Quote from: Peegee on Wed 03/11/2021 18:23:11
I am in room1, I do some actions, then I go to a special room where I have items to start the save. There I put "player.ChangeRoom (1)" to go to the room and I put ResetRoom (1), I come back to my room1 but it didn't reset anything.

Please tell, what do you have in room 1 that needs to be reset?
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 18:25:45
... so how can we do a full backup?
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Wed 03/11/2021 18:29:35
Quote from: Peegee on Wed 03/11/2021 18:25:45
... so how can we do a full backup?

Write a function in the room script that sets everything to their starting positions. Call it from "Before fade-in" event, for example, checking if certain global variable is set. Set that global variable whenever you need to reset the room.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 18:30:10
I need to reset several characters their states, their location, the state of the inventory, the objects that I have picked up, or not, all the variables ... I don't understand that it is so complicated. I can also do the backup "by hand", listing everything I want to reset, but I have very rich levels and it can be complex and problematic.
Title: Re: Buttons, idles and load screen
Post by: Crimson Wizard on Wed 03/11/2021 18:35:55
Quote from: Peegee on Wed 03/11/2021 18:30:10
I need to reset several characters their states, their location, the state of the inventory, the objects that I have picked up, or not, all the variables ... I don't understand that it is so complicated. I can also do the backup "by hand", listing everything I want to reset, but I have very rich levels and it can be complex and problematic.

Yes, you would have to do this by hand, there's no other way, because in AGS characters and inventory items do not belong to the room, but to the "global" state. And it does not let to reset only the part of the global state automatically.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Wed 03/11/2021 18:53:30
Ok Crimson Wizard, thanks for your help. I will do like that, but I apprehend and I protest !
Title: Re: Buttons, idles and load screen
Post by: Khris on Thu 04/11/2021 10:52:11
Nobody cares.
If you can't figure out how to do this with save games / non-saving rooms, you need to do it manually.
Title: Re: Buttons, idles and load screen
Post by: Peegee on Mon 15/11/2021 14:18:54
(it was a joke)
Yes finally I do almost the reset by hand, in the room load, but I still put ResetRoom, to reset objects, sometimes more problematic. I have currently resolved my backup issues, including double level issues. Regards