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 Some complex issue (SOLVED)
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#1
Some complex issue (SOLVED)

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.

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.

Derp.
(This post was last modified: 08-16-2014, 10:58 PM by Neelke.)
08-16-2014, 01:19 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#2
RE: Some complex issue

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

Trying is the first step to success.
08-16-2014, 02:32 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#3
RE: Some complex issue

Well, basically this is for the guardian walking forward. GuardianGroundEffect sets the particle and sound it generates. FadeInGuardianLight sets a pointlight to red.

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.

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.

//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?

Derp.
(This post was last modified: 08-16-2014, 12:40 PM by Neelke.)
08-16-2014, 12:07 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Some complex issue

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: (Select All)
int iRandom RandInt(02);

if(
alLumpIdx && iRandom == 0

If that's not the issue, could you post the crash report as well?

(This post was last modified: 08-16-2014, 03:45 PM by Mudbill.)
08-16-2014, 03:44 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#5
RE: Some complex issue

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: (Select All)
//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.
(This post was last modified: 08-16-2014, 07:26 PM by TheGreatCthulhu.)
08-16-2014, 07:25 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#6
RE: Some complex issue

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.

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

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.

Derp.
08-16-2014, 10:41 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#7
RE: Some complex issue (SOLVED)

(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: (Select All)
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: (Select All)
// 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: (Select All)
//Extra events depending on the step
    
alLumpIdx GetLocalVarInt(sEvent);    // NOTE: removed the "int" 
08-17-2014, 01:11 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#8
RE: Some complex issue (SOLVED)

(facepalm) Man, sometimes you just don't know what you're doing. Thanks man XD

Derp.
08-17-2014, 02:16 PM
Find




Users browsing this thread: 2 Guest(s)