Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Thu 19/05/2005 09:29:33

Title: Day - Night Question
Post by: on Thu 19/05/2005 09:29:33
My Question is this - I Would like to use the tint effect in my game to make time changing between day and night... up to now I have manually used scripting to do this.... but would like to change it so that it happens automatically.... (Day light fading....becomes night...) Could some one please tell me wear to start and some help with script as well. ???
Title: Re: Day - Night Question
Post by: QQuest on Thu 19/05/2005 14:26:21
Very New at AGS....How(Scripting Needed)....Please Help
Title: Re: Day - Night Question
Post by: Ashen on Thu 19/05/2005 15:00:04
You're going to have to be more specific about what you need - for example how long do you want it to take, is it just one room or across the whole game, cutscene or playable, what code have you got so far to work from...
Title: Re: Day - Night Question
Post by: QQuest on Thu 19/05/2005 15:18:07
In my room script I Called
in room script // Player enters screen (before fading)
TintScreen (0,0,50); // to tint screen blue
//rest of script
//

Then as the game goes on..... in a different room(Later) I used
in room script // Player enters screen (before fading)
TintScreen (10,0,30); // to tint screen lighter blue to give the appearance of dawn braking
//rest of script
//
Display("The Sun is rising");
//
//


A few rooms later......
in room script // Player enters screen (before fading)
TintScreen (20,0,0); // to tint screen lighter blue to give the appearance of dawn braking
//rest of script
//
Display("Dawn Brakes");
//
//

....Later.....
TintScreen (0,0,0); // to tint screen lighter blue to give the appearance of dawn braking
//rest of script
//

I would like to have this tipe of day night effect done auotomatically by the game...across the hole game.... with a "GAME DAY" lenght of about 30 Min and a "GAME NIGHT" lenht of about an hour.
Day and Night should be playeble as the my charecter is a vampire....who needs to sleep or hide during the day......., but during day times the player charecter is switched to  a diferent charecter who has his own quest during the day...(smaller quests...to assist the vampire.)
Title: Re: Day - Night Question
Post by: Ashen on Thu 19/05/2005 16:09:57
You have 4 'stages' of light to fit into your day (I guess Dawn, Day, Dusk and Night).
Say the 'day' stages take about 15 mins each, and the 'night' ones take 30 - for the 90 minute 'Game Day' you wanted.

In 'Player enters screen (before fadein)' of the first room:

TintScreen (0,0,50); // or whatever the initial tint you want is
SetTimer (1, 900 * GetGameSpeed ()); // or 1800, if you want to start the game at 'night'

In case you're wondering where I got 900 & 1800 from:
15 / 30 (minutes per 'stage') * 60 (seconds per minute) * number of gameloops per second (usually 40, but GetGameSpeed() may be more accurate)


Then, in the GLOBAL repeatedly_execute:

if (IsTimerExpired (1)) {
  if (GetGlobalInt (1) == 0) {
    TintScreen (10,0,30);
    // Any message you want
    SetTimer (1, 900 * GetGameSpeed ()); // Alter these, based on whether tint is for night or day
  }
  else if (GetGlobalInt (1) == 1) {
    TintScreen (20,0,0);
    // Any message you want
    SetTimer (1, 1800 * GetGameSpeed ()); // Alter these, based on whether tint is for night or day
  }
  else if (GetGlobalInt (1) == 2) {
     TintScreen (0,0,0);
    // Any message you want
     SetTimer (1, 1800 * GetGameSpeed ()); // Alter these, based on whether tint is for night or day
  }
  else if (GetGlobalInt (1) == 3) {
    TintScreen (0,0,50);
    // Any message you want
    SetTimer (1, 900 * GetGameSpeed ()); // Alter these, based on whether tint is for night or day
  }
  if (GetGlobalInt (1) < 3) SetGlobalInt (1, GetGlobalInt (1) + 1);
  else SetGlobalInt (1, 0);
}


Something like that should work - I tried it with much smaller numbers, though (9/18 seconds). If you want to add more transitions, just add more else if (GetGlobalInt (1) == x) conditions, and don't forget to change the (GetGlobalInt (1) < 3) as well. You could use your own int, instead of a GlobalInt, of course - I was just trying to save a little scripting.
Title: Re: Day - Night Question
Post by: QQuest on Fri 20/05/2005 07:00:33
Thank you so mutch  ;D....can't wait to try this out.... will let you know once I got it.

Some thing else... is it possible to have a button on my GUI to skip over the "Day Time"...."Night Time" event.
Title: Re: Day - Night Question
Post by: Ashen on Fri 20/05/2005 10:56:09
Should be possible, yes. All you'd need to do is have the button run SetTimer (1, 1); to force the update to happen sooner, and any other changes you want to happen based on what time of day/night it is (e.g. change the player character) - which you can check with GetGlobalInt(1) like in the other code.
Title: Re: Day - Night Question
Post by: QQuest on Fri 20/05/2005 14:09:40
Hey what do you know....it works Thank you again ;D

......BUT.....Now I am stuck with a different problem.....

I want the VAMPIRE to (DIE) (Game Over) if he is not standing on a specific hot spot during a certain time of day i.e.. "dark spot" or "Shadow" during the day time.... how do I get the script to recognize that it is day time so that it can activate the hot spot(Shadow).
Title: Re: Day - Night Question
Post by: Ashen on Fri 20/05/2005 14:41:39
You can use GetGlobalInt(1) in repeatedly_execute (e.g.

if (GetGlobalInt == 0) Enable Hotspot (1); // or whatever GlobalInt 1 should be for daylight, and whatever hotspot you're using.
else DisableHotspot(1);

Or, you could activate/deactivate the hotspot when you change the tint. (That might not work, though - since it's a global script, the hotspot would have to be the same number in every room.)

(Also, looking at it, you might be better using a Region, rather than a Hotspot, for this.)
Title: Re: Day - Night Question
Post by: QQuest on Mon 23/05/2005 12:00:16
Thank you...got it working....GUI still a problem.....My game exits on button use for some or other reason, doesn't give a message....just exits.
Title: Re: Day - Night Question
Post by: Ashen on Mon 23/05/2005 19:16:26
Has this just started happening, since you included the 'standing on shadow' code from above?
Can you show the code for the button, and maybe whatever you added for the shadow thing - it's posible there's some conflict that causes the crash, especially if it's a new problem.
Title: Re: Day - Night Question
Post by: QQuest on Tue 24/05/2005 08:20:42
All the oter GUI buttons work fine.... remember the button that I made to skip "Day -Night" time.... Thats the one that exits the game....the others work fine.

code:
SetTimer (1, 1); // seems to delete the timer.... don't know if that is it...

can't think of anything else.  ???
Title: Re: Day - Night Question
Post by: Ashen on Tue 24/05/2005 11:45:20
I got that it was that button causing the problem - it's just that you originally said it worked, then said it was a problem AFTER you'd got the shadow code working. That's why I asked if it was a new problem, and what code you'd put in recently.

One thing I spotted:

if (GetGlobalInt == 0) Enable Hotspot (1);

should be:

if (GetGlobalInt(1) == 0) Enable Hotspot (1);

But I'm guessing you sorted that out, since you say it's working, and I don't know if that'd cause a crash anyway.

Other than that, there's no reason I can see that the code shown in this thread would cause a crash, so the problem is either a random bug, or a conflict with some other code somewhere else in the game - and since it sounded like it started after the shadow code went in, that seemed like the most likely suspect.

Since the button code doesn't seem to be at fault (i.e. it works when I've tested it) , what else you got set to happen when the time changes?
Title: Re: Day - Night Question
Post by: QQuest on Tue 24/05/2005 12:33:46
First off all...sorry for bugging you all the time....Now....I only made the button after everything els....it's the last thing I put in....but I made a stupid error...I used the wrong button numbers....the exit button did what the "Day Night" button was supouse to do and the "Day Night" button then did the job of my exit button.... (should test before I ask...hey)....SORRRRYYYY.....  :o
Title: Re: Day - Night Question
Post by: monkey0506 on Tue 24/05/2005 20:41:03
Don't worry, just some tips:

1.  Review the problem yourself at least twice to ensure you don't know the solution.
2.  Check the manual for anything related to your problem.
3.  Search the forums for related threads.
4.  Ask in the forums for help.

You should always try to follow these steps to prevent yourself from asking questions that are/have been covered in the manual/in the forums.  And you'll be more likely to remember it if you have to search around a bit instead of waiting for a reply...
Title: Re: Day - Night Question
Post by: DeadlyJynx on Sat 28/05/2005 09:17:39
call me a spammer but.....

i check  the manual while posting and waiting for replies on forums...

Anyways ... i did a sort of same thing as he did... and it worked fine...