Tripication 
 
 
		
			Member 
			
			
			
 
			
	Posts: 172 
	Threads: 19 
	Joined: Dec 2011
	
 Reputation: 
6
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				 (01-15-2012, 11:55 AM)Shadowfied Wrote:  Uhm..I thought I already told you I solved it? 
 
Statyk had put "SetLeverStuckState("LEVER4", 1, true);" in every function, removing all of those and adding your "SetLeverStuckState" scripts at the end solved it. There was no reason (not that I understand anyway) to make them stuck all the time and using the InteractDisablesStuck checkbox for this situation. Oh, thats good then. NVM about the last post.  
And good luck with the rest of your story
			  
			
			
 
			
		 |  
	 
 | 
 
	| 01-15-2012, 12:00 PM  | 
	
		
	 | 
 
 
	
		
		Shadowfied 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 261 
	Threads: 34 
	Joined: Jul 2010
	
 Reputation: 
5
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				 (01-15-2012, 11:56 AM)Your Computer Wrote:  Here's a more efficient way of doing it (though entirely untested).  
 
const string[] lever_names = {"LEVER1", "LEVER2", "LEVER3", "LEVER4"} const int[] desired_lever_states = {1, 1, -1, 1}
  /******************************************************************************/
  void OnStart() {     SetEntityConnectionStateChangeCallback("LEVER1", "lever_func");     SetEntityConnectionStateChangeCallback("LEVER2", "lever_func");     SetEntityConnectionStateChangeCallback("LEVER3", "lever_func");     SetEntityConnectionStateChangeCallback("LEVER4", "lever_func");
      SetLocalVarInt("LEVER1", 0);     SetLocalVarInt("LEVER2", 0);     SetLocalVarInt("LEVER3", 0);     SetLocalVarInt("LEVER4", 0); }
  /******************************************************************************/
  void lever_func(string &in asEntity, int alState) {     if (GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)         return;
      SetLocalVarInt(asEntity, alState);         CheckFunction(); }
  /******************************************************************************/
  void CheckFunction() {     for (int i = 0; i < lever_names.length(); ++i)     {         if (GetLocalVarInt(lever_names[i]) != desired_lever_states[i])             return;         else         {             SetLeverStuckState(lever_names[i], desired_lever_states[i], true);             SetEntityConnectionStateChangeCallback(lever_names[i], "");         }     }          GiveSanityBoost();     SetSwingDoorLocked("LEVERDOOR", false, true);     SetLocalVarInt("LEVER_PUZZLE_COMPLETE", 1); } 
 
  Wow that's a lot shorter. I appreciate it, although for now I'm gonna stick with what I understand myself so I have use for it and know what I'm doing.
 
Thank you very much Tripication.
			  
			
			
 
			
				
(This post was last modified: 01-15-2012, 12:02 PM by Shadowfied.)
 
				
			 
		 |  
	 
 | 
 
	| 01-15-2012, 12:01 PM  | 
	
		
	 | 
 
 
	
		
		Tripication 
 
 
		
			Member 
			
			
			
 
			
	Posts: 172 
	Threads: 19 
	Joined: Dec 2011
	
 Reputation: 
6
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				Ahh, that was fun. Time for tea.
			 
			
			
 
			
		 |  
	 
 | 
 
	| 01-15-2012, 12:02 PM  | 
	
		
	 | 
 
 
	
		
		Shadowfied 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 261 
	Threads: 34 
	Joined: Jul 2010
	
 Reputation: 
5
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				 (01-15-2012, 12:02 PM)Tripication Wrote:  Ahh, that was fun. Time for tea. Enjoy it. ;]
			  
			
			
 
			
		 |  
	 
 | 
 
	| 01-15-2012, 12:03 PM  | 
	
		
	 | 
 
 
	
		
		Statyk 
 
 
		
			Schrödinger's Mod 
			
			
			
 
			
	Posts: 4,390 
	Threads: 72 
	Joined: Sep 2011
	
 Reputation: 
241
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				 (01-15-2012, 11:56 AM)Your Computer Wrote:  Here's a more efficient way of doing it (though entirely untested).  
 
const string[] lever_names = {"LEVER1", "LEVER2", "LEVER3", "LEVER4"} const int[] desired_lever_states = {1, 1, -1, 1}
  /******************************************************************************/
  void OnStart() {     SetEntityConnectionStateChangeCallback("LEVER1", "lever_func");     SetEntityConnectionStateChangeCallback("LEVER2", "lever_func");     SetEntityConnectionStateChangeCallback("LEVER3", "lever_func");     SetEntityConnectionStateChangeCallback("LEVER4", "lever_func");
      SetLocalVarInt("LEVER1", 0);     SetLocalVarInt("LEVER2", 0);     SetLocalVarInt("LEVER3", 0);     SetLocalVarInt("LEVER4", 0); }
  /******************************************************************************/
  void lever_func(string &in asEntity, int alState) {     if (GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)         return;
      SetLocalVarInt(asEntity, alState);         CheckFunction(); }
  /******************************************************************************/
  void CheckFunction() {     for (int i = 0; i < lever_names.length(); ++i)     {         if (GetLocalVarInt(lever_names[i]) != desired_lever_states[i])             return;         else         {             SetLeverStuckState(lever_names[i], desired_lever_states[i], true);             SetEntityConnectionStateChangeCallback(lever_names[i], "");         }     }          GiveSanityBoost();     SetSwingDoorLocked("LEVERDOOR", false, true);     SetLocalVarInt("LEVER_PUZZLE_COMPLETE", 1); } 
 
  
Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.
 
Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):
 
CheckFunction() 
{ 
SetEntityInteractionDisabled("LEVER1", true); 
SetEntityInteractionDisabled("LEVER2", true); 
SetEntityInteractionDisabled("LEVER3", true); 
SetEntityInteractionDisabled("LEVER4", true); 
}
			  
			
			
			
				
(This post was last modified: 01-15-2012, 03:23 PM by Statyk.)
 
				
			 
		 |  
	 
 | 
 
	| 01-15-2012, 03:13 PM  | 
	
		
	 | 
 
 
	
		
		Inurias 
 
 
		
			Junior Member 
			
			
			
 
			
	Posts: 20 
	Threads: 0 
	Joined: Jan 2012
	
 Reputation: 
2
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				 (01-15-2012, 03:13 PM)Statyk Wrote:   (01-15-2012, 11:56 AM)Your Computer Wrote:  Here's a more efficient way of doing it (though entirely untested).  
 
const string[] lever_names = {"LEVER1", "LEVER2", "LEVER3", "LEVER4"} const int[] desired_lever_states = {1, 1, -1, 1}
  /******************************************************************************/
  void OnStart() { SetEntityConnectionStateChangeCallback("LEVER1", "lever_func"); SetEntityConnectionStateChangeCallback("LEVER2", "lever_func"); SetEntityConnectionStateChangeCallback("LEVER3", "lever_func"); SetEntityConnectionStateChangeCallback("LEVER4", "lever_func");
  SetLocalVarInt("LEVER1", 0); SetLocalVarInt("LEVER2", 0); SetLocalVarInt("LEVER3", 0); SetLocalVarInt("LEVER4", 0); }
  /******************************************************************************/
  void lever_func(string &in asEntity, int alState) { if (GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1) return;
  SetLocalVarInt(asEntity, alState); CheckFunction(); }
  /******************************************************************************/
  void CheckFunction() { for (int i = 0; i < lever_names.length(); ++i) { if (GetLocalVarInt(lever_names[i]) != desired_lever_states[i]) return; else { SetLeverStuckState(lever_names[i], desired_lever_states[i], true); SetEntityConnectionStateChangeCallback(lever_names[i], ""); } }
  GiveSanityBoost(); SetSwingDoorLocked("LEVERDOOR", false, true); SetLocalVarInt("LEVER_PUZZLE_COMPLETE", 1); } 
 
   
 
 
Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment. 
 
 
Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion): 
 
CheckFunction() 
{ 
SetEntityInteractionDisabled("LEVER1", true); 
SetEntityInteractionDisabled("LEVER2", true); 
SetEntityInteractionDisabled("LEVER3", true); 
SetEntityInteractionDisabled("LEVER4", true); 
} If you are really going for shortness, I just made up an even shorter version (which works):
 string[] vars = {"", "", "", "", ""}; 
 
void OnStart() 
{ 
    for (int i = 1; i <= 4; i++) 
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback"); 
} 
 
void LeverCallback(string &in asEntity, int alState) 
{ 
 
    if (alState != 0) 
    { 
        for (int i = 1; i <= 4; i++) 
        { 
                if (StringContains(asEntity, "" + i)) 
                { 
                    vars[i] = "b" + asEntity; 
                    SetLocalVarInt(vars[i], alState); 
                    SetLeverStuckState(asEntity, alState, true); 
                    break; 
                } 
        } 
    } 
 
    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1) 
        DoMyStuff(); 
} 
 
void DoMyStuff() 
{ 
     GiveSanityBoost(); 
                 SetSwingDoorLocked("LEVERDOOR", false, true); 
 
     for (int l = 1; l <= 4; l++) 
        SetEntityInteractionDisabled("LEVER" + l, true); 
}
 
- Inurias
			  
			
			
			
		 |  
	 
 | 
 
	| 01-16-2012, 09:11 PM  | 
	
		
	 | 
 
 
	
		
		Shadowfied 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 261 
	Threads: 34 
	Joined: Jul 2010
	
 Reputation: 
5
		
	 | 
	
		
			
RE: Need help to make a lever puzzle 
			 
			
				 (01-16-2012, 09:11 PM)Inurias Wrote:   (01-15-2012, 03:13 PM)Statyk Wrote:   (01-15-2012, 11:56 AM)Your Computer Wrote:  Here's a more efficient way of doing it (though entirely untested).  
 
const string[] lever_names = {"LEVER1", "LEVER2", "LEVER3", "LEVER4"} const int[] desired_lever_states = {1, 1, -1, 1}
  /******************************************************************************/
  void OnStart() { SetEntityConnectionStateChangeCallback("LEVER1", "lever_func"); SetEntityConnectionStateChangeCallback("LEVER2", "lever_func"); SetEntityConnectionStateChangeCallback("LEVER3", "lever_func"); SetEntityConnectionStateChangeCallback("LEVER4", "lever_func");
  SetLocalVarInt("LEVER1", 0); SetLocalVarInt("LEVER2", 0); SetLocalVarInt("LEVER3", 0); SetLocalVarInt("LEVER4", 0); }
  /******************************************************************************/
  void lever_func(string &in asEntity, int alState) { if (GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1) return;
  SetLocalVarInt(asEntity, alState); CheckFunction(); }
  /******************************************************************************/
  void CheckFunction() { for (int i = 0; i < lever_names.length(); ++i) { if (GetLocalVarInt(lever_names[i]) != desired_lever_states[i]) return; else { SetLeverStuckState(lever_names[i], desired_lever_states[i], true); SetEntityConnectionStateChangeCallback(lever_names[i], ""); } }
  GiveSanityBoost(); SetSwingDoorLocked("LEVERDOOR", false, true); SetLocalVarInt("LEVER_PUZZLE_COMPLETE", 1); } 
 
   
 
 
Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment. 
 
 
Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion): 
 
CheckFunction() 
{ 
SetEntityInteractionDisabled("LEVER1", true); 
SetEntityInteractionDisabled("LEVER2", true); 
SetEntityInteractionDisabled("LEVER3", true); 
SetEntityInteractionDisabled("LEVER4", true); 
} If you are really going for shortness, I just made up an even shorter version (which works): 
 
string[] vars = {"", "", "", "", ""}; 
 
void OnStart() 
{ 
    for (int i = 1; i <= 4; i++) 
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback"); 
} 
 
void LeverCallback(string &in asEntity, int alState) 
{ 
 
    if (alState != 0) 
    { 
        for (int i = 1; i <= 4; i++) 
        { 
                if (StringContains(asEntity, "" + i)) 
                { 
                    vars[i] = "b" + asEntity; 
                    SetLocalVarInt(vars[i], alState); 
                    SetLeverStuckState(asEntity, alState, true); 
                    break; 
                } 
        } 
    } 
 
    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1) 
        DoMyStuff(); 
} 
 
void DoMyStuff() 
{ 
     GiveSanityBoost(); 
                 SetSwingDoorLocked("LEVERDOOR", false, true); 
 
     for (int l = 1; l <= 4; l++) 
        SetEntityInteractionDisabled("LEVER" + l, true); 
}
  
- Inurias I wish I understood that..
			  
			
			
 
			
		 |  
	 
 | 
 
	| 01-17-2012, 08:15 AM  | 
	
		
	 | 
 
 
	 
 |