multi-room light switch

Started by random_guy, Sun 10/06/2007 09:50:59

Previous topic - Next topic

random_guy

I'm going pretty well designing my game, even though as soon as I so much as see scripting code written down my eyes glaze over. But now I want to program something so when the player performs a certain action the power goes off in all five rooms created so far. When this happens, I want every room to be dark, but bright enough you can still see. I know how to set up the switch using variables, and have got that set up, but my solution for creating darkness of creating a checkerboard pattern with dark colours is less than ideal, because it doesn't look that great and the object interferes with the cursor.

What's the best way to perform what I'm trying to do? Keep in mind my aversion to scripting code - if it's doable via the GUI menus, that'd be great!

MrParkle

I think there are several possibilities to achieve this but it'll ask a bit of scripting.
The easiest solution I think is the following:
You can make an object (like a black square with the size of the room) and use transparency to achieve a darker see-through overlay (object[0].Transparency = 50).

The prettiest solution however is creating a new room:
Room1 is the room with lights on, Room2 is the room with lights off. Depending on the interactions available in the room, the scripting is relatively easy.
You can use a graphic editor to make the same background darker and play with lightning effects. This will be a lot easier than using AGS to alter the background.
To copy your existing room you can choose "save room as" in AGS. In the new room you load the other background. A nice feature with this is the fact that all objects etc stay at the same place.

Like the manual says: for a bit advanced gamemaking you have to script - but we are all here to help. Anyone else a suggestion?

Creator

You can always change the background frames (using the animating background frames, you'll find this in the manual).

MrParkle

Quote from: Creator on Sun 10/06/2007 12:07:41
You can always change the background frames (using the animating background frames, you'll find this in the manual).

Even better, I never think of the easiest solution first. Use the solution of Creator, almost no scripting needed.

Khris

#4
Using a black, transparent, full-screen object is easier, just keep in mind that you have to make the object unclickable and put its baseline at the very bottom of the screen to make sure it's displayed before/above all other objects.
From the menu, select Script -> on_event, then put this inside the function:
(Prepare, because your eyes are about to glaze over)
Code: ags
function on_event(EventType event, int data) {
  if (event==eEventEnterRoomBeforeFadein) {
    if (dark) {
      object[0].Visible=true;
      object[0].Transparency=50;
      object[0].Clickable=false;
      object[0].Baseline=Room.Height;
    }
    else
      object[0].Visible=false;
  }
}
(assuming that you're using the very first object in every room for the darkness object)


Using a second background frame is neater considering that lowering the light will also alter the hues of the room. But then you need to darken objects and characters manually. This can be done using a region with a low light level.

Code: ags
function on_event(EventType event, int data) {
  if (event==eEventEnterRoomBeforeFadein) {
    if (dark) {
      SetBackgroundFrame(1);
      region[1].LightLevel=-50;
    }
    else {
      SetBackgroundFrame(0);
      region[1].LightLevel=0;
    }
  }
}
(assuming that you are using region 1 to handle the lighting)

random_guy

#5
Thanks, guys. That'll help a lot.
edit: I keep getting an error message in the code I'm trying to write. What am I doing wrong?

Code: ags
#sectionstart on_event  // DO NOT EDIT OR REMOVE THIS LINE
function on_event(EventType event, int data) {
  if (event==eEventEnterRoomBeforeFadein) {
    if (GetGlobalInt('is it dark?') == 1) {
      object[3].Visible=true;
      object[3].Transparency=50;
      object[3].Clickable=false;
      object[3].Baseline=Room.Height;
    }
    else
      object[3].Visible=false;
  }
}
  


edit2: Am I wrong in thinking that a global integer is the same as a variable? If so, how do I call a variable in place of the global integer?

Ashen

#6
Please, include the exact text of any error messages you get. You should be able to use Ctrl-C to copy them/

GlobalInts are a type of variable, but looking at the name, I'm guessing you're after Graphical variables, as defined through thr Interaction Editor. If that's the case, READ THE MANUAL (although personally I recommend avoiding them, as they're very cumbersome to use). If not, I don't think that'd be a valid name for a script variable because of the spaces (and possibly the question mark), but where did you declare it and what type of variabel is it (int, bool, etc)?
I know what you're thinking ... Don't think that.

Khris

A GlobalInt is a special variable. It's an integer, and it's already global.
If you want to use your own global variables, declare them in the script, then ex- and import them.

e.g. like this:
Code: ags
bool it_is_dark=false;              // a bool is a variable that is either true or false
export it_is_dark;

#sectionstart on_event  // DO NOT EDIT OR REMOVE THIS LINE
function on_event(EventType event, int data) {
  if (event==eEventEnterRoomBeforeFadein) {
    if (it_is_dark) {
      ...
...

Then, in the script header, add this line:
Code: ags
import bool it_is_dark;

By ex- and importing a variable it is made global, thus can be accessed and changed from every script.

Now, if somebody turns off the light in one of the rooms, use
Code: ags
it_is_dark=true;


random_guy

I got it to work, and then discovered you need a hi-colour game to get transparencies to work, and mine is 256 colours. Oh well, back to the drawing board.

Ashen

KhrisMUC's second method, using Region.LightLevel should work, even in 256 colour.
I know what you're thinking ... Don't think that.

Monsieur OUXX

Just a little artistic piece of advice :

If you choose the solution where you change the background, keep in mind the way it was done in several adventure games : everything is almost black, but the character and important objects are gray ("monochromly" gray, not only darker) .

This sounds strange, but if you look at the results in some games, it's very immersive AND it doesn't disturb the gameplay (the player doesn't need to hurt his eyes to play).
 

SMF spam blocked by CleanTalk