Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Scares
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#21
RE: Random Scares

(04-23-2013, 06:48 PM)BeeKayK Wrote:
Spoiler below!

if(asTimer == "PlayerAh")
{
int AhVariable = RandInt(1, 2)
switch(AhVariable)
{
case 1:
PlaySoundAtEntity("Aaaah1", "player_react_guardian1.snt", "Player", 0, false);
AddTimer("PlayerAh", RandInt(10, 20), "Ambience");
break;

case 2:
PlaySoundAtEntity("Aaaah2", "player_react_guardian2.snt", "Player", 0, false);
AddTimer("PlayerAh", RandInt(10, 20), "Ambience");
break;
}
}

This is my script.
Why am i getting an error, that it expected a ; at the highlighted text?

Don't worry, this is not my whole script file. I know this single passage wouldn't work in any way. It's a part of a timer, as you see in the top of the script

JAP already solved the issue, but to explain the error a little....

It was saying there was an issue at the line directly below where the actual problem was.

int AhVariable = RandInt(1, 2)

The compiler reads this line, but because there is no ; at the end, it does not know where the line ends. As far as the compiler knows, the next line down is part of the same statement.
To the compiler it looks like this
int AhVariable = RandInt(1, 2) switch(AhVariable) {

The error is generated because it was expecting to the have the statement terminated by the ;
switch(int) { is not a valid part of a statement, so it throws the error on this line.


tl;dr - the line number given in the error message is approximate, with this particular error, it tends to be the line above

(04-24-2013, 04:50 PM)BeeKayK Wrote: I tried. Now just nothing happens

Can you post the whole function?

(This post was last modified: 04-24-2013, 04:58 PM by Adrianis.)
04-24-2013, 04:56 PM
Find
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#22
RE: Random Scares

(04-24-2013, 04:56 PM)Adrianis Wrote: The compiler reads this line, but because there is no ; at the end, it does not know where the line ends. As far as the compiler knows, the next line down is part of the same statement.
To the compiler it looks like this
int AhVariable = RandInt(1, 2) switch(AhVariable) {

The error is generated because it was expecting to the have the statement terminated by the ;
switch(int) { is not a valid part of a statement, so it throws the error on this line.


tl;dr - the line number given in the error message is approximate, with this particular error, it tends to be the line above
Okay, well if this is the case, how do we resolve the issue. Like I just can't figure out how to fix it. I keep getting the same error.

It tells me the expected ';' or ',' is for line 117. This is my script:
void PlrCollideSwitch(string &in asParent, string &in asChild, int alState)
{
    int RandomScare = RandInt(1, 5)
    switch(RandomScare) *LINE 117
    {
    case 1:
    //Scare 1
        GiveSanityDamage(40, true);
        PlaySoundAtEntity("scarecase1", "scare_breath.snt", "Player", 3.0f, False);
        break;
    case 2:
    //Scare 2
        {
        AddEntityCollideCallback("Player", "scarecase2", "Push", true, 1);
        }
        void Push(string &in asParent, string &in asChild, int alState)
            {
            GiveSanityDamage(40, true);
            PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
            AddPlayerBodyForce(30000, 0, 0, false);
            }
        break;
    case 3:
    //Scare 3
        {
        AddEntityCollideCallback("Player", "scarecase3", "Throw", true, 1);
        }
        void Throw(string &in asParent, string &in asChild, int alState)
            {
            GiveSanityDamage(40, true);
            AddPropForce("throwhelmet", -28.5, 4, 6, "mylordscurse_1");
            }
        break;
    case 4:
    //Scare 4
        GiveSanityDamage(40, true);
        PlaySoundAtEntity("scarecase4", "scare_walk_hallway.snt", "Player", 3.0f, False);
        break;
    case 5:
    //Scare 5
        GiveSanityDamage(40, true);
        SetPlayerCrouching(True);
        FadeSepiaColorTo(10, 3.0f);
        PlaySoundAtEntity("scarecase5", "react_scare.snt", "Player", 3.0f, False);
        break;
    }
}
(This post was last modified: 05-07-2013, 04:23 AM by RurouniMori.)
05-07-2013, 04:22 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#23
RE: Random Scares

Have you added a ; at said line?

"Veni, vidi, vici."
"I came, I saw, I conquered."
05-07-2013, 04:30 AM
Find
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#24
RE: Random Scares

(05-07-2013, 04:30 AM)JustAnotherPlayer Wrote: Have you added a ; at said line?

I have, it proceeds to tell me Expected '}' at the very last line of my script. :/ Ah, I'm sucha noob. I've come so far on it already and I thought it would be nice to jazz it up with something more random.

EDIT: And before this, my script worked perfectly fine, no issues. So I decided to just not do the random event, my script has changed since.
(This post was last modified: 05-07-2013, 05:24 AM by RurouniMori.)
05-07-2013, 04:47 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#25
RE: Random Scares

void PlrCollideSwitch(string &in asParent, string &in asChild, int alState)
{
    int RandomScare = RandInt(1, 5);
    switch(RandomScare)
    {
    case 1:
    //Scare 1
        GiveSanityDamage(40, true);
        PlaySoundAtEntity("scarecase1", "scare_breath.snt", "Player", 3.0f, False);
        break;
    case 2:
    //Scare 2
        {
        AddEntityCollideCallback("Player", "scarecase2", "Push", true, 1);
        }
        void Push(string &in asParent, string &in asChild, int alState)
            {
            GiveSanityDamage(40, true);
            PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
            AddPlayerBodyForce(30000, 0, 0, false);
            }
        break;
    case 3:
    //Scare 3
        {
        AddEntityCollideCallback("Player", "scarecase3", "Throw", true, 1);
        }
        void Throw(string &in asParent, string &in asChild, int alState)
            {
            GiveSanityDamage(40, true);
            AddPropForce("throwhelmet", -28.5, 4, 6, "mylordscurse_1");
            }
        break;
    case 4:
    //Scare 4
        GiveSanityDamage(40, true);
        PlaySoundAtEntity("scarecase4", "scare_walk_hallway.snt", "Player", 3.0f, False);
        break;
    case 5:
    //Scare 5
        GiveSanityDamage(40, true);
        SetPlayerCrouching(True);
        FadeSepiaColorTo(10, 3.0f);
        PlaySoundAtEntity("scarecase5", "react_scare.snt", "Player", 3.0f, False);
        break;
    }
}

Fixed.

"Veni, vidi, vici."
"I came, I saw, I conquered."
05-17-2013, 12:19 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#26
RE: Random Scares

Apologies for the late reply, that code isn't fixed JAP...

case 2:
....

    //Scare 2
        {
        AddEntityCollideCallback("Player", "scarecase2", "Push", true, 1);
        }
        void Push(string &in asParent, string &in asChild, int alState)
            {
            GiveSanityDamage(40, true);
            PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
            AddPlayerBodyForce(30000, 0, 0, false);
            }
        break;
....

This bit of code is wrong - You don't need any curly braces { } inside of each Case statement, the code block for the Case statement is defined within the space between the keyword 'case [int]:' and 'break;'

case 3: CODE HERE
CODE HERE
break;

(the break; keyword is not strictly necessary, but it is needed in order to stop the flow of the case statements before it starts executing code from the other cases)

^ That is all explained in JAP's original post, underneath the code sample

You also cannot define a function within the code block of a case statement, as you do here
void Push(string &in asParent, string &in asChild, int alState)
{
code
}

Now, I'm not sure exactly what event you are trying to set up, but the code that JAP kindly provided is not as simple to use as it might appear - I highly recommend you learn about how switch...case statements work before attempting to use this method. I say that for your benefit, this will cause more headaches then it will solve
There an explanation of how they work here...
http://www.angelcode.com/angelscript/sdk...ments.html

(This post was last modified: 05-20-2013, 06:55 PM by Adrianis.)
05-20-2013, 06:49 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#27
RE: Random Scares

(05-20-2013, 06:49 PM)Adrianis Wrote: Apologies for the late reply, that code isn't fixed JAP...

case 2:
....

    //Scare 2
        {
        AddEntityCollideCallback("Player", "scarecase2", "Push", true, 1);
        }
        void Push(string &in asParent, string &in asChild, int alState)
            {
            GiveSanityDamage(40, true);
            PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
            AddPlayerBodyForce(30000, 0, 0, false);
            }
        break;
....

This bit of code is wrong - You don't need any curly braces { } inside of each Case statement, the code block for the Case statement is defined within the space between the keyword 'case [int]:' and 'break;'

case 3: CODE HERE
CODE HERE
break;

(the break; keyword is not strictly necessary, but it is needed in order to stop the flow of the case statements before it starts executing code from the other cases)

^ That is all explained in JAP's original post, underneath the code sample

You also cannot define a function within the code block of a case statement, as you do here
void Push(string &in asParent, string &in asChild, int alState)
{
code
}

Now, I'm not sure exactly what event you are trying to set up, but the code that JAP kindly provided is not as simple to use as it might appear - I highly recommend you learn about how switch...case statements work before attempting to use this method. I say that for your benefit, this will cause more headaches then it will solve
There an explanation of how they work here...
http://www.angelcode.com/angelscript/sdk...ments.html

What Adrianis said. Even though it looks kind of easy, it's actually very hard.

"Veni, vidi, vici."
"I came, I saw, I conquered."
05-21-2013, 02:19 AM
Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#28
RE: Random Scares

(04-16-2013, 03:10 PM)JustAnotherPlayer Wrote: Hello everyone! I've used this technique in my custom story, A Forgotten Memory. Special thanks for people that helped me to understand this. Using this will randomize the scares you will have. This gives the CS/FC replay value.

It's like this, each playthrough had different results. Example;
First Playthrough : You pass out and wakes up in some other place.
Second Playthrough : A door blew open.

It's good. Why? Because the Player will think like he knew, but he didn't.

Okay, enough with the chattering. Let's start.

PHP Code: (Select All)
void OnStart()
{
AddEntityCollideCallback("Player""ScriptArea_1""PlrCollideSwitch"true1);
}

void PlrCollideSwitch(string &in asParentstring &in asChildint alState)
{
int x RandInt(15);
switch(
x)
{
case 
1:
//Scare 1
    
break;
case 
2:
//Scare 2
    
break;
case 
3:
//Scare 3
    
break;
case 
4:
//Scare 4
    
break;
case 
5:
//Scare 5
    
break;
}

Get it? Integer is RandInt, and it will randomize between 1 and 5 as 1 is the minimal and 5 is the maximal. If one of the cases fit with the inputInteger, it will do that case until the first break is reached. For this, you don't need curly brackets({}) to envelope code, but you need breaks.
Just change the
//Scare #CaseNumber
to what scare you want.

Even nobody including you (the creator) will know which one is picked.
This will give your custom story/full conversion replay value.

OFF-TOPIC:
Even Scares are now can be randomized. I'm so smart.

EDIT:
It seems like the script gives everyone an error. I already changed it and now tell me if it works or not.

Do I simply copy this into my hps or do I have to change some things?

-Grind to the Gore-
07-21-2013, 11:22 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#29
RE: Random Scares

Just copy it.

"Veni, vidi, vici."
"I came, I saw, I conquered."
07-21-2013, 11:30 AM
Find
GoreGrinder99 Offline
Member

Posts: 166
Threads: 47
Joined: Feb 2013
Reputation: 1
#30
RE: Random Scares

(07-21-2013, 11:30 AM)JustAnotherPlayer Wrote: Just copy it.

I don't need to make a script area on my map for the event to happen at?

-Grind to the Gore-
07-21-2013, 11:50 AM
Find




Users browsing this thread: 3 Guest(s)