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 Switch (Case/Break thingy)
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#1
Switch (Case/Break thingy)

"Noob" question time!

Sorry, this is the first time I've tried to use this, so I probably did something stupid-obvious wrong.
Spoilers for possible length issues
Spoiler below!

What should be happening: 1. The player goes through the dream 2. Answering machine ends dream 3. Player slowly opens eyes/blinks and rolls over 4. Player sits up (phone_2 starts around here) 5. Player stands up 6. Player takes a step forward 7. Player is set active so the person can control him (phone_3 starts a little while after)
What's happening: The player goes through the 'dream' sequence all well and lovely, it fades out, lucid_phone_1 and lucid_phone_2 plays, screen still hasn't faded in. The last music, lucid_phone_3, gets stuck on look and the player is in a black-out coma. If left running for more than 15 minutes on the script, the game crashes.

I removed irrelevant parts of the script. If you think it would all be useful for answering the question, let me know so I can post all 221 lines (which could probably be condensed a lot, but I'm too lazy).

PHP Code: (Select All)
void OnStart()
{
    
AddTimer("timer_wakeup"30.0f"timer_wakeup");
    
AddTimer("timer_enddream"25.0f"timer_enddream");
    
StartPlayerLookAt("area_entitylook"1.0f2.0f"");
    
SetPlayerMoveSpeedMul(0.5f);
    
SetPlayerRunSpeedMul(0.5f);
    
PlayMusic("lucid_dream"false101false);
    
SetGlobalVarInt("NightTriggered"0);
}

void Intro()
{

}

void OnEnter()
{

}

////////////////////////////////////
//////////////SCRIPTS///////////////
////////////////////////////////////
void script_standup(string &in asParentstring &in asChildint alState)
{
    
SetLocalVarInt("var_walking"1);
    
SetPlayerCrouching(false);
    
    
AddTimer("timer_setplayeractive"0.5f"timer_setplayeractive");
}

////////////////////////////////////
///////////////TIMERS///////////////
////////////////////////////////////

void timer_setplayeractive(string &in asTimer)
{
    
SetPlayerActive(true);
    
    
StopPlayerLookAt();
    
FadeImageTrailTo(0.5f0.4f);
    
FadeRadialBlurTo(0.0f0.02f);
}

void timer_enddream(string &in asTimer)
{
    
FadeOut(1.0f);
    
StopPlayerLookAt();
    
SetPlayerActive(false);
    
SetPlayerMoveSpeedMul(1.0f);
    
SetPlayerRunSpeedMul(1.0f);
    
PlayMusic("lucid_phone_1"false102false);
    
StopMusic(0,1);
}

void timer_wakeup(string &in asTimer)
{
    
AddTimer("timer_phone2"20.0f"timer_phone2"); //start next phone message
    
AddLocalVarInt("var_wakup"1);
    
float SectionSpeed 0.0f//define SectionSpeed
    
    
switch (GetLocalVarInt("var_wakeup"))
    {
        case 
1//Teleporting player and setting up sequence
            
TeleportPlayer("PlayerStartArea_2"); //Moves player from castle to bed
            
SetPlayerCrouching(true); //places the player on the bed sheeds
            
AddEntityCollideCallback("Player""area_standup""script_standup"true1); //makes player stand up
            
MovePlayerHeadPos(0.8f, -0.8f0.0f20.0f1.0f); //player's head is on the bed
            
FadePlayerRollTo(-90.0f150.0f200.0f); //player is looking at ceiling
        
            
SectionSpeed 4.0f;
        break;
        
        case 
2:    //I don't remember why I needed this since the same thing is in the last case, but I'm leaving it in to be safe
            
FadePlayerRollTo(-90.0f1.0f1.0f);
    
            
SectionSpeed 0.5f;
        break;
    
        case 
3//fade in, blurry eyes
            
FadeIn(1.3f);
            
StartScreenShake(0.02f ,0.0f0.3f1.0f);
            
FadeRadialBlurTo(0.03f1.5f);
            
FadePlayerFOVMulTo(1.3f1.7f);
            
            
SectionSpeed 1.5f;        
        break;
    
        case 
4//fade out again
            
FadeOut(2.3f);
            
FadeRadialBlurTo(0.01f0.01f);
                
            
SectionSpeed 2.75f;
        break;
        
        case 
5//fade in, still blurry
            
FadeIn(2.5f);
            
FadeRadialBlurTo(0.03f0.02f);
            
FadePlayerFOVMulTo(0.75f0.2f);
        
            
SectionSpeed 2.75f;
        break;
    
        case 
6//blinking - kind of
            
FadeOut(2.0f);
            
FadeRadialBlurTo(0.01f0.01f);
        
            
SectionSpeed 2.5f;
        break;
    
        case 
7//opening eyes, a little blurry still
            
FadeIn(2.0f);
            
FadeRadialBlurTo(0.03f0.03f);
        
            
SectionSpeed 2.5f;
        break;

        case 
8//Roll over and sit
            
FadePlayerFOVMulTo(1.0f3.4f);
            
MovePlayerHeadPos(0.0f0.0f0.0f0.4f0.1f);
            
FadePlayerRollTo(05.0f23.0f);
            
StartPlayerLookAt("area_look1"2.0f4.0f""); //Floor
            
FadeRadialBlurTo(0.01f0.01f);
        
            
PlaySoundAtEntity("sound_rustle""player_climb.snt""Player"0.0ffalse);
        
            
SectionSpeed 3.25f;
        break;

        case 
9//stand up
            
MovePlayerForward(0.075f);
            
AddTimer("timer_standup"0.5f"timer_standup");
            
PlaySoundAtEntity("sound_standing""player_stand.snt""Player"0.0ffalse);
            
StartPlayerLookAt("area_look2"1.25f3.75f""); //Wall
            
AddTimer("timer_setplayeractive"0.25"timer_setplayeractive");
        
            
SectionSpeed 0.0f;
        break;
    }
    
    if (
GetLocalVarInt("var_wakeup") <9)
    {
        
AddTimer("timer_wakeup"SectionSpeed"timer_wakeup"); 
    }
}

void timer_standup(string &in asTimer//causes player to take a step
{
    
MovePlayerForward(0.075f);
}

void timer_phone2(string &in asTimer)
{
    
StopMusic(0,2);
    
PlayMusic("lucid_phone_2"false103false);
    
AddTimer("timer_phone3"23.0f"timer_phone3");
}

void timer_phone3(string &in asTimer)
{
    
StopMusic(0,3);
    
PlayMusic("lucid_phone_3"false104false);
}

void timer_stoplook(string &in asTimer)
{
    
StopPlayerLookAt();

My apologies if the inconsistencies in my scripting are confusing. They're caused by the change in experience; this was the second map I scripted and I just came back to it after writing 4 other map scripts and starting ENGG 233 (Computing for Engineers - it's a computer software course based around C++).

I'm sorry if this question's been answered a million times, I tried searching "case break" on the forum to double-check, but I couldn't find anything that might be similar to my problem (usually, I have to actually do something to understand it :p).

Thanks for the help - in case I forget to thank you personally for some reason.

[Image: quote_by_rueppells_fox-d9ciupp.png]
(This post was last modified: 09-25-2013, 07:58 AM by CarnivorousJelly.)
09-25-2013, 07:55 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#2
RE: Switch (Case/Break thingy)

I don't see you even calling StartPlayerLookAt yet you're using StopPlayerLookAt.

Also, the reason why it's not working, you have to match the same number var with the case number.

"Veni, vidi, vici."
"I came, I saw, I conquered."
09-25-2013, 08:40 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#3
RE: Switch (Case/Break thingy)

Inside your function timer_wakeup you have a name of a variable wrong:
The counter++ AddLocalVarInt("var_wakup", 1);
And the check at the bottom if (GetLocalVarInt("var_wakeup") <9)



Since var_wakeup it's gonna return 0, the timer is gonna get called every time.
Additionally, since the switch function above failed to find any match after case 9, the variable SectionSpeed remains with 0.0f, as it was initially declared, creating an infinite timer.

And when your computer can't handle it, it crashes.

(This post was last modified: 09-25-2013, 12:01 PM by Daemian.)
09-25-2013, 12:00 PM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#4
RE: Switch (Case/Break thingy)

(09-25-2013, 08:40 AM)JustAnotherPlayer Wrote: I don't see you even calling StartPlayerLookAt yet you're using StopPlayerLookAt.
"StartPlayerLookAt("area_entitylook", 1.0f, 2.0f, "");" (L5)
" StartPlayerLookAt("area_look1", 2.0f, 4.0f, ""); //Floor" (L5 of Case 8)
There's at least two places I used StartPlayerLookAt... but that's not the point, so I'm going to move on.
(09-25-2013, 08:40 AM)JustAnotherPlayer Wrote: Also, the reason why it's not working, you have to match the same number var with the case number.
Care to elaborate on what you mean? Like I said: first time using case/break and I barely know what I'm doing.

(09-25-2013, 12:00 PM)Amn Wrote: Inside your function timer_wakeup you have a name of a variable wrong:

The counter++ AddLocalVarInt("var_wakup", 1);

And the check at the bottom if (GetLocalVarInt("var_wakeup") <9)

Since var_wakeup it's gonna return 0, the timer is gonna get called every time.

Additionally, since the switch function above failed to find any match after case 9, the variable SectionSpeed remains with 0.0f, as it was initially declared, creating an infinite timer.

And when your computer can't handle it, it crashes.
Ohhhhhh I didn't notice the typo D: Well, that's embarrassing c: Thank you!

[Image: quote_by_rueppells_fox-d9ciupp.png]
09-25-2013, 06:37 PM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#5
RE: Switch (Case/Break thingy)

So...it's working now then I assume? Or still having problems?

[Image: Tv0YgQb.gif]
Image by BandyGrass
(This post was last modified: 09-25-2013, 06:52 PM by Kreekakon.)
09-25-2013, 06:48 PM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#6
RE: Switch (Case/Break thingy)

It's working now, I just tested it! Sorry, should have clarified that in my last post c:

[Image: quote_by_rueppells_fox-d9ciupp.png]
09-25-2013, 07:04 PM
Find




Users browsing this thread: 2 Guest(s)