Frictional Games Forum (read-only)

Full Version: Variable help needed PLEASE :'(
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello ,

I need help with a script -to do with variables, Ive never used them
before- and when the player interacts with a lever nothing happens when I want a message when door = 0 but nothing happens, I hope you can help Big Grin
Code:
//VARAIBLES
    AddLocalVarInt("door1", 0);
    //FUNCTIONS
    SetEntityPlayerInteractCallback("lever1", "used1", false);
Code:
void used1(string &in asParent, string &in asChild, int alState)
{
     if(GetGlobalVarInt("door1")==1)
    {
    SetSwingDoorLocked("metal_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "metal_1", 0, false);
    }
    else
    {
     PlayGuiSound("21/21_lever_fail.ogg", 1);
     SetMessage("Message", "mem8", 3);
     }
}
You know that you don't need to declare the variables?

AddLocalVarInt("door1", 0); // This will add 0 to the door1 variable, which means that it will do nothing.
(05-21-2011, 09:58 PM)nemesis567 Wrote: [ -> ]You know that you don't need to declare the variables?

AddLocalVarInt("door1", 0); // This will add 0 to the door1 variable, which means that it will do nothing.

What do you mean?
Do you really need a global variable in this case?

In your "void OnStart()", you could add this: SetLocalVarInt("door1", 0);

Then the place where you set it to 1, put this: SetLocalVarInt("door1", 1); or AddLocalVarInt("door1", 1);

This is what the used1 function should look like.

Code:
void used1(string &in asParent, string &in asChild, int alState)
{
     if (GetLocalVarInt("door1") == 1)
     {
          SetSwingDoorLocked("metal_1", false, true);
          PlaySoundAtEntity("", "unlcok_door", "metal_1", 0, false);
          return;
     }
     else
     {
          PlayGuiSound("21/21_lever_fail.ogg", 1);
          SetMessage("Message", "mem8", 3);
          return;
     }
}
}
(05-21-2011, 10:07 PM)Kyle Wrote: [ -> ]Do you really need a global variable in this case?

In your "void OnStart()", you could add this: SetLocalVarInt("door1", 0);

Then the place where you set it to 1, put this: SetLocalVarInt("door1", 1); or AddLocalVarInt("door1", 1);

This is what the used1 function should look like.

Code:
void used1(string &in asParent, string &in asChild, int alState)
{
     if (GetLocalVarInt("door1") == 1)
     {
          SetSwingDoorLocked("metal_1", false, true);
          PlaySoundAtEntity("", "unlcok_door", "metal_1", 0, false);
          return;
     }
     else
     {
          PlayGuiSound("21/21_lever_fail.ogg", 1);
          SetMessage("Message", "mem8", 3);
          return;
     }
}
}


Still nothing happens SD@Angry:R{AP!!!!!!
*feels like screaming!
It should work. Maybe if you shown a little more of your script I can be able to fix it all. :/