Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: katie08cd on Sat 18/01/2020 21:06:15

Title: ANALOG CLOCK
Post by: katie08cd on Sat 18/01/2020 21:06:15
hello everyone is it possible to create an analog clock in the game? that goes on its own without blocking anything, and that during a certain animation, you can give the command to change the background or props? thanks, in the meantime I created a characters clock with a 12-frame loop, only that anyway the animation starts but it ends and then if I send it to other rooms the animation starts again, instead I would like it to be a fake clock but with 12 hours, in fact I created 12 frames for this, I would like to find a solution thanks

ciao a tutti e possibile creare un orologio analogico nel gioco? che vada per conto suo senza bloccare nulla, e che poi durante una certa animazione, puoi dare il comando di cambiare sfondo oppure oggetti di scena? grazie, nel frattempo mi sono creata un orologio characters con loop di 12 frame, solo che comunque mi parte l'animazione ma finisce e poi se lo mando in altre stanze riparte da capo l'animazione, io invece vorrei come se fosse un orologio finto ma con 12 ore, infatti ho creato 12 frame per questo, vorrei trovare una soluzione grazie

(https://i.ibb.co/qm2BR6t/2020-01-18-214755.png) (https://ibb.co/nQKrDpH)
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Sat 18/01/2020 21:56:23
Short answer: Yes.

Now hos exactly does this watch move?
1)  Does it run on real time? 1hour of game running = 1 hour in game has passed?
2)  Does it change at a given setting? Like if you do task 1 and 2, the time moves 1 hour, then task 3 & 4 makes the timer move another hour...
3) Another scenario?

So first explain exactly how your clock should work, then we can give you solution (or even code) on how to solve the task at hand.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Sat 18/01/2020 23:00:48
hello thanks for the answer, no it does not work in real time, the time then I decide it according to the mission but I believe 6 hours of real game = one day in the game, the timer always moves one hour in the game, the but idea is that the game starts on October 1, 1898 at 9 in the morning, so if I calculate in the right way after 30 minutes, 10 will start, etc. of sunset, while if it is 5 in the morning the background of dawn comes out, even when I use the carriage to go to a place it must change animation of the landscape from day to night, then for bad weather that is decided throughout history,

yes I would like to create the code with the analog clock skin as seen in the photo if possible, thanks, if you want I will send you the files with the animation if you want to try, the game starts at 9 in the morning
Title: Re: ANALOG CLOCK
Post by: fernewelten on Sat 18/01/2020 23:37:03
You can have a function called "repeatedly_execute_always" that will be called 40 times ("ticks") per second, no matter what. It goes into the GlobalScript script (the Script, not the header). Just put the following near the end of that file to define it:
"function repeatedly_execute_always()
{
}"

In the editor, define an int variable in "Global Variables" (look for that section in the upper right pane of the editor).

In repeatedly_execute_always() increment this new variable. In order to prevent overflow, set the variable to 0 as soon as it has reached the ticks of a whole day.

In repeatedly_execute_always(), whenever your variable has reached the appropriate values, change the appearance of your room appropriately. If this entails changing objects, then this will become a big hassle since GlobalScript does not know the object names of your room. In this case, do "CallRoomScript(0)" whenever the room needs to be changed, and in your room script, define a function "on_call" near the end. This function will then be called whenever your global script calls CallRoomScript(), so you can handle things from there.

To be more specific, do something like the following near the end of your room script:
"function on_call(int what)
{
    if (0 == what)
    { ... change the appearance of the room ... }
}"

You can use the same mechanism to change the clock face:
1. In "repeatedly_execute_always", determine whether the clock face needs to be changed now; if so, call "CallRoomScript(1)".
2. In your room script, in function "on_call", add code such as
"   if (1 == what)
    { ... determine the sprite number that your clock should show ...
        YourClock.Graphic = the_right_sprite_number;
    }"

Whenever your character enters a new room, then its appearance must be changed to match the time of day. The easiest way to do this is to define the event "Enters room before fade-in" for the room and see to it that the corresponding function is _below_ the function "on_call()" in the room script. Then, simply do "on_call(0);" in the function for "Enters room before fade-in". This will guarantee that "on_call(0)" will be called whenever the player enters the room, before the room is shown yet.

In the same vein, to guarantee that the wall clock shows the right time when the player enters the room, do "on_call(1);" in the function for "Enters room before fade-in".

Hope those pointers help. If you need further details, feel free to ask.
Title: Re: ANALOG CLOCK
Post by: Crimson Wizard on Sun 19/01/2020 00:41:35
Quote from: fernewelten on Sat 18/01/2020 23:37:03
You can have a function called "repeatedly_execute_always" that will be called 40 times ("ticks") per second, no matter what.

A little correction: it will be called X times, where X is the value of SetGameSpeed, could be anything from 10 to 1000 in theory.


I can also recommend using GUI instead of room objects, because it's much easier and you don't depend on room, you can share same GUI between several rooms, and update it in global script.

For calculating real time, DateTime script object is much more preferrable (unless you need millisecond precision). DateTime.Now allows you to get and save real current time. If you get DateTime.Now next time, and subtract the saved value, you will get almost exact number of seconds passed since.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Sun 19/01/2020 01:46:28
hi thanks, a question my watch must be a character or a view? however my clock must change time every 20 minutes, the game starts at 9 in the morning, then for example if the sprite of 5 in the morning, I have to change objects like dawn if I am in the city or traveling with the carriage, in the end I just have to calculate 4 scenarios, sunrise, day, sunset, evening, sunrise and sunset are a few minutes, while day and evening last longer, and I have to do all this in 8 hours of real life which result in 24 hours in the game , so every 20 minutes of real time changes an hour in the game and repeats until you finish the chapter, then in the next chapter I start a new time, new assassins, new suspects, etc. etc., maybe I should write a script with 24 voices, sunrise and sunset will be 1 minute each, while day and evening will last, day 280 minutes, evening 200 minutes

01 = 20 minutes
02 = 20
03 = 20
04 = 20
05 = 19 + 1minutes animation sunrise 200 minutes total evening
06 = 20 animation day
07 = 20
08 = 20
09 = 20
10 = 20
11 = 20
12 = 20
13 = 20
14 = 20
15 = 20
16 = 20
17 = 20
18 = 20
19 = 19 + 1minutes animation sunset 280 minutes total day
20 = 20 animation evening
21 = 20
22 = 20
23 = 20
00 = 20

I forgot, obviously in every room of the house or building or in the street, the clock runs normally, while if the character selects a point at the destination, such as going to the police or the crime scene, I should calculate them the theoretical time of 1 hour or 2, since I use a carriage with horses (1898) the game takes place
Title: Re: ANALOG CLOCK
Post by: katie08cd on Sun 19/01/2020 11:17:51
thank you for the advice, but unfortunately for me the program is in English, so I have to translate what you say with google translate (and the translation is not always right), then I have to try and try again until I get a result, thanks again everyone
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Sun 19/01/2020 12:47:32
To display the clock use a GUI, no need for characters or views. Just change the sprite of the clock when the timer reaches 20 (or corresponding value of Game Speed). Do the same to change background or set other events in march.

Try and try again, is also a valid way to reach the solution.  (nod)

Decide what is important to keep track of: day? hour? minute? sec?
If you only keep track of seconds, then your variable value will be a big number, which means it's probably easier to keep track of the others, and just reset (like a watch adds a 1 to the next value and resets to zero the current value). This will make it easier for you to keep track, and write if/if else/else clauses that make sense to you.

Title: Re: ANALOG CLOCK
Post by: katie08cd on Sun 19/01/2020 14:02:48
I have to create a GUI, with the clock button and inside put a script to change the frame, right? and which variable I should use I am not so expert, if in the game I start the GUI (excellent solution by the way because it is safe until I do .visible = false will be displayed) but how can I set that every 20 minutes of real time it moves one frame at a time, and in that frame for example 5 o'clock in the morning, it displays the object 0, because then I have to set my method 4 primary objects for each room, for example
object 0 dawn
object 1 day
object 2 sunset
object 3 evening

in each room I have to put 4 primary objects in such a way that I create a nice day-change effect in the game

great idea the GUI thanks, now I need a way to create the script, if you can give me an example of how to create it,

in my opinion the GUI gOro24, must use 26 continuous loop frames of about 20 minutes, also if the frame moves to the hours, it must follow this pattern

frames / minutes / objects
frame 10 = 9 in the morning
object 0 disable, dawn
object 1 true, day
object 2 disable, sunset
object 3 disable, evening


01 = 20 minutes = object 3 evening
02 = 20 minutes = object 3 evening
03 = 20 minutes = object 3 evening
04 = 20 minutes = object 3 evening
05 = 20 minutes = object 3 evening
06 = 1 minute = object 0 dawn
07 = 19 minutes = object 1 day
08 = 20 minutes = object 1 day
09 = 20 minutes = object 1 day
10 = 20 minutes = object 1 day
11 = 20 minutes = object 1 day
12 = 20 minutes = object 1 day
13 = 20 minutes = object 1 day
14 = 20 minutes = object 1 day
15 = 20 minutes = object 1 day
16 = 20 minutes = object 1 day
17 = 20 minutes = object 1 day
18 = 20 minutes = object 1 day
19 = 20 minutes = object 1 day
20 = 1 minute = object 2 sunset
21 = 19 minutes = object 3 evening
22 = 20 minutes = object 3 evening
23 = 20 minutes = object 3 evening
24 = 20 minutes = object 3 evening
25 = 20 minutes = object 3 evening
26 = 20 minutes = object 3 evening
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Sun 19/01/2020 16:28:14
You don't need an object to for each period of the day.
Also you have 2 different things in here. One is making the watch and keeping track of time. Another is changing the visual of your BGs to show of day/night cycle.

Concentrate on making the watch first, since you'll need the variables of time to decide when to do your BG change.

First make the GUI and use your  Clock at 00:00 sprite image as the BG.  open Global Variables (the one with a blue globe icon in the project tree). Now right click on an empty place and choose "add new variable...", give it a name like intSecunds. Leave it at int and set the default value to 0. Repeat for intMinutes, intHour & intDay (if you need to keep track of which day it is). You can change the variable names as you see fit. Also they don't all need to default at 00, so if yor game starts at 07:34, then just default Hour to 7 and minute to 34. ;)

now, locate in Global Scripts -> repeatedly_execute_always()

and then add the code to keep track of time:
Code (ags) Select

intSecunds++;
if (intSecunds*GetGameSpeed()==2400)
{
player.SayBackground("1 sec"); // for debugging, delete or comment out with //
intSecunds=0;
intMinute++;
if (intMinute==60)
{
intMinute=0;
intHour++;
gClock.BackgroundGraphic=Clock00+intHour; // Clock00 is sprite number that corresponds your clock at 00:00 (I'm assuming they have been imported sequencially and in the right order)
if (intHour==24)
{
intHour=0;
intDay++;
        gClock.BackgroundGraphic=Clock00; // Clock00 is sprite number that corresponds your clock at 00:00
}
}
}


I'm not saying this is the only way to do it, and have no idea if I forgot anything in here. But I would go with something like this.


Don't have the time right now to give you code to change the game's BG.





Title: Re: ANALOG CLOCK
Post by: Snarky on Sun 19/01/2020 20:34:19
You could also check out my Day/Night module (https://www.adventuregamestudio.co.uk/forums/index.php?topic=49791.0) to keep track of the time.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Mon 20/01/2020 14:22:06
wow, hello thank you, as soon as I fix my AGS I try immediately, I'm remaking the game again because I changed a main room and now some chars don't go anymore, and then in the game I found various functions so better to start again with code clean, however I did not understand the part of the frame, in the sense that I did not understand how to create frames within a GUI, I can change the background and add a button, but I am missing the fact of how to add other frames, but you have you already tried everything? does it work can you create a small executable? Thanks for your patience :)
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Mon 20/01/2020 14:32:49
Line 11 on my code is how you change the clock sprite.

No idea what you mean by "frame".
Title: Re: ANALOG CLOCK
Post by: katie08cd on Mon 20/01/2020 18:34:26
that I can't make an animated sequence in GUI, right? because my watch, at 26 frames, or maybe it can be done but I have never tried it
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Mon 20/01/2020 19:05:40
How exactly do you want to animate the clock?
From what I understood of what you wrote, the clock changed only at every hour, if it's running on full time like a real clock, then you'll need a lot more sprites (or animate the pointers). Otherwise just do what I told you do to or use Snarky's module.

If you need to use a view for animation, use a button (I can't recall if the background can be assigned a view, but think it's not). Make a button, then assign the view to that button and it will animate.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Mon 20/01/2020 23:15:43
hello thanks for replying, then I apologize because I understood to create a GUI and inside that gui to put the clock frames (which are 26) but I realized that you cannot import frames in the gui, so I ask , to use your code what do I have to create to make animation? a character, an object, what is created to animate, sorry for my ignorance on this issue :)
Title: Re: ANALOG CLOCK
Post by: Crimson Wizard on Mon 20/01/2020 23:37:05
Quote from: katie08cd on Mon 20/01/2020 23:15:43
hello thanks for replying, then I apologize because I understood to create a GUI and inside that gui to put the clock frames (which are 26) but I realized that you cannot import frames in the gui, so I ask , to use your code what do I have to create to make animation? a character, an object, what is created to animate, sorry for my ignorance on this issue :)

You can add sprite on GUI, there's a property called BackgroundGraphic. You can also make a Button on GUI and add image to this button, using property called NormalGraphic.
Both GUI's background graphic, and button's graphic can be changed anytime in script.

In AGS you can also set whole animation to the object, using Views, but you do that if you want continious animation (the animation that runs all the time on screen), but that's not what you need probably for this clock.
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Mon 20/01/2020 23:45:02
I'm not animating anything. I'm just replacing the clock sprite (image) with the next one.
You say in your first post that you have "created a characters clock with a 12-frame loop". So I'm assuming that you want to show only the hours and change the hour every time the hour has changed. So that the player can see what the current hour he's playing.

But now you're talking about a 26 frames animation...  ???

If you only need to show a single image (no animation!) and change the image every game hour, the set the first sprite to your clock 00 as the GUI image background.

If you want to animate it somehow, you will need to create a button, add the image of the first sprite to your clock 00 as the normal button image (note that you can also use this option for a single image with no animation).

CW beat me to the answer. :)
Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 00:14:19
first of all thank you both for the answers, you are very kind, thank you thank you, I did not know that you could change frames for this I am in difficulty, now in the photo I have created a transparent gclock GUI, with the frame button 00 in it (0 : 00) now if I want to create a simple thing like, I enter the room, a time starts that after 20 minutes of play, must change the frame, what command should I use for this? then the same command must be repeated 24 times, (to create a clock effect animation) and continuous cycle, I don't have to do anything complicated but just to understand how it works, that at a certain time it can change frames, thanks

(https://i.ibb.co/fHrDThz/2020-01-21-010249.png) (https://ibb.co/0rYszgR)

per prima cosa vi ringrazio entrambi per le risposte, siete molto gentili, grazie grazie, non sapevo che si poteva cambiare frame per questo mi trovo in difficoltà , ora in foto ho creato una GUI gclock trasparente, con dentro il pulsante del frame 00 (0:00) adesso se voglio creare una cosa semplice del tipo, entro nella stanza, parte un orario che dopo 20 minuti di gioco, deve cambiare il frame, che comando devo usare per questo? poi lo stesso comando va ripetuto 24 volte, (per creare una animazione di effetto orologio) e ciclo continuo, non devo fare nulla di complicato ma tanto per capire come funziona, che ad un determinato tempo possa cambiare frame, grazie
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Tue 21/01/2020 11:25:13
Code (ags) Select

function repeatedly_execute_always() // locate this in GlobalScript
{
  intSecunds++;
  if (intSecunds*GetGameSpeed()==2400)
  {
    intSecunds=0;
    intMinute++;
    if (intMinute==20) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).
    {
        intMinute=0;
        intHour++;
        Bclock.NormalGraphic=88+intHour; // 88 is sprite number that corresponds your clock at 00:00 (note that this only works if 89 is hour 01:00, and 90 is 02:00, etc)
        if (intHour==12 && intHour==24)
        {
          Bclock.NormalGraphic=88; // this resets the clock image to 00:00
          if (intHour==24)
          {
          intHour=0;
          intDay++;
          }
       }
    }
  }
}


Setting the day/night cycle is slightly more complicated. Does your clock show 06:01 ? If not and you just want the BG to show Dawn animation at this time, it's easier. Otherwise I recommend you might want to change the sprite numbers to make it easier when coding.
Let's say that you import all your clocks sprites in order....
Sprite number = clock hour
88 = 00:00
89 = 01:00
90 = 02:00
91 = 03:00
92 = 04:00
93 = 05:00
94= 06:00
95 = 06:01 (Dawn) // would it keep showing 6:01? <--- This situation would mess up the clock, showing the correct hour in my code. My suggestion would be to move it to another number. So that 95 = 07:00 and so on...

If what you want is to show an animation at 6:01 in your room changing from night to dawn to day, then all is needed is to add an if check in the minutes section of the code and keep track of the hour and minute, when  it matches you just tell it to animate and do the changes needed to the room.

If you want the clock to animate then just use
bclock.Animate(view); //where view is the view number or name (all caps). Place this line right after gClock.Visible=True.

I can try and explain in Portuguese, if you think you'll get a better match in the translation, considering Portuguese and Italian match in grammar and derive both from Latin.
Posso tentar explicar em Português, se tu achares que a tradução é melhor, tendo em consideração que Português e Italiano têm a gramática em comum e derivam ambas do Latim.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 15:26:36
hello, thanks for the answer, then let's start over, a simple thing for you, use the animated command that from how as you can see in the picture does not work because I'm wrong something,
gclock = gui
bclock = button gui gclock
clock24 is view animated
what am i wrong with this command ?, what should i write exactly, then first i was trying your script but by mistake i then send you the photo, of your script i created 4 int in global variabiles and copied your script, on function repeatedly_execute_always ()
only that later he gave me an error at this point

GlobalScript.asc(128): Error (line 128): Nested functions not supported (you may have forgotten a closing brace)

// Called when a dialog script line "run-script" is processed
function dialog_request (int param)
{
}

thanks anyway :)

(https://i.ibb.co/ZTfRzhs/2020-01-21-161854.png) (https://imgbb.com/)

(https://i.ibb.co/fMSWHdL/2020-01-21-163544.png) (https://imgbb.com/)

(https://i.ibb.co/RcdMqzF/2020-01-21-163622.png) (https://imgbb.com/)
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Tue 21/01/2020 17:13:16
From the manual: Button.Animate(int view, int loop, int delay, RepeatStyle)

So you probably want something like: Bclock.Animate(CLOCK24, 0, 10, eRepeat); (where 10 is the speed the animation will run, and eRepeat to make it animate constantly)

About the last one, it tells you exactly what is wrong. You forgot a } (closing brace).
Now, you don't show your code and cut it, but I can see that there's a dotted line behind 123 that has no closing } bellow it. Try adding a line between line 123 and 124 and add a } under the dotted vertical line.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 18:09:06
yeep, small steps, the clock works, how do i calculate the delays? is there by chance a delay converter for seconds or minutes? , now that it finally works I can interact, now if from this animation I would like to make a similar sequence,

gClock.Visible = true;
    Bclock.Animate (CLOCK24, 0, 10, eRepeat);
10 speed = I want to change it in 20 minutes

after I try again your script, thank you very much
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Tue 21/01/2020 19:11:16
uhm... number too big that my mind explodes.  Math is not my forte...


My script "manually" animates your clock every 20 minutes.
So it does exactly what you want to do with the animation (Meaning you don't need to animate the button it at all! as I'm manually changing it at the appropriate time).
Note that if you are animating the clock, changing the clocks normalGraphic will likely not work. Since there's a warning about it in the manual. My advice is: forget animating the clock. That's not really what you want, when we talk about animating is something that will run a quick/short animation sequence once or keep repeating it.
Delete or comment out the Bclock.animate command, and go with the code.


Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 20:01:43
ok I solved your script, it just doesn't move, I even changed the number of frames, seconds, minutes, but nothing doesn't change, what escapes me to make it work? is not that maybe you have to set the script on the view for it to work?
Bclock24.NormalGraphic intHour + = 77;
77 and to test if it moves because with 88 it stays still
Bclock.Animate (CLOCK24, 0, 30, eRepeat);
with this command animation works but with other AGS, I always make a test copy to try the functions, but unfortunately I see that by mistake if I insert the view, anyway thank you so much with the normalgraphic command (which I didn't know how to use) I can also create the pages for dialogue and much more, thanks again
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Tue 21/01/2020 21:13:45
Please copy paste the entire function.  :-\
Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 21:19:37
ok I tried with delays, and I did some tests
40 = 1 sec
2400 = 1 min
12000 = 5 min
36000 = 15 min
48000 = 20 min
unfortunately though if I put 33000 delay, the clock goes crazy it runs very fast, so I assume there is a limit also in the delay
32000 = 13 min> the maximum limit of 13 minutes
Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 21:22:14

function repeatedly_execute_always()
{
  //intSecunds++;
  if (intSecunds*GetGameSpeed()==2400)
  {
    intSecunds=0;
    intMinute++;
    if (intMinute==1) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).
    {
        intMinute=0;
        intHour++;
        Bclock24.NormalGraphic=88+intHour;
        if (intHour==12 && intHour==24)
        {
          Bclock24.NormalGraphic=00; // this resets the clock image to 00:00
          if (intHour==0)
          {
          intHour=0;
          intDay++;
          }
        }
    }
  }
 
}
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Tue 21/01/2020 22:19:53
 //intSecunds++; <-- this is commented out. That's why the clock isn't running. Remove the // from it

Also, please wrap your code here in the forum with the [ code] [ /code] tags, or copy/paste and then select/highlight your code and choose the # button.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Tue 21/01/2020 22:46:13
ok it works but I notice two problems
if (intMinute == 1) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).

1. is there a second, not a minute, that is normal, or do I have to calculate the seconds by minutes?

2. no it resets to the frame continues indefinitely showing me other images of the game, as if there was no stop despite putting the start frame. and the final frame, it seems that it does not find it

Code (ags) Select
intMinute=0;
        intHour++;
        Bclock24.NormalGraphic=77+intHour;
        if (intHour==12 && intHour==24)
        {
          Bclock24.NormalGraphic=80; // this resets the clock image to 00:00
          if (intHour==0)
          {
          intHour=0;
          intDay++;


I also did the test to put only 4 frames
from 77 to 80, but it does not stop it continues showing me all the images of the game

other strange thing, if I put any frame like 77 and in the button is set 77, he starts from 80, so I have to put 75 if I want to see frame 77, strange as what

as always thank you
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Tue 21/01/2020 23:37:24
Please show me the numbers of your clock images. Sprite number.

No.

1. intSecund is keeping track of the seconds that have passed. Once the seconds reach 60 they are reset to 0 and to intMinute is added 1. This keeps repeating, until intMinutes reaches 20 (because you want 1 hour in game to equal 20 minutes in real life time), then IntMinutes gets reset to 0, to intHour it's added 1 and the clock changes to the next sprite.

2. There's in no stop sprite, just the sprite that corresponds to clock at 00:00!

And also, that is not the code I posted before. You have changed it at one point or another, and thus it does not work.  :-\ Please copy/paste my code (https://www.adventuregamestudio.co.uk/forums/index.php?topic=57712.msg636615180#msg636615180) and do not make changes. I have edited my code to add the missing closing bracket.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Wed 22/01/2020 00:26:37
https://drive.google.com/file/d/1jjhytBxb6M14_FVlywSWh7Bsm7HL4Jf3/view

hello, I tried again but nothing, it does not stop continue with all the images, I prepared a copy so at least you can understand, maybe you need a reset or stop variable, I don't know, any frame that I put (even not clock) starts always with 4 frames first, so if in the first frame it says 77, I have to put 74 to start it, and then it does not stop it continues always, thanks again

push inizia, caso 1 to play
sorry for the graphic :)

I also did the test to set the 1 sprite to 12, but it does not stop always continues

        intMinute=0;
        intHour++;
        Bclock24.NormalGraphic=1+intHour; // 88 is sprite number that corresponds your clock at 00:00 (note that this only works if 89 is hour 01:00, and 90 is 02:00, etc)
        if (intHour==12 && intHour==24)
        {
          Bclock24.NormalGraphic=12; // this resets the clock image to 00:00
          if (intHour==24)
          {
          intHour=0;
          intDay++;

Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Wed 22/01/2020 07:26:08
I fixed it, there's a if/else missing to change the sprite number when intHour is bigger than 11, need to subtract 12 to get the correct sprite to show again.
I'll post the fixes (there's more than one) later, as I needed to leave  now.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Wed 22/01/2020 13:36:49
wowww :) thank you, I'm glad you did it, congratulations
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Wed 22/01/2020 14:10:18
Okay, I'm back.

I started by checking the sprite numbers, and the sprite for clock 00:00 was the last one of the series, not the first.
So I started by re-numbering the sprites. They now run from 100 to 111, and 100 is 00:00, 101 is 01:00, etc, up to clock 11:00.
I had to delete the frames on the clock view, but you don't need them anyway.

Here's the remaining changes I did:
Code (ags) Select

function repeatedly_execute_always()
{
  if (gClock.Visible==true)
  {
  intSecunds++;
  if (intSecunds==60*GetGameSpeed())
  {
    intMinute++;
    intSecunds=0;if (intMinute==20) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).
    {
      intHour++;
      intMinute=0;
      if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00
      else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number
      if (intHour==12 || intHour==24)
      {
        Bclock24.NormalGraphic=100; // this resets the clock image to 00:00
        if (intHour==24)
        {
          intHour=0;
          intDay++;
        }
      }
    }
    CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background acording to the clock at game start
    }
   //player.SayBackground(String.Format("%d:%d:%d", intHour, intMinute, intSecunds/GetGameSpeed())); // for debug purpose, player will tell the time
  }
}


I created a new Script in called CustomScripts (use it to add new scripts you wish to call from anywhere in script, and don't want it messed with GlobalScript functions).

Here you find the new function:
Code (ags) Select

void CheckRoomBackground()
{
if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
else if (intHour>=6 && intMinute>=1) SetBackgroundFrame(2); // Day Backgrund
else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
}


And in the Header: import void CheckRoomBackground();

Use this function to set you your room before fade in (as seen in room 40):

Code (ags) Select

function room_Load() // remember to plug this function to room events, just copy/pasting it won't work.
{
CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background according to the clock at game start
}


Also, if you open Room40 and look at the Backgrounds, you'll notice I've added 3 new BGs.
Background 0 (default) is the one you had, which is Evening/Night,
Background 1 is Dawn,
Background 2 is Day,
Background 3 is Sunset.

Note: I don't know what happens if AGS tries to set a Background in a room that only has 1 background. I'm guessing the two options are "Nothing happens or game crashes..."  (roll)

Here's your source back: https://www.mediafire.com/file/vo67divmugtk8sc/orologio.zip/file
Title: Re: ANALOG CLOCK
Post by: katie08cd on Wed 22/01/2020 17:23:11
OMG WOW, when I go to the map to go to the police, you see the background, fantastic * _ *, I made you create a wonderful script, thanks it was what I wanted, but now the game starts at 9 am, so I just have to change it sprites from 00 to 9, and then the change background script that corresponds to the time, thanks again
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Wed 22/01/2020 17:36:28
NONONONO

Just open Global Variables, edit intHour and set the default to 9!
Title: Re: ANALOG CLOCK
Post by: katie08cd on Wed 22/01/2020 18:17:23
ok if I put 9 in global variabiles, the backgrounds go to me like the XD disco strobe effect, they cycle, if I set sprite 109 in the script and the gclock button disappears, because obviously the sprite sequence has changed, so what should I change to to start the game at 9? if I change the sprites the sequence is correct because it is set to 12 sprites, and those remain, the sprite 00 becomes 9 etc., and continues the cycle, the problem and the backgrounds change, now in this script the 6 is set as a time, or number of sprites? because in this way I could change it just tell him where the sprite 6 is located etc, thanks anyway I really like the script

Code (ags) Select
if ((intHour <6) || (intHour> = 19 && intMinute> = 1)) SetBackgroundFrame (0); // Night Background
else if (intHour == 6 && intMinute == 0) SetBackgroundFrame (1); // Dawn Background
else if (intHour> = 6 && intMinute> = 1) SetBackgroundFrame (2); // Day Backgrund
else if (intHour == 19 && intMinute == 0) SetBackgroundFrame (3); // Sunset Background
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Wed 22/01/2020 18:59:08
That is not sprite number, it's hour.  :~(
Title: Re: ANALOG CLOCK
Post by: katie08cd on Wed 22/01/2020 19:14:45
yes I noticed, but how come if I set it to 9 in global variabiles, the backgrounds cycle me? and then I was weighing if instead of the script with the background change, they put something like if sprite 109 changes bacground 1, can we do it? do you think so we can solve the problem, because it is fantastic but my office in the game opens at 9 am XD, as always thank you very much, another thing I noticed that I no longer see the dark around the icons (before it was gray if I went to hotspots etc, what command did you use or setting to make sure that you don't see the grayness between the icons, thanks

(https://i.ibb.co/c1CkymX/2020-01-22-201212.png) (https://ibb.co/rmcFQWf)

Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Wed 22/01/2020 19:43:33
I forgot to mention I changed the greyout commands. It's changed in settings "When player interface is disabled, GUIs should". I just set it to Normal, as I I don't like the greyed out that is default to Sierra template. And it made the clock look weird.

Oh, I see. this is what happens when I code and don't test all options.  :-[
Give a me sec to figure out.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Wed 22/01/2020 19:50:52
I did the test, if I set the global at 9 it makes me the background cycle, if instead I put at 6, nothing happens
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Wed 22/01/2020 20:13:45
I found the problems,
- The first is that my check for hour was looking for a specific time, that would never be.
- The second wass that the first "check" for the clock come only after the clock reached the first hour, so the clock would show 00 and then jump to 10 after the first hour.

So I fixed it, it now. I'll try and explain how you can fix it (it's just copy/paste & replace in the right place).

Open CustomScripts Script and copy/paste the following code (replace all the lines in the script):
Code (ags) Select

// new module script

void AdjustClock()
{
  if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00
  else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number
}

void CheckRoomBackground()
{
  if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  else if (intHour>=6) SetBackgroundFrame(2); // Day Backgrund
  else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
}


Now open CustomScripts Header and copy/paste the following code:
Code (ags) Select

import void AdjustClock();



Open GlobalScript and locate the following two lines and replace them with: AdjustClock();
Code (ags) Select

if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00
else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number


Lastly, open Room40 script and add the same line to room_load and it should look like this:
Code (ags) Select

function room_Load()
{
  AdjustClock();
  CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background acording to the clock at game start
}


Note: This last code you should add when you create a new playable room. Also take notice that if other rooms need to start at a specific time, you can just add a line before AdjustClock();, and type intHour=8; this would make that room to start at 8:00.
I'm not sure how you are planing to set the rooms, but if you have a case per room and they all need to start at 9, then just add the intHour=9; code to the room_Load of all your rooms. If not the clock will continue counting from when it stops (I set it to count if it's visible, so remember to turn it off if the player is accessing a GUI like save or settings...)
Title: Re: ANALOG CLOCK
Post by: katie08cd on Thu 23/01/2020 00:10:43
OMG WOOOW, I set at 9 and the day came * _ * fantastic, thank you very much you do me doing school, before I took a cue from your script so I created one for the deduction room, because I practically have a nice long code and global script it bothered me because it still needed space, so I took a cue from your script and I created mine, I'm too happy, I still created a simple thing, in the deduction room I created the inventory, there are words and you have to drag these words on the suspect, the wrong ones turn red and then the display text says "does not match etc" instead for the right one of each category, the label is displayed, the categories that I invented are 5
opportunity
weapon
test
motive
conclusion

when you have these 5 elements you can incriminate the suspect, also if a category of the type (occasion) if it is correct automatically removes you those are not exact

for each category I created 4 wrong elements

does not seem, but I'm very happy that I created a small script (obviously not at the levels of the master XD) but thanks anyway, and if you want to put your script in the downloads, which by the way is a fantastic thing because it makes the game more openworld if we want, put it well maybe other people need it, thanks again for everything

Title: Re: ANALOG CLOCK
Post by: katie08cd on Thu 23/01/2020 16:23:03
hello I'm trying the clock and it makes me a strange thing, if I start the room at 6 pm, when it arrives at 9 pm, it sets the background during the day like 9 am, then at 10 pm the night starts again, maybe it doesn't calculate the 24 hours , then I tried to add another 12 sprites but he doesn't see them, if now I want to make a 24 sprite watch (which I think is more precise) what should I do ?, I did the test again now, if I start at 21 it comes always during the day, then it passes at night but at 10 pm it is day again, I send you a new file with 24 sprites already set from 100 to 123, another thing if in the script you want to make a list of the 24 sprites to associate, go ahead, that then I fix them, (always if possible of course) we set the clock to 24 hours with 24 sprites at least we are sure that it counts those, thank you very much

https://drive.google.com/file/d/14Z4nh9mb9oQGnl7RuGgSjnD8QolYjuvY/view
Title: Re: ANALOG CLOCK
Post by: Matti on Fri 24/01/2020 00:36:15
I haven't followed this thread closely, but I'm not sure about this:

Code (ags) Select
void CheckRoomBackground()
{
  if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  else if (intHour>=6) SetBackgroundFrame(2); // Day Backgrund
  else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
}


I don't really get it, but the last "else if" will never be called.
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Fri 24/01/2020 02:00:33
you're right   :-[ try this...  (roll)

else if (intHour>=6 && intHour<=18) SetBackgroundFrame(2); // Day Backgrund

Code (ags) Select

void CheckRoomBackground()
{
  if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  else if (intHour>=6 && intHour<=18) SetBackgroundFrame(2); // Day Backgrund
  else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
}
Title: Re: ANALOG CLOCK
Post by: Khris on Fri 24/01/2020 09:13:03
Took a look at this, started to make little changes, then some bigger ones :-D

- replaced the clock with a dynamically drawn one
- backgrounds fade into each other now.
- added two functions:  SetClock(int hour, int minute);  and  AdvanceClock(int hour, int minute);
- while debug mode is on, hold down space to advance time really fast

Spoiler
(https://i.imgur.com/Nq5aaxu.png)
6:18 AM, fading from dawn to day
[close]
Download (https://drive.google.com/open?id=1dhLDladrXMRYWKBwGBxBYHo12Jq-zNCO)


Edit: completely OT, but feels necessary to say nonetheless: 800x600 is a really bad choice, given that probably 95% of devices use 16:9 or similar widescreen resolutions now. My monitor is set to Full HD so I can play this either in a relatively small window or with huge black bars on the sides, which is a shame given the beautiful graphics.
I'd consider switching to 1280x720 or 640x360 while you're in the early stages.
Title: Re: ANALOG CLOCK
Post by: Slasher on Fri 24/01/2020 09:44:22
Nice one Khris  (nod)

You should have included a 'Quit' though...



Title: Re: ANALOG CLOCK
Post by: Matti on Fri 24/01/2020 10:58:00
Nice work indeed!

I agree that you should use a different resolution (and that the graphics are beautiful  :)).

@ Slasher: There is a quit button in the menu.
Title: Re: ANALOG CLOCK
Post by: Cassiebsg on Fri 24/01/2020 12:10:17
Cool. :) Take the master to make it better.  :-D
Title: Re: ANALOG CLOCK
Post by: katie08cd on Fri 24/01/2020 12:18:23
hello, thanks for the work, wow and fantastic, ok I understand how to set the clock, thanks,
but unfortunately for this modification I have not given the full version, and I was wondering, is it possible in my map function, yes because the game uses my invention of the map, where you select a place, the carriage comes and takes you to your destination, it is possible to do a time calculation on the map? eg if I leave the office at 9 in the morning and arrive in the place at 11, then I go back to the office, do I always leave from 9? or at 13? thanks, in case of this modification I will send you the whole file, thanks again

I created a new room but it doesn't change the background, do I have to add some commands in fade in, or in the script? thanks, theoretically I asked this works to change the background in each room of the game to have a time effect as you have seen, what command should I use to change the background in each room?
Title: Re: ANALOG CLOCK
Post by: katie08cd on Sat 25/01/2020 12:56:45
the backgrounds in the other rooms don't go, what command do I have to use? thanks

Code (ags) Select
// new module script

#define CLOCK_CENTER_X 40
#define CLOCK_CENTER_Y 40
#define CLOCK_RADIUS_H 25
#define CLOCK_SPRITE_H 29
#define CLOCK_RADIUS_M 30
#define CLOCK_SPRITE_M 30

enum BGFrame {
  eBGNight = 1, eBGDawn = 2, eBGDay = 3, eBGDusk = 4
};

int seconds, minutes;
int hour, minute;

void DrawImageAA(this DrawingSurface*, int x, int y, int slot) {
  this.DrawImage(x - 1, y, slot, 80);
  this.DrawImage(x, y + 1, slot, 80);
  this.DrawImage(x + 1, y, slot, 80);
  this.DrawImage(x, y - 1, slot, 80);
  this.DrawImage(x, y, slot);
}

DynamicSprite* clockFace;

void DrawClock()
{
  clockFace = DynamicSprite.CreateFromExistingSprite(28, true);
  DrawingSurface* ds = clockFace.GetDrawingSurface();
  int a;
 
  // hour hand
  DynamicSprite* hourHand = DynamicSprite.CreateFromExistingSprite(CLOCK_SPRITE_H, true);
  a = minutes / 2;
  while (a > 359) a -= 360;
  if (a > 0 && a < 360) hourHand.Rotate(a, hourHand.Width, hourHand.Height);
  hourHand.Resize(CLOCK_RADIUS_H * 2, CLOCK_RADIUS_H * 2);
  ds.DrawImageAA(CLOCK_CENTER_X - hourHand.Width / 2, CLOCK_CENTER_Y - hourHand.Height / 2, hourHand.Graphic);
 
  // minute hand
  DynamicSprite* minuteHand = DynamicSprite.CreateFromExistingSprite(CLOCK_SPRITE_M, true);
  a = minutes * 6;
  while (a > 359) a -= 360;
  if (a > 0 && a < 360) minuteHand.Rotate(a, minuteHand.Width, minuteHand.Height);
  minuteHand.Resize(CLOCK_RADIUS_M * 2, CLOCK_RADIUS_M * 2);
  ds.DrawImageAA(CLOCK_CENTER_X - minuteHand.Width / 2, CLOCK_CENTER_Y - minuteHand.Height / 2, minuteHand.Graphic);
 
  ds.Release();
  gClock.BackgroundGraphic = clockFace.Graphic;
}

DrawingSurface* roomDS;
DynamicSprite* roomBG;

void CheckRoomBackground()
{
  if (player.Room < 40) return;
 
  int newBottom = eBGDay; // day
  int newTop = 0; // no second layer yet
  int t;
 
  // is it night?
  if (hour < 6 || hour > 18) newBottom = eBGNight;
  // dawn?
  if (hour ==  6 && minute < 30) newBottom = eBGDawn;
  // dusk?
  if (hour == 19 && minute < 30) newBottom = eBGDusk;

  // fading for 20 minutes each

  // night -> dawn
  if (hour == 5 && minute > 40) {
    newTop = eBGDawn;
    t = (60 - minute) * 5;
  }
  // dawn -> day
  if (hour == 6 && minute > 10 && minute < 30) {
    newTop = eBGDay;
    t = (30 - minute) * 5;
  }
  // day -> dusk
  if (hour == 18 && minute > 40) {
    newTop = eBGDusk;
    t = (60 - minute) * 5;
  }
  // dusk -> night
  if (hour == 19 && minute > 10 && minute < 30) {
    newTop = eBGNight;
    t = (30 - minute) * 5;
  }
 
  roomDS = Room.GetDrawingSurfaceForBackground();
  roomBG = DynamicSprite.CreateFromBackground(newBottom);
  roomDS.DrawImage(0, 0, roomBG.Graphic);
  if (newTop > 0) {
    roomBG = DynamicSprite.CreateFromBackground(newTop);
    roomDS.DrawImage(0, 0, roomBG.Graphic, t);
  }
  roomDS.Release();
  roomBG.Delete();
}

void Update() {
  if (seconds > 24 * 3600) seconds -= 24 * 3600;
  minutes = seconds / 60;
  hour = minutes / 60;
  minute = minutes - hour * 60;
  CheckRoomBackground();
  DrawClock(); 
}

void SetClock(int h, int m) {
  seconds = h * 3600 + m * 60;
  Update();
}

void AdvanceClock(int h, int m) {
  seconds += h *3600 + m * 60;
  Update();
}

int frameCount = 0;
void repeatedly_execute_always() {
 
  if (game.debug_mode && IsKeyPressed(eKeySpace)) {
    AdvanceClock(0, 1);
  }
  else {
    frameCount++;
    if (frameCount >= GetGameSpeed()) {
      frameCount -= GetGameSpeed();
      seconds += 3; // 1 second passes IRL => 3 seconds pass in game
    }
  }
 
  Update();
}

void on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) SetBackgroundFrame(0);
}
Title: Re: ANALOG CLOCK
Post by: Khris on Sun 26/01/2020 10:04:44
I already sent Katie a PM, but for reference, the line in question is line 58:

Code (ags) Select
  if (player.Room < 40) return;

I put this there because in the source files, the only playable room was room 40, and it was supposed to disable the background code for menu and intro rooms.
Title: Re: ANALOG CLOCK
Post by: katie08cd on Sun 26/01/2020 17:07:48
yes you are right, because the first modification was made by Cassiebsg, then since he only had to modify one thing I gave him the file you took, while before I sent him the one with the rooms but I had not calculated your intervention, however just remove that line and put 4 backgrounds (in case of error) always in each room and AdvanceClock (2, 0) also works; , but if in the future I would like a script in hours with a map can I do it? my idea was to make the map as in the photo divided into 4 time slots imagine (which I will then have to fix), from the left 0 hours, center + 1 hour, right + 2 hours, off the map 4 hours, travel to London in NY etc. the time it takes for train and ship, you can create a script where I insert the rooms change time (each room) all the time differences, of course then I create the detailed list but asked if I could do a thing of the kind, in the meantime thank you very much again

(https://i.ibb.co/hcV9vNn/2020-01-26-174514.png) (https://ibb.co/f9HF7WK)