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
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#2
RE: Script help

void OnStart()
{
    for(int i=1;i<=4;i++) AddUseItemCallback("Chem"+i, "GetAcidComplete", "UsedChemsOnPot", true, 0);
    SetLocalVarInt("Var1", 0);
}

void UsedChemsOnPot(string &in asParent, string &in asChild, int alState)
{

    PlayGuiSound("16_lever_stuck", 0.3f);
    PlaySoundAtEntity("", "impact_metal_chain_med", "Player", 0.0f, false);
    
    if("asParent" == "Chem1" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    else if("asParent" == "Chem2" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    else if("asParent" == "Chem3" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    else if("asParent" == "Chem4" && GetLocalVarInt("Var1") == 1)
    {
        AddLocalVarInt("Var1", 1);
    }
    
    if(GetLocalVarInt("Var1") == 4)
    {
        PlayMusic("26_event_agrippa_head.ogg", false, 0.7, 0.1, 10, false);
    }
}

Several problems here

Firstly, the 'for' loop at the beginning of your script needs to be part of a function (it can't be loose in the script), for example OnStart like in my edited code above.

In the for loop, you start int i at 0, but you are running the loop whilst it is less than or equal to (<=) 4, which means it will run 5 times, so I changed it to 1 since you want to add the 1 to the names of the items. Also, in the last section of the for loop conditions you only had (i+), it needs to be (i++) which means (i + 1) in order to properly iterate.

I've added the SetLocalVarInt to OnStart, and changed all of the SetLocalVarInt's from within the if statements in 'UsedChemsOnPot', changed to AddLocalVarInt. The difference is that SetLocal...etc is telling the game "put the value of this variable to the number I specify", so it was constantly setting the value to 1, rather than adding 1 to the value as I think you wanted to. AddLocalVarInt is telling the game "add the number I specify to this variable", so it starts at 0 then adds 1 each time a chemical is used, eventually ending at 4 which is enough for the final if statement to run.


In the future, this kind of thread should be created in the 'Development Support' sub-forum Smile

Hope that works, let me know if your still getting problems with it.

EDIT: You changed it while I was writing Tongue
So, additionally, you need to not have "" around the conditions for the 'for' loop (conditions is the part in brackets)
You were also using too many braces '{}', you need to keep track of where the opening { and closing } are, so you don't include too many

(This post was last modified: 03-27-2013, 01:59 PM by Adrianis.)
03-27-2013, 01:56 PM
Find


Messages In This Thread
Script help - by Rakez68 - 03-27-2013, 01:36 PM
RE: Script help - by Adrianis - 03-27-2013, 01:56 PM
RE: Script help - by Rakez68 - 03-27-2013, 02:08 PM
RE: Script help - by Adrianis - 03-27-2013, 02:15 PM
RE: Script help - by Rakez68 - 03-27-2013, 02:46 PM
RE: Script help - by PutraenusAlivius - 03-27-2013, 02:55 PM
RE: Script help - by Rakez68 - 03-27-2013, 03:23 PM
RE: Script help - by PutraenusAlivius - 03-27-2013, 03:27 PM
RE: Script help - by Rakez68 - 03-27-2013, 03:39 PM
RE: Script help - by PutraenusAlivius - 03-27-2013, 03:40 PM
RE: Script help - by Rakez68 - 03-27-2013, 04:09 PM
RE: Script help - by Adrianis - 03-27-2013, 04:11 PM
RE: Script help - by Rakez68 - 03-27-2013, 04:50 PM
RE: Script help - by Adrianis - 03-27-2013, 05:44 PM



Users browsing this thread: 1 Guest(s)