How i put a light switch in my rooms?

Started by Jakerpot, Wed 07/01/2009 19:06:55

Previous topic - Next topic

Jakerpot

Hi everybody. I guess this question of mine sucks, it could be on the help, it could have already been posted or wahtever i'm doing wrong, i want to know; how the hell i make a light switch? In my room there is a lamp. and i want to the room to start black (not complete black, but almost all black) and the when the player interact with the small rope on the roof, the lights will turn on. And when the player quit the room and enter again, the lights will be already on (not if he turned off again before quiting). Did you understand?
Help me please  ??? ???



Khris

Import the two backgrounds as room backgrounds. First the dark one, then the lit one (for the purposes of my explanation, it doesn't really matter).

Add a "player enters screen before fadein" event to the room, then add the "interact with rope" event (by clicking the ellipses button in the event's field).
Now open the room script.
It should look like this:
Code: ags
// room script

function room_Load() 
{

}

function oRope_Interact()
{

}


Add the following lines so it looks like this:
Code: ags
// room script

int light_is_on;

function room_Load() {
  SetBackgroundFrame(light_is_on);    // set background to frame 0 (dark) or frame 1 (light)
}

function oRope_Interact() {
  light_is_on = 1 - light_is_on;  // toggle light
  SetBackgroundFrame(light_is_on);    // update background
}


An alternative way to do it is use only the lit background, then put a semi-transparent, screen-sized black GUI on top.
If you want to use that method, call the GUI e.g. gDarkness, then use this:
Code: ags
// room script

bool light_is_on;

function room_Load() {
  gDarkness.Transparency = 40;     // experiment with settings 20 to 80
  gDarkness.Visible = !light_is_on
}

function oRope_Interact() {
  light_is_on = !light_is_on;  // toggle light
  gDarkness.Visible = !light_is_on
}


Vince Twelve

D'oh, I wrote a big message and then Khris beat me to it!

I'll just add that if you're changing the background frame, you might want to experiment with SetAmbientTint, Character.Tint, or Object.Tint to make the characters and objects on the screen get darker as well.  Otherwise, you could just make them invisible if you don't want them to be seen at all when the lights are off.

That would be done in
Code: ags

function oRope_Interact() {
  light_is_on = 1 - light_is_on;  // toggle light
  SetBackgroundFrame(light_is_on);    // update background
  if(light_is_on==0){
    //change the tints to black here
  }
  else{
    //remove tints here
  }
}

Jakerpot

#3
Thank guys, but Khris, is Light_is_one a variable? This part i don't get it. Tell-me what is it please.
EDIT: Another question, i want to add some pick-up things in the room, but then how i make to the objects turn almost black? When lights off, the pick-ups goes black-like, and when the lights are on, they turn to normal collour, i have to use a tint scripts?  (sorry guys, this is my 2 day with AGS, with a long 2 years interval since my last use in it  :-X )
EDIT II: i want to know too, how can i do a script like, if lights off, then when the player interact with the oick-ups will pop-up a message saing that its too dark there. How i do that?????????



Vince Twelve

You'll see inside that second block of code Khris wrote the first line is
Code: ags

int light_is_on;


That's him declaring a variable.  Actually, you should probably give it a starting value, 0 for off, 1 for on.  Like this:

Code: ags

int light_is_on=0;  //makes the lights start off


What I was talking about with Tint will help you make the objects black.  Read about it in the manual and post back with any specific questions.

For making interactions change depending on the light being on or off, just use an if statement inside the interact function.

Code: ags


function oObjectName_Interact(){
  if(light_is_on==1){
    //do stuff when light is on
  }
  else{
    //do stuff when light is off
  }
}

Jakerpot

Ok, if i understand well, if i write int, i'am creating a variable?



Vince Twelve

Yes,  int means you are declaring an integer (number).  You have to declare a variable before you can use it.

Read the Beginner's tutorial on scripting here:
http://www.adventuregamestudio.co.uk/actutor.htm

SMF spam blocked by CleanTalk