Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help SOLVED - Levers Script
MsHannerBananer Offline
Member

Posts: 218
Threads: 34
Joined: Sep 2013
Reputation: 10
#1
SOLVED - Levers Script

Objective: 7 switches needed to be in the same position before another switch unlocks, which allows the player to progress.

Following Mudbills tutorial aaaaaand of course I got stuck, because the function isn't calling at all. Yay me.

void LeverPuzzle(string &in asEntity, int LeverState)
{
    if(GetLeverState("marine") == -1
    && GetLeverState("pump") == -1
    && GetLeverState("animal") == -1
    && GetLeverState("quarters1") == -1
    && GetLeverState("quarters2") == -1
    && GetLeverState("quarters3") == -1
    && GetLeverState("quarters4") == -1)
    {
        SetPropStaticPhysics("main_switch1", false);
        SetLeverStuckState("marine", -1, true);
        SetLeverStuckState("pump", -1, true);
        SetLeverStuckState("animal", -1, true);
        SetLeverStuckState("quarters1", -1, true);
        SetLeverStuckState("quarters2", -1, true);
        SetLeverStuckState("quarters3", -1, true);
        SetLeverStuckState("quarters4", -1, true);
    }
}

void MainSwitch1(string &in entity, int alState)//For when the above script sets this switch's staticstate to false and it can be moved into the proper position//
{
     if(alState == -1)
    {
    SetPropStaticPhysics("main_switch1", true);
    }
}

Yes, I've checked, double checked, and triple checked my names. They all match. The function isn't calling at all.

(This post was last modified: 04-01-2014, 04:01 AM by MsHannerBananer.)
03-31-2014, 07:49 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Levers Script

Try adding some debug messages around to see where it stops working. Add one before the if statements in the LeverPuzzle function to confirm that it's called, then have one inside the block to check if it's passed. If you have this event added to the entities in the level editor, they should surely run this function, but perhaps the states aren't proper?

(This post was last modified: 03-31-2014, 09:27 AM by Mudbill.)
03-31-2014, 09:26 AM
Find
MsHannerBananer Offline
Member

Posts: 218
Threads: 34
Joined: Sep 2013
Reputation: 10
#3
RE: Levers Script

(03-31-2014, 09:26 AM)Mudbill Wrote: Try adding some debug messages around to see where it stops working. Add one before the if statements in the LeverPuzzle function to confirm that it's called, then have one inside the block to check if it's passed. If you have this event added to the entities in the level editor, they should surely run this function, but perhaps the states aren't proper?

Totally looooove that this kind of magical stuff happens to me.

These kinds of problems end up 1 of 3 ways with me. Either they're super simple and I'm an idiot to have not been able to figure it out; they mysteriously solve themselves automagicall ;P ; or they never get solved and I have to change the script. Yay me, haha.

Wouldn't happen to be because they are the levers imported from Penumbra, would it? I mean, they have the exact parameters as the levers traditionally found in Amnesia, so I didn't think it would be a problem. I guess the only way to find out would be if I replaced all the levers in question with Amnesia levers.

Debugssss where for art thou debugs... (debug messages aren't calling hahahahahahah scripting hates me. *sobs*)


Edit: The good news is that with globalvarint's I can do a nice little work around. Hopefully.

The bad news is, I have a long night of scripting ahead of me. *Dead*

(This post was last modified: 03-31-2014, 10:43 AM by MsHannerBananer.)
03-31-2014, 10:41 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#4
RE: Levers Script

I'm testing out some stuff now with local vars. If I come up with a solution, I'll let you know, and I'll try to keep the code as simple as possible!

EDIT: Got it (at least, I believe I have. Posting it now below here, editing this post.



In this description, I am assuming you named the callbacks in the level editor. I have named these switches differently in my example, but the only one that really makes any difference is the main_switch1.

Okay, I won't lie, without being mean, the code is a bit too extensive.

I decided to replicate your map by using a test map, in which I used eight switches. The first seven from left to right are the ones needing to be stuck in order to get the main one (the far right) to not be a static physic object.

[Image: 642fli.jpg]

Basically I took your code, shortened it, and did what I could to reproduce the appropriate output. To do so, I told each of the first seven levers to callback your code called LeverPuzzle, and similarly with the main switch to call MainSwitch1 (however these functions work differently in the actual code I had).

[Image: ejx4pc.jpg]

Then I called the code as below.
PHP Code: (Select All)
void OnStart()
{
    
//SetPropStaticPhysics("main", true);                Enabled this through Level Editor
    
SetLocalVarInt("switches"0);                            //Create a localvar 
}

void LeverPuzzle(string &in asEntityint LeverState)
{
    if(
LeverState == -1)                                      //Lever is all the way up
    
{
        
SetLeverStuckState(asEntity, -1false);       //asEntity makes either lever become stuck
        
AddLocalVarInt("switches"1);                //Increment Var
    
}
    if(
GetLocalVarInt("switches") == 7)                  //All switches are up
    
{
        
SetPropStaticPhysics("main"false);        //Main switch can be used
    
}
}

void MainSwitch1(string &in asEntityint LeverState)
{
    if(
LeverState == -1)                                      //Check if main switch is up
    
{
        
SetLeverStuckState(asEntity, -1false);  //Stick main switch to up position
        //Put what you want to happen after you trigger main switch here :-)
                //For example, I unlocked the door in that example room :D
    
}


And... well that was it really xD

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 03-31-2014, 11:43 AM by Romulator.)
03-31-2014, 11:10 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#5
RE: Levers Script

I'm not sure if it's intentional or not, but I don't think it's desired to have each lever stuck after it's used. I just imagine it to be a kinda pointless puzzle if all you do is pull all the levers; no particular order or combination.

Anyway, the problem might actually be because of the imported levers. Have you tried them for other functions? Perhaps they have odd states. I made a lever once and it resulted in having the lower state at the bottom and the top state just slightly above it (before the lever even got half way up). Try using the default ones, just change the entity with the triple dot button.

03-31-2014, 01:42 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#6
RE: Levers Script

(03-31-2014, 01:42 PM)Mudbill Wrote: I'm not sure if it's intentional or not, but I don't think it's desired to have each lever stuck after it's used. I just imagine it to be a kinda pointless puzzle if all you do is pull all the levers; no particular order or combination.

Anyway, the problem might actually be because of the imported levers. Have you tried them for other functions? Perhaps they have odd states. I made a lever once and it resulted in having the lower state at the bottom and the top state just slightly above it (before the lever even got half way up). Try using the default ones, just change the entity with the triple dot button.

In my instance, you would need to make sure that they are stuck, because then you could just rack up the LocalVar off one switch.

And I could be wrong, but I think that with the old code, if they aren't stuck, it won't work, because it may call the LeverState after you let it go, which although would be 1, it comes back to 0.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
03-31-2014, 02:03 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#7
RE: Levers Script

Yeah in your case making them stuck would be required, or else the whole thing could be solved by just pulling 1 lever again and again.

Also, yes the old one would be like that depending on what levers you use. Some levers revert back to the middle position, which would cause them to go back to state 0. Some levers stay in their location though, like the control room piston lever.
Perhaps that's the problem here. Hanna, do your levers jump back to the middle?

03-31-2014, 02:15 PM
Find
MsHannerBananer Offline
Member

Posts: 218
Threads: 34
Joined: Sep 2013
Reputation: 10
#8
RE: Levers Script

@Mudbill

It actually is intentional for the levers to be pulled and remain stuck after use. The idea is more complex than just arriving at a map and pulling them down to progress.

What actually happens is in a hub, there are 8 accessible area's, 7 of them have scripted events that simulate turning off the power. These events all set their own Global Variables to 1, and the switches related to them check for those. If their variable equals what it's supposed to, the switch's StaticState is supposed to be set to false, but for quicker testing, I didn't include this all in the script I'm currently trying to figure out.

Once all the switches are pulled into place, you're able to pull down the last main switch, which ultimately allows the player to progress.

I haven't tried it with the traditional Amnesia switches, however I do know that the imported switches do work with script. Big Grin I have several functions that really on the ConnnectionStateCallback and "if" statements to run PlaySound, SetPropStatic and other things.


@Romulator

It's not being mean at all! I know I suck with scripting, so I always look to find the simplest way around my problems, haha. I take any and all help I can get. I don't mind if the code is extensive, a lot of the code I have could be considered extensive anyway.

I never got to try doing things with global/local variables last night, so I'm going to try that before anything else. I'll edit this if I'm still having problems.

Thank you guys, you've saved my bacon sooooo many times.

(This post was last modified: 03-31-2014, 08:15 PM by MsHannerBananer.)
03-31-2014, 08:15 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#9
RE: Levers Script

Well, if you'd like to stuck your levers when you pull them, just add the
PHP Code: (Select All)
SetLeverStuckState(asEntityLeverStatefalse); 
before your whole if-statement. That will just make so that every lever will remain where it is, once it's pulled.

(This post was last modified: 03-31-2014, 10:44 PM by Mudbill.)
03-31-2014, 10:44 PM
Find
MsHannerBananer Offline
Member

Posts: 218
Threads: 34
Joined: Sep 2013
Reputation: 10
#10
RE: Levers Script

Alright, so, as it turns out, it's not the levers. It's somewhere in my script that's conflicting with what I want done. I traded the switches for the traditional Amnesia levers, and it still isn't calling. I'm gonna go through and clean up my script, probably rewrite it, and see if I still run into problems.

04-01-2014, 12:04 AM
Find




Users browsing this thread: 1 Guest(s)