Set Color Sequence On Object

Started by Arjunaz78, Fri 18/11/2011 02:25:41

Previous topic - Next topic

Arjunaz78

I have create an object in the game room, and set a 5 object (standing lamp) on my room..and i use the tint code that can change the lamp color..
for activate it's,i just create a custom variable too,that determine the lamp click counting to force the color event function...

this is the code that i been use..

Code: ags
function SLamp1_Interact()
{
  aClick.Play();
  
    lamp_click++;
  
    if (lamp_click == 1) {
  oSLamp1.Tint(0, 250, 0, 30, 100);
}
 
 if (lamp_click >= 2) {
  oSLamp1.Tint(250, 0, 0, 30, 100);
 }
 
 if (lamp_click >= 3) {
   oSLamp1.Tint(0, 0, 250, 30, 100);
 }
}


The problem is how can i switch back to red color again after i click the blue color like below code? i mean after..

Code: ags
if (lamp_click >=3) {
 oSLamp1.Tint(0, 0, 250, 30, 100);
 }


What i want is the lamp_click int run in sequence that will switch back to start of lamp_click event. This will be look's like repeatedly executed function, but i don't know how to use it with this custom global variable, besides i don't think i can use the loops event ('while' statement).
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Adrian

By default int lamp_click starts at 0.

You need one setting for each color of your lamp:
lamp off: lamp_click = 0
lamp first color: lamp_click = 1
lamp second color: lamp_click = 2

Everytime the function is called, lamp_click increases by 1, so at some point you have to put it back to 0, which is in the last else condition. When the function is called again afterwards, lamp_click will be set to 1 again and the whole cycle starts over again as wanted.

By the way, you can set back the tint of an object just by calling oSLamp1.RemoveTint();

Try this:
Code: ags

function SLamp1_Interact()
{
  aClick.Play();
  
  lamp_click++;
  
  if (lamp_click == 1) {
  	oSLamp1.Tint(0, 250, 0, 30, 100);
  }
 
  else if (lamp_click == 2) {
  	oSLamp1.Tint(250, 0, 0, 30, 100);
  }
 
  else {
  	oSLamp1.Tint(0, 0, 250, 30, 100);
	lamp_click = 0;
  }
}



Arjunaz78

YES..thanks..it's work but there is another problem..how can i set or determine an action that will activate the other event such as changeroom or open door using the color event action..what i want is when the player click or choose the right color sequence, it will activate the other event action..

For above example, i will using the tint color function event to determine an action..when the player has choose the other three of the lamp color..for example the oSLamp1 = green, oSLamp2 = red & oSLamp3 = blue..the window or secret door will open..how can i coding it? i actually knew with using else, if, else if and while operator..but i got confusing with this ones..

THX.
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Khris

Add a function to the top of the room script, like this:

Code: ags
function Check_Lamps() {

  if (lamp_click1 == 2 && lamp_click2 == 1 && lamp_click3 == 0) {

    // open door
  }
}


Now call that at the end of each lamp's interact function:

Code: ags
  ...
  ...

  else {
  	oSLamp1.Tint(0, 0, 250, 30, 100);
	lamp_click = 0;
  }

  Check_Lamps();    // <- ADD THIS
}


Cool, huh?
NEEEXT!

SMF spam blocked by CleanTalk