Jibble

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

Buttons, idles and load screen
« on: 11 Oct 2021, 14:57 »
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.

Re: Buttons, idles and load screen
« Reply #1 on: 11 Oct 2021, 15:27 »
Hello.

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.

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.

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.
« Last Edit: 11 Oct 2021, 15:29 by Crimson Wizard »

Re: Buttons, idles and load screen
« Reply #2 on: 12 Oct 2021, 07:51 »
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

Re: Buttons, idles and load screen
« Reply #3 on: 12 Oct 2021, 08:13 »
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"?

How to move the character instantly?

Characters have "x" and "y" properties, so you do simply
Code: Adventure Game Studio
  1. cChar1.x = 100;
  2. cChar1.y = 200;
  3.  
or
Code: Adventure Game Studio
  1. player.x = 100;
  2. player.y = 200;
  3.  
for simplicity if it's a player character.

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

Re: Buttons, idles and load screen
« Reply #4 on: 12 Oct 2021, 08:20 »
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: Adventure Game Studio
  1.   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: Adventure Game Studio
  1.   cNpc.x = 123;
  2.   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.

Re: Buttons, idles and load screen
« Reply #5 on: 12 Oct 2021, 09:36 »
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

Re: Buttons, idles and load screen
« Reply #6 on: 12 Oct 2021, 10:56 »
Characters have a .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.

Re: Buttons, idles and load screen
« Reply #7 on: 13 Oct 2021, 11:24 »
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

Re: Buttons, idles and load screen
« Reply #8 on: 13 Oct 2021, 13:02 »
You can change the baseline at any time during the game:
Code: Adventure Game Studio
  1.   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: Adventure Game Studio
  1. function room_Load() {
  2.   SaveGameSlot(101, "room x initial state");
  3. }

To reset the room, call
Code: Adventure Game Studio
  1.   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.

Re: Buttons, idles and load screen
« Reply #9 on: 14 Oct 2021, 09:32 »
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?

Re: Buttons, idles and load screen
« Reply #10 on: 14 Oct 2021, 09:47 »
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
« Last Edit: 14 Oct 2021, 10:20 by Peegee »

Re: Buttons, idles and load screen
« Reply #11 on: 14 Oct 2021, 09:53 »
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: Adventure Game Studio
  1. function hSuite2_AnyClick() {
  2.   // stop music and load room #1
  3.   aZik01.Stop();
  4.   player.ChangeRoom(1, 246, 229);
  5. }

Now set up the room's initial state and queue saving it
Code: Adventure Game Studio
  1. function room_Load() {
  2.  
  3.   // hide player character
  4.   player.Transparency = 0;
  5.  
  6.   // position other characters in current room
  7.   cGob1.ChangeRoom(player.Room, 129, 171, eDirectionDown);
  8.   cGob2.ChangeRoom(player.Room, 171, 166);
  9.   cGob3.ChangeRoom(player.Room, 89, 163);
  10.  
  11.   SaveGameSlot(1, "room 1 initial state");
  12.  
  13. }

Re: Buttons, idles and load screen
« Reply #12 on: 14 Oct 2021, 11:14 »
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
« Last Edit: 14 Oct 2021, 12:04 by Peegee »

Re: Buttons, idles and load screen
« Reply #13 on: 14 Oct 2021, 11:52 »
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.

Re: Buttons, idles and load screen
« Reply #14 on: 15 Oct 2021, 08:57 »
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);
}
}
}

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 #15 on: 15 Oct 2021, 17:55 »
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).

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

Re: Buttons, idles and load screen
« Reply #16 on: 16 Oct 2021, 08:49 »
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.

Re: Buttons, idles and load screen
« Reply #17 on: 16 Oct 2021, 09:24 »
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;
 

}

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 #18 on: 16 Oct 2021, 10:01 »
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.
There are those who believe that life here began out there...

Re: Buttons, idles and load screen
« Reply #19 on: 16 Oct 2021, 11:39 »
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: Adventure Game Studio
  1. player.Transparency=0;
  2.  

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 »

Re: Buttons, idles and load screen
« Reply #40 on: 03 Nov 2021, 18:05 »
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?

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.
« Last Edit: 03 Nov 2021, 18:08 by Crimson Wizard »

Re: Buttons, idles and load screen
« Reply #41 on: 03 Nov 2021, 18:06 »
I cannot reset rooms every time I enter them because sometimes I enter a room which must have kept its previous state.

Re: Buttons, idles and load screen
« Reply #42 on: 03 Nov 2021, 18:22 »
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)?

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.

Re: Buttons, idles and load screen
« Reply #43 on: 03 Nov 2021, 18:23 »
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.

Re: Buttons, idles and load screen
« Reply #44 on: 03 Nov 2021, 18:24 »
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?

Re: Buttons, idles and load screen
« Reply #45 on: 03 Nov 2021, 18:25 »
... so how can we do a full backup?

Re: Buttons, idles and load screen
« Reply #46 on: 03 Nov 2021, 18:29 »
... 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.

Re: Buttons, idles and load screen
« Reply #47 on: 03 Nov 2021, 18:30 »
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.

Re: Buttons, idles and load screen
« Reply #48 on: 03 Nov 2021, 18:35 »
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.
« Last Edit: 03 Nov 2021, 18:37 by Crimson Wizard »

Re: Buttons, idles and load screen
« Reply #49 on: 03 Nov 2021, 18:53 »
Ok Crimson Wizard, thanks for your help. I will do like that, but I apprehend and I protest !

Re: Buttons, idles and load screen
« Reply #50 on: 04 Nov 2021, 10:52 »
Nobody cares.
If you can't figure out how to do this with save games / non-saving rooms, you need to do it manually.
« Last Edit: 04 Nov 2021, 11:02 by Khris »

Re: Buttons, idles and load screen
« Reply #51 on: 15 Nov 2021, 14:18 »
(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