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
#11
RE: Random Scares

(04-18-2013, 12:10 PM)Your Computer Wrote:
(04-18-2013, 11:11 AM)BeeKayK Wrote: can a switch script determine if the case has been used before?

Switch statements normally check against integer values, and an integer value isn't enough information to check if something has been used before. If statements check against boolean values, normally through the use of boolean operators or values that can be implicitly converted into a boolean value. Unfortunately, AngelScript scripting (at least the version that comes with Amnesia) doesn't implicitly convert other data types into boolean values for if statement conditions.

If I remember correctly it does convert integers to boolean values when evaluating an if condition, at least in terms of 0 being false and anything else being true, as in C, if that's what you meant.

(This post was last modified: 04-18-2013, 12:48 PM by Adrianis.)
04-18-2013, 12:40 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#12
RE: Random Scares

(04-18-2013, 12:40 PM)Adrianis Wrote: If I remember correctly it does convert integers to boolean values when evaluating an if condition, at least in terms of 0 being false and anything else being true, as in C, if that's what you meant.

If you test the code:

PHP Code: (Select All)
if(1){} 

You will get the error: Expression must be of boolean type. In C (and many other languages), that would be the same as writing:

PHP Code: (Select All)
if(true){} 

In HPL2 scripting, it's not.

Tutorials: From Noob to Pro
04-18-2013, 01:00 PM
Website Find
Adrianis Offline
Senior Member

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

Fair enough then, I thought I had some code in a test map on my home PC where I tried that out thinking it would be useful, but I guess not...

04-18-2013, 01:11 PM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#14
RE: Random Scares

(04-18-2013, 11:11 AM)BeeKayK Wrote: can a switch script determine if the case has been used before?

Correct me if I'm wrong, but I think you could add local (or global) variables and an "if" statement to restrict how many times/if the case is used more than once. I'm not entirely certain since I don't fully understand how the original script works.

What I think I'm saying up ^ there:
///*insert opening part of switch script here*////
if(GetLocalVarInt("Scare1Played") == 0)
{
       *insert the scare script*
       SetLocalVarInt("Scare1Played, 1);
}

if (GetLocalVarInt("Scare1Played") == 1)
{
   /////whatever else you want here/////
}
/////rest of script below/////

Is that in any way possibly right, or should I just go home and focus on mapping?

Edit: just realized I put the same == number, thanks Robosprog Smile

[Image: quote_by_rueppells_fox-d9ciupp.png]
(This post was last modified: 04-21-2013, 12:01 AM by CarnivorousJelly.)
04-19-2013, 05:57 AM
Find
Adrianis Offline
Senior Member

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

(04-19-2013, 05:57 AM)Kiandra Wrote:
Spoiler below!

(04-18-2013, 11:11 AM)BeeKayK Wrote: can a switch script determine if the case has been used before?

Correct me if I'm wrong, but I think you could add local (or global) variables and an "if" statement to restrict how many times/if the case is used more than once. I'm not entirely certain since I don't fully understand how the original script works.

What I think I'm saying up ^ there:
///*insert opening part of switch script here*////
if(GetLocalVarInt("Scare1Played") == 0)
{
       *insert the scare script*
       SetLocalVarInt("Scare1Played, 1);
}

if (GetLocalVarInt("Scare1Played") == 0)
{
   /////whatever else you want here/////
}
/////rest of script below/////

Is that in any way possibly right, or should I just go home and focus on mapping?


You can definately do it like that, but if you looking at having 5+ different events, all of which you need to keep track of, it's going to get very inneficient (but not really a problem*) to keep them all in seperate variables.

Doing it you're way would look more like...
void PlrCollideSwitch(string &in asParent, string &in asChild, int alState)
{
int x = RandInt(1, 5)
switch(x)
{
case 1:
    if (GetLocalVarInt("Scare1Done") == 0) {
    //Scare 1
    SetLocalVarInt("Scare1Done", 1);
    }
    break;
case 2:
    if (GetLocalVarInt("Scare2Done") == 0) {
    //Scare 2
    SetLocalVarInt("Scare2Done", 1);
    }
    break;
case 3:
etc etc...

* the possibility for hard-to-track bugs is pretty high doing it like that. It's ok if your ready for it

(This post was last modified: 04-19-2013, 09:53 AM by Adrianis.)
04-19-2013, 09:45 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#16
RE: Random Scares

Your's adrianis isn't enough.

You're gonna need a if(GetLocalVarInt("Variable") == 1) too to get
{
int x = RandInt(1, 5)
switch(x)

}

this again

Trying is the first step to success.
04-20-2013, 09:42 AM
Find
Adrianis Offline
Senior Member

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

(04-20-2013, 09:42 AM)BeeKayK Wrote: Your's adrianis isn't enough.

You're gonna need a if(GetLocalVarInt("Variable") == 1) too to get
{
int x = RandInt(1, 5)
switch(x)

}

this again

Not sure quite what you mean. The RandInt will be generated again if the function is called again.

If you're saying you need to repeat the RandInt call to get a number that has not been used already, that's a whole other issue.

04-20-2013, 08:23 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#18
RE: Random Scares

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

Trying is the first step to success.
(This post was last modified: 04-23-2013, 06:52 PM by FlawlessHappiness.)
04-23-2013, 06:48 PM
Find
PutraenusAlivius Offline
Posting Freak

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

(04-23-2013, 06:48 PM)BeeKayK Wrote: 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
TRY

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;
}
}

"Veni, vidi, vici."
"I came, I saw, I conquered."
04-24-2013, 08:24 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#20
RE: Random Scares

I tried. Now just nothing happens

Trying is the first step to success.
04-24-2013, 04:50 PM
Find




Users browsing this thread: 1 Guest(s)