ANALOG CLOCK

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

Previous topic - Next topic

katie08cd

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






Cassiebsg

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

katie08cd

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

Cassiebsg

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.


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

katie08cd

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

Cassiebsg

Please copy paste the entire function.  :-\
There are those who believe that life here began out there...

katie08cd

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

katie08cd


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++;
          }
        }
    }
  }
 
}

Cassiebsg

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

katie08cd

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

Cassiebsg

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

katie08cd

#31
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++;


Cassiebsg

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

katie08cd

wowww :) thank you, I'm glad you did it, congratulations

Cassiebsg

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

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

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

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

katie08cd

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

Cassiebsg

NONONONO

Just open Global Variables, edit intHour and set the default to 9!
There are those who believe that life here began out there...

katie08cd

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

Cassiebsg

That is not sprite number, it's hour.  :~(
There are those who believe that life here began out there...

katie08cd

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




SMF spam blocked by CleanTalk