Time of day Scripting (SOLVED)

Started by Da_Elf, Wed 01/11/2006 22:27:24

Previous topic - Next topic

Da_Elf

I'm having a problem. its been so long since i last coded that i forgot how to properly use global variables. I want to set up a time system when the beginning time = 1 then after that everytime you enter a room it adds 1 to the time then when you leave the room it does a conditional check on the variable. if the variable is less than lets say 5 (  <5   ) then going to the next room it loads the daytime room. if the variable is between 5 and 10 then it will open a night room. then if the variable reaches 10 it will load a day room then set the variable back to 1. is this possible?

Khris

At the start of the global script, put this:
Code: ags
int daytime=1;

function Leave(int dayroom, int nightroom, int x, int y) {
  daytime++;
  if (daytime==11) daytime=1;
  if (daytime<6) player.ChangeRoom(dayroom, x, y);
  else player.ChangeRoom(nightroom, x, y);
}


Import the function in the header:
Code: ags
import function Leave(int dayroom, int nightroom, int x, int y);


Then use e.g. Leave(3, 7, 10, 130); to make the player appear at coords 10, 130 in room 3(day) or 7(night).

Da_Elf

my main problem is figuring out where the scripts go. i can read through your code and it makes sence. where to put it is what i never understand. If you read your instructions properly i need to do something like this?



once thats in is this where i put the other code you mentioned??



this is how ive been controlling walking off the screen to get to other rooms

. i now need to know where im supposed to specify in each room if for instance walking out of room1 (asterixes house during the day) through the bottom of the screen to then decide if its room 5 or 6 at the fish monger. and every room needs to be able to read the time variable and choose between a day room or a night room.

Khris

Quote from: Da_Elf on Wed 01/11/2006 23:34:23once thats in is this where i put the other code you mentioned??
Yes. The function needs to be imported in the script header so it's available from room scripts, too.

Then, instead of using the "Player - Go to..."-interaction, use a RunScript-interaction, click the "Edit script"-button, this will open a window, then insert Leave(...); there.

(If you go to Room Editor -> Settings, you can click the {}-button to take a look at the room script. Your previous action should have created a function called something like room_a() with a comment stating the event that triggers the function, in this case crossing a screen edge, inside the function is exactly the code you've entered in the other window.)

The Leave-function takes care of everything, you only need to specify the dayroom, then the nightroom, then the coords.
It will increment the variable, reset it to one if necessary and make the player go to one of the rooms, depending on its count.

Da_Elf

ok. i tried doing this but get this error.


Khris

No, you got it all wrong, leave the global script as it was before!

Then, in the room script, simply add
Code: ags
Leave(5, 6, 20 196);


And you don't need to increase daytime manually.

Your room script should look like this:
Code: ags
// room script file

#sectionstart room_a   // DO NOT...
function room_a() {
  // script for Room: Walk off bottom screen edge
  Leave(5, 6, 20, 196);
}
#sectionend room_a  // DO NOT...

Da_Elf


Janik

Hey is that an Asterix game you are working on (I'm guessing from the background)? If so, awesome!
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

gypsysnail

Hey this is what I have been looking for too :) I need to know how, from the start, to make night time happen at times and day time happen again - a timer? If anyone can help me with this, that would be brillant :). I am new to this all :P. Is it i have to create two of the same room - one darkened (night) and one normal (day) for each room thats outside etc? And put in a timer in the game? The ball is rolling..... ;) thankies in advance for help
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Gilbert

I'm just too lazy to explain, maybe my old demo can inspire you (sloppily updated to work with V2.72, note:documents were from VERY old version), it used background frames (and palette effects) instead of rooms though.

gypsysnail

Lol Gilbot, mr lazy man ;) I will go try it!! Thankies :P
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

You need to decide on a way time will pass first. Real time? System time? Changing rooms? Doing certain stuff (like letting the character rest, or using magic)?

Next thing to do is wondering about how the game will display the time of day. Using two rooms for each location is obvious, but it's tedious to continuously update both of them whenever the player does something. (Even more if there aren't just day and night but e.g. dusk and dawn, too, since you'd need four rooms for every location then.)
The better way would be to use background frames and palette effects, as Gilbot did.
The background frames hold differently lighted versions of the background, while a big region with a varying level of light takes care of chars and objects.

Third and final step: Handle room changes. Every room needs to call a function that sets the room's lighting according to the time of day. There's an event handler called eEventEnterRoomBeforeFadein that can be used.

The "problem" with AGS is, even if you're very specific when telling us about what you want to happen, there is probably still more than one way to achieve it.

Da_Elf

I didnt know about the palette thing so when i was designing my backgrounds i used photoshop and make different adjustment layers which allow me to turn on nighttime looks. This way i set things up in ags with two rooms for every area. i couldnt use bacground frames since some backgrounds are animated and i need the frames to deal with the animation. I was just guessing what would be the best approach. basically im a novice so i dont know whats best

Khris

You can animate backgrounds with non-clickable objects, too. One should use that for small areas preferably, but in theory an object can be used to animate the whole background.

You are using only day and night, so it won't be that much of a hassle, but I believe gypsysnail wants to implement several different times of the day.
When using two or more rooms, you'll have to move the NPCs to the current one every time the player enters. But this is going to be the least of your worries. You'll have to keep track of used hotspots and picked up items, open/closed doors and so on.

It's possible, but as I said, it's going to be much, much repetitive work, and it's way more error-prone than usual scripting already is.

Da_Elf

it will be lots of work. what ill be doing is to setup all of the day ones scripting in all the general things that will work both for day and night (based on what i need to happen on both day and night) then i will simple make a copy of the day room and replace the background with the night background. then further refine my scripting for the day and the night seperately

gypsysnail

Ahh thats interesting! If the dawn and dusk are hard to do then maybe I should opt for the easier way and let the room go dark slowly at a set certain time with the palette and those tinting sort of things...... that be easier? With a timer on hand, I think I can trust the timer to set off the rooms to go dark (except for the indoors areas - how will I stop those goin tinted like night time outside?) Thanks heaps for the replies, will look fwd to hearing more on this and what you can come up for this one I have. Cheers :)
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

With a system like this, every room is going to have the same background scheme, e.g.: original background: day, background frame 1: dusk, 2: night, 3: dawn
The lighting region in all rooms is going to be the same, too, e.g. region #1.

Thus stopping indoor rooms from going dark is easy: don't darken the night frames and don't draw region #1 :)

A more resource friendly way would be to use an array to store whether the room is outside or not, then use if (outside[player.Room]) {...} around the darkening code.

SMF spam blocked by CleanTalk