Frictional Games Forum (read-only)

Full Version: Some complex issue (SOLVED)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, this script worked perfectly before; I added something in and it doesn't work anymore. Since of my bad memory I can't remember what it was I added in. So, I'm taking some help from you guys.

Code:
void TimerGuardian(string &in asTimer)
{
    float fShadowLumpFadeMul = RandFloat(2.0, 3.0);
    float fShadowNewStep = 3.0f;
    float fDelayToEvent = 0.25f;
    
    //Set up a random scream (33% chance)
    if(alLumpIdx > 5 && RandInt(0,2)==0)
    {
        PlaySoundAtEntity("GuardianScream", "25_guardian_ontop.snt", "Player", 0, false);
    }
    
    //Reached final step, no need for further guardian sounds
    if(GetLocalVarInt(sEvent) == 12) return;
    
    //Configurables
    string sEvent = asTimer; //Sets the timer name to the variable name
    AddLocalVarInt(sEvent, 1); //Sets a variable to the guardians step
    string sDmgDeathArea = "AreaGuardianKill_" + GetLocalVarInt(sEvent); //Sets a new dmg area after each variable
    
    for(int i=1; i<=6; ++i) SetPropActiveAndFade("slime_"+GetLocalVarInt(sEvent)+"_"+i, true, fShadowLumpFadeMul);
    GuardianGroundEffect("AreaGuardianEffectFloor_"+GetLocalVarInt(sEvent), true);
    SetEntityActive(sDmgDeathArea, true);
    FadeInGuardianLight("ShadowLight_"+GetLocalVarInt(sEvent));
    
    StartScreenShake(0.1f, RandFloat(0.15f,0.6f), 0, 0.1);
    PlaySoundAtEntity("GuardianSplashSound", "25_guardian_slime_appear.snt", "Player", 0, false);
    
    AddTimer(sEvent, fShadowNewStep, "TimerGuardian");
    
    //Set checkpoint
    CheckPoint("reset", "PlayerStartArea_1", "ResetGuardian", "Hints", "DeathByWorm1");
    
    //Extra events depending on the step
    int alLumpIdx = GetLocalVarInt(sEvent);
    AddTimer("EventStep"+alLumpIdx, fDelayToEvent, "EventStep"+alLumpIdx);
}

And the custom scripts (such as GuardianGroundEffect) works perfectly. I can assure you.
Could you specify in details:

What's supposed to happen?

What's not happening?

Is it the whole script that's not happening, or is it just a small part? It's much easier to find something if you know what you're looking for Wink
Well, basically this is for the guardian walking forward. GuardianGroundEffect sets the particle and sound it generates. FadeInGuardianLight sets a pointlight to red.

Code:
AddTimer("EventStep"+alLumpIdx, fDelayToEvent, "EventStep"+alLumpIdx);

This here is for checking if there's some extra stuff supposed to be happening during this step. Like blowing out some candles for example.

Code:
void EventStep8(string &asX)
{
    for(int i=56; i<=60; ++i) SetLampLit("candle_floor_blue_no_light_"+i, false, true);
    for(int i=114; i<=117; ++i) SetLampLit("candle_floor_blue_no_light_"+i, false, true);
    
    SetLampLit("candle_floor_blue_11", false, true);
    SetLampLit("candle_floor_blue_20", false, true);
}

When the guardian has reached step 12, no more steps are made.

Don't know if you need anymore information.

This whole script worked before, but I added some extra finesses in and now it crashes the level. So yeah.

Well, found out the scripts which messed everything up.

Code:
//Set up a random scream (33% chance)
    if(alLumpIdx > 5 && RandInt(0,2)==0)
    {
        PlaySoundAtEntity("GuardianScream", "25_guardian_ontop.snt", "Player", 0, false);
    }
    
    //Reached final step, no need for further guardian sounds
    if(GetLocalVarInt(sEvent) == 12) return;

This here is wrong appearntly. Can you guys see anything wrong?
You might want to actually contain your RandInt in a variable. I don't think you can run void blocks within an if-statement. How about this?

PHP Code:
int iRandom RandInt(02);

if(
alLumpIdx && iRandom == 0

If that's not the issue, could you post the crash report as well?
That shouldn't cause the issue; the RandInt function returns an integer, so functionally the two variants of the code should be equivalent - if not, then it's a bug in the script engine (but I don't think that is the case). Try Mudbill's suggestion anyway, just in case.

After that - if you are sure that the lines of code you quoted are the ones that are causing the problem, you can pinpoint the source like this: first comment out just the "PlaySoundAtEntity" part (just place // in front), and see if the game crashes or not. If it does, than that line is the problem. If not, un-comment it, and comment out the "if(GetLocalVarInt(sEvent) == 12) return;" part, then run, and if the game doesn't crash, that line was the problem.

That said, that particular line looks suspicious to me, because of this:
PHP Code:
//Reached final step, no need for further guardian sounds
    
if(GetLocalVarInt(sEvent) == 12) return;
    
    
//Configurables
    
string sEvent asTimer//Sets the timer name to the variable name 

Note that sEvent is declared after it is used in the previous line of code. That shouldn't even compile.
The "string sEvent = asTimer;" part should come before the call to GetLocalVarInt.
That did it. Both Mudbill and TheGreat. What I find weird here though is the fact that I had to delete the alLumpIdx premanently. For some reason it refused to work no matter what I changed. This is how it looks right now.

Code:
int iRandom = RandInt(0,2);
    if(iRandom == 0)
    {
        PlaySoundAtEntity("GuardianScream", "25_guardian_ontop.snt", "Player", 0, false);
    }

Code:
string sEvent = asTimer; //Sets the timer name to the variable name
    AddLocalVarInt(sEvent, 1); //Sets a variable to the guardians step
    string sDmgDeathArea = "AreaGuardianKill_" + GetLocalVarInt(sEvent); //Sets a new dmg area after each variable
    
    //No need for further steps after 12
    if(GetLocalVarInt(sEvent) == 12) return;

The only thing here now that's making it worse is that the random guardian sound might be played at the first step, but I guess I gotta accept that as it is. Either way, it works. Thanks guys.
(08-16-2014, 10:41 PM)Neelke Wrote: [ -> ]What I find weird here though is the fact that I had to delete the alLumpIdx premanently. For some reason it refused to work no matter what I changed. [...] The only thing here now that's making it worse is that the random guardian sound might be played at the first step, but I guess I gotta accept that as it is.

That happens for the same reason: aLumpIdx is used near the top of the function, but the script engine doesn't know what it is since it is declared at the very bottom of the function
(where it says "int alLumpIdx = GetLocalVarInt(sEvent);").
But in this case, you can't simly move that line, because the script changes the local variable's value, so you still need to make the call to GetLocalVarInt.

Try something like this:
PHP Code:
void TimerGuardian(string &in asTimer)
{
    
float fShadowLumpFadeMul RandFloat(2.03.0);
    
float fShadowNewStep 3.0f;
    
float fDelayToEvent 0.25f;
    
    
string sEvent asTimer//Sets the timer name to the variable name
    
int alLumpIdx GetLocalVarInt(sEvent);
    
    
//If step > 5, set up a random scream (33% chance)
    
int iRandom RandInt(0,2);
    if(
alLumpIdx && iRandom == 0)
    {
        
PlaySoundAtEntity("GuardianScream""25_guardian_ontop.snt""Player"0false);
    }        
    
    
AddLocalVarInt(sEvent1); //Sets a variable to the guardians step
    
string sDmgDeathArea "AreaGuardianKill_" GetLocalVarInt(sEvent); //Sets a new dmg area after each variable
    
    //No need for further steps after 12
    
if(GetLocalVarInt(sEvent) == 12) return;
    
    for(
int i=1i<=6; ++iSetPropActiveAndFade("slime_"+GetLocalVarInt(sEvent)+"_"+itruefShadowLumpFadeMul);
    
GuardianGroundEffect("AreaGuardianEffectFloor_"+GetLocalVarInt(sEvent), true);
    
SetEntityActive(sDmgDeathAreatrue);
    
FadeInGuardianLight("ShadowLight_"+GetLocalVarInt(sEvent));
    
    
StartScreenShake(0.1fRandFloat(0.15f,0.6f), 00.1);
    
PlaySoundAtEntity("GuardianSplashSound""25_guardian_slime_appear.snt""Player"0false);
    
    
AddTimer(sEventfShadowNewStep"TimerGuardian");
    
    
//Set checkpoint
    
CheckPoint("reset""PlayerStartArea_1""ResetGuardian""Hints""DeathByWorm1");
    
    
//Extra events depending on the step
    
alLumpIdx GetLocalVarInt(sEvent);
    
AddTimer("EventStep"+alLumpIdxfDelayToEvent"EventStep"+alLumpIdx);


Unless I missed something, that should work.
These are the parts I changed:
PHP Code:
// NOTE: just reorganized the code and added one line
    
string sEvent asTimer//Sets the timer name to the variable name
    
int alLumpIdx GetLocalVarInt(sEvent);  // <-- NOTE: the added line
    
    //If step > 5, set up a random scream (33% chance)
    
int iRandom RandInt(0,2);
    if(
alLumpIdx && iRandom == 0)
    {
        
PlaySoundAtEntity("GuardianScream""25_guardian_ontop.snt""Player"0false);
    }        
    
    
AddLocalVarInt(sEvent1); //Sets a variable to the guardians step
    
string sDmgDeathArea "AreaGuardianKill_" GetLocalVarInt(sEvent); //Sets a new dmg area after each variable 

and
PHP Code:
//Extra events depending on the step
    
alLumpIdx GetLocalVarInt(sEvent);    // NOTE: removed the "int" 
(facepalm) Man, sometimes you just don't know what you're doing. Thanks man XD