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 Not Working D:
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#1
Script Not Working D:

So I have a script that will count the number of ingredients in an area and will then activate a grunt if all the ingredients are present, but it's not working, and I don't know why....
void Grill(string &in asParent, string &in asChild, int alState)
{
    if(alState == 1)
    {
        if(GetLocalVarInt("NumBodyParts") == 3)
        {
            SetEntityActive("servant_grunt_1",true);
        }
        else
        {
            AddLocalVarInt("NumBodyParts",1);
        }
    }
    else
    {
        AddLocalVarInt("NumBodyParts",-1);
    }
}

With the callback functions

    AddEntityCollideCallback("corpse_male_leg_1","Grill","Grill",false,0);
    AddEntityCollideCallback("corpse_male_arm_1","Grill","Grill",false,0);
    AddEntityCollideCallback("corpse_male_torso_1","Grill","Grill",false,0);

I have used a "playGUIsound" function to test each part of the script above, and each section works except for the section within the
if(GetGlobalVarInt("NumBodyParts") == 3)
        {
            SetEntityActive("servant_grunt_1",true);
        }

It is running the other parts of the code, but either the AddLocalVarInt functions aren't working, or I need to somehow initialize the variable "NumBodyParts" and I do not know how to do this. (From what I could tell from looking at the other Amnesia scripts, this variable should create itself when I use the AddLocalVarInt function, though of course I could be wrong).

11-12-2010, 04:29 AM
Find
Arvaga Offline
Junior Member

Posts: 8
Threads: 1
Joined: Oct 2010
Reputation: 1
#2
RE: Script Not Working D:

If you check the functions list we have all this for variable management:
void  SetLocalVarInt(string& asName, int alVal);
void  SetLocalVarFloat(string& asName, float afVal);
// asVal has to be constant
void  SetLocalVarString(string& asName, string& asVal);

void  AddLocalVarInt(string& asName, int alVal);
void  AddLocalVarFloat(string& asName, float afVal);
void  AddLocalVarString(string& asName, string& asVal);

int  GetLocalVarInt(string& asName);
float  GetLocalVarFloat(string& asName);
string&  GetLocalVarString(string& asName);

void  SetGlobalVarInt(string& asName, int alVal);
void  SetGlobalVarFloat(string& asName, float afVal);
// asVal has to be constant
void  SetGlobalVarString(string& asName, string& asVal);

void  AddGlobalVarInt(string& asName, int alVal);
void  AddGlobalVarFloat(string& asName, float afVal);
void  AddGlobalVarString(string& asName, string& asVal);

int  GetGlobalVarInt(string& asName);
float  GetGlobalVarFloat(string& asName);
string&  GetGlobalVarString(string& asName);

Maybe you have to set it first with SetLocalVarInt. Or if that doesn't work try using GlobalVars.

Now I see you use AddLocalVarInt to add the values, but you are using GetGlobalVarInt, my guess is that it should be GetLocal and that you have to set the variable with SetLocalVar before using it.

Visit the scripts recollection thread to find scripts for your custom stories.
11-12-2010, 01:31 PM
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
#3
RE: Script Not Working D:

(11-12-2010, 01:31 PM)Arvaga Wrote: Now I see you use AddLocalVarInt to add the values, but you are using GetGlobalVarInt, my guess is that it should be GetLocal and that you have to set the variable with SetLocalVar before using it.

Nur, that last section of code was a mistake on my part. That was a copy/paste from when I was using global variables instead of local variables but switched it to local variables because that made more sense (and also because the global variables weren't working and I figured that the local variables might). If you look in the original code at the top, it does use the GetLocalVarInt() function. I have also tried adding SetLocalVariableInt("NumBodyParts",0) in the "Run first time starting map" section, but it didn't make a difference and none of the examples I have seen in the amnesia game code use this. Also the example here does not require this.

Humm, Problem solved... for some reason
if(GetLocalVarInt("NumBodyParts") == 3)
needed to be changed to
if(GetLocalVarInt("NumBodyParts") == 2)
I don't really understand this.... but it works now. :/

Edit again:
Duh, I know why. Because the if function is checking to see if there are 3 body parts in the grill BEFORE it's adding the third value to the function so... ok. It all makes sense now. Big Grin

(This post was last modified: 11-12-2010, 04:40 PM by Homicide13.)
11-12-2010, 04:19 PM
Find




Users browsing this thread: 1 Guest(s)