ANALOG CLOCK

Started by katie08cd, Sat 18/01/2020 21:06:15

Previous topic - Next topic

katie08cd

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


Cassiebsg

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

katie08cd

#2
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

fernewelten

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

Crimson Wizard

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

katie08cd

#5
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

katie08cd

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

Cassiebsg

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.

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

katie08cd

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

Cassiebsg

#9
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

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.





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

Snarky

You could also check out my Day/Night module to keep track of the time.

katie08cd

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

Cassiebsg

Line 11 on my code is how you change the clock sprite.

No idea what you mean by "frame".
There are those who believe that life here began out there...

katie08cd

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

Cassiebsg

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

katie08cd

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

Crimson Wizard

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

Cassiebsg

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

katie08cd

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



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

Cassiebsg

#19
Code: ags

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

SMF spam blocked by CleanTalk