object conditionals

Started by JJJAC55, Fri 25/03/2005 18:25:37

Previous topic - Next topic

JJJAC55

OK, in my game there's a job where you're a janitor.  Each night you use the key to get in, then theres dirt and crap on the floor you have to sweep up.  Then you use the broom and stuff to clean it.  How to I make it so the dirt and crap only appears @ night?

DoorKnobHandle

Once again you have to use variables...

First you declare this variable on top of your script:

Code: ags

int isnight;


Now you initialise it in your game_start ( ) function like this:

Code: ags

isnight = 0;


Now whenever you change from being night to day you change the variable using:

Code: ags

isnight = 1;


or:

Code: ags

isnight = 0;


And then you go to "On Player enters screen" of the room with the dirt and crap and write:

Code: ags

ObjectOff ( DIRT );
ObjectOff ( CRAP );

if ( isnight == 1 )
{
Ã,  Ã, ObjectOn ( DIRT );
Ã,  Ã, ObjectOn ( CRAP );
}


That only shows the dirt and crap when it is night...

Ask if you have further questions or look it up in the manual!

strazer

Global variables don't have to be initialized, they are automatically initialized to 0.
If you need another starting value, you can initialize it when defining it:

Code: ags

// global script

int isnight = 1;


To be able to access a variable defined in the global script in room scripts, you have to export it first, then import it in either the global script header (for all rooms) or just the room script of the room where you need it:

Code: ags

// global script

int isnight;
export isnight;


Then

Code: ags

// main script header

import int isnight;


or

Code: ags

// room script

import int isnight;

SMF spam blocked by CleanTalk