Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

• 2 Votes - 3 Average
• 1
• 2
• 3
• 4
• 5
Kyle
Posting Freak

Posts: 910
Joined: Sep 2010
Reputation: 7
 Post: #1 Scripting Answers This is where I will help describe scripting and create useful examples of it. I will try my best. If I forget something, please post it. "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Chinese Proverb These are some words that apply to scripting. Spoiler below! bool = This is a true/false statement. It is used mostly to check to see something. True meaning yes, false meaning no. int = This is an integer. It is a whole number that can be positive or negative. Examples: 1, 6, 32, -8, 0, -43 float = This is a whole number and some more left after it. Examples: 1.2, 3.23, 53234.3, -443.1, -323.1 string = This is a word or phrase. It is not a number. You can think of it as a string of characters. Examples: Hello, Hello World, How are you "" = This is used to go around strings to seperate them from other things, so the game can recognize that a phrase is being used instead of a word. Examples: "Hello", "Hello World", "How are you" void = This is used at the beginning of functions. It means that nothing is before it, aside from using int, bool, or string. Examples: void OnStart(), void OnEnter(), void OnLeave(), void CollideRoomTwo() == = This is used for when something equals something else in an "if" statement or an "else if" statement. It literally means "equal to". Examples: x == a, t + 1 == x != = This is used when something does not equal something else in an "if" statement or an "else if" statement. Examples: x != a, 2 != 3 && = This is an "and" symbol. It is used mostly when asking for multiple things. Example: for(int i = 1; i > 0 && i < 11; i++) || = This is an "or" symbol. It is used for asking multiple things and if one of them is true, then whatever you want happens aside from it being false. if = This is an "if" statement. It is used when you are going to ask something. Example: if (x == a) { [whatever you want here] } else = This is an "else" statement. It is used when something of an "if" statement isn't true, then it will do that. Example: if (x == a) { } else { [do what ever would happen instead if x doesn't equal a] } else if = This is an "else if" statement. It is used when you want to ask if another thing is true if the "if" statement was false. Example: if (x == a) { } else if (x == b) { [What ever you want to happen if x == b && x != a] } for = This is a "for" statement. It is used mostly when creating multiple instances of something. Example: for (x = 1; x > 5 && x < 0; x++) { AddTimer("timer"x, x * 1.5, "TimerFunction01") } < = This is a less than sign. > = This is a greater than sign. <= = This is a less than or equal to sign. >= = This is a greater than or equal to sign. ++ = This adds 1 to a number. Example: x++ -- = This subtracts 1 to a number. Example: x-- Scope = This term refers to the access a variable has to the whole network of scripts within your custom story files. Examples: int x in a function stays within that function. x would become undefined if attempted to be used within another function. SetLocalVarInt("Variable", 1); is like saying x = 1, but it can be used all within the script. SetGlobalVarInt("Variable", 1); is the same thing but can be used within all the scripts within your custom story folder. Need global.hps to work. See below. // = This is used to signal that all text to the right of it will be notes and will not conflict with the script itself. /* = This is used to signal that all text to right and underneath it will become notes. This can be useful for typing paragraphs at the beginning to explain a script or ideas or organization. Only stopped by */ */ = This is used to stop a /* from turning things into notes, so the space between /* and */ will all be notes. OnStart() Scripts Preloading and Music Spoiler below! Preloading prevents a moment of lag when the Sound/ParticleSystem is played in the game. The music helps make the game more mysterious than what it may already be. Code: (Select All) ```void OnStart() {      PreloadParticleSystem("ParticleSystemFile.ps");      PreloadSound("SoundFile.snt");      PlayMusic("MusicFile.ogg", true, 1, 2, 1, false); }``` Variable and Random Scripts Organized Timer Spoiler below! Code: (Select All) ```void OnStart() {      for (x = 1; x > 0 && x < 6; x++)      {           AddTimer("timer"x, x * 2, "Function01");      } } void Function01(string &in asTimer) {      int x = asTimer;      if (x == "timer1")      {           [whatever you want to happen here]           return;      }      else if (x == "timer2")      {           [whatever you want to happen here]           return;      }      else if (x == "timer3")      {           [whatever you want to happen here]           return;      }      else if (x == "timer4")      {           [whatever you want to happen here]           return;      }      else if (x == "timer5")      {           [whatever you want to happen here]           return;      } }``` Random Patrol Nodes Spoiler below! Code: (Select All) ```void OnStart() {      AddEntityCollideCallback("Player", "ScriptArea_1", "Function01", true, 1); } void Function01(string &in asParent, string &in asChild, int alState) {      SetEntityActive("MonsterName", true);      int x = RandInt(0, 4);      for (int y = 1; y > 0 && y < 11; y++)      {           AddEnemyPatrolNode("MonsterName", "PathNode_"+y, x, "");      } }``` Don't worry, this thread will be updated occasionally. I will make sure I add almost any sort of script commands, statements, functions, or entire scripts. Illumination (This post was last modified: 05-22-2011 09:17 PM by Kyle.)
05-10-2011 07:03 PM
Simpanra
Senior Member

Posts: 314
Joined: Mar 2011
Reputation: 0
 Post: #2 RE: Scripting Answers yo =) ok so i have tried using the "ui_terror_meter" sound file (it is the high pitch noise you hear when being chased) to simulate a chase (so you think something is there but nothing is), i used the PlaySoundAtEntity function for this. However, StopSound doesnt manage to cancel it =( I then tried the PlayGuiSound function but this still wasnt cancelled by the StopSound function. I am now resorting to playing it as a music file =/ why wouldnt the StopSound work? =/
05-10-2011 07:21 PM
Kyle
Posting Freak

Posts: 910
Joined: Sep 2010
Reputation: 7
 Post: #3 RE: Scripting Answers I always wondered why it never worked, so don't think I know... :/ Illumination
05-10-2011 07:38 PM
Simpanra
Senior Member

Posts: 314
Joined: Mar 2011
Reputation: 0
 Post: #4 RE: Scripting Answers (05-10-2011 07:38 PM)Kyle Wrote:  I always wondered why it never worked, so don't think I know... :/ Thats ok =) It might be something to do with the sound file itself seeing as it is a pre-set for an actual event in game, it might not like being scripted =)
05-10-2011 07:58 PM
Delirium92
Senior Member

Posts: 262
Joined: Mar 2011
Reputation: 5
 Post: #5 RE: Scripting Answers Ok so this will start off being totally off topic but, i teach drums and i do session recording for a living, as a hobby i script and do level design using the UDK, ive got the hang of HPL and the script, i am trying to figure out the , for, if, else, else if, statements, so far this has told me what they mean, but your examples lack allot of elaboration, example: you have given examples but they lack context to me, like if i was teaching a student drums and i would play a drumbeat really fast and expect them to understand it, i would like to ask what are these statements used for? it needs more explanation other then just examples, im not having a go i just think you need to elaborate on the context is all.
07-26-2011 11:14 AM
Kyle
Posting Freak

Posts: 910
Joined: Sep 2010
Reputation: 7
 Post: #6 RE: Scripting Answers (07-26-2011 11:14 AM)Saffire192 Wrote:  Ok so this will start off being totally off topic but, i teach drums and i do session recording for a living, as a hobby i script and do level design using the UDK, ive got the hang of HPL and the script, i am trying to figure out the , for, if, else, else if, statements, so far this has told me what they mean, but your examples lack allot of elaboration, example: you have given examples but they lack context to me, like if i was teaching a student drums and i would play a drumbeat really fast and expect them to understand it, i would like to ask what are these statements used for? it needs more explanation other then just examples, im not having a go i just think you need to elaborate on the context is all. "if" statements are used in the same way people question things. If 1 + 1 = 2, then unlock a door. To make that a little more involved, I'll say that once the player collides with "Area1" and "Area2", then "Door1" is unlocked. Code: (Select All) ```void OnStart() {      SetLocalVarInt("Var01", 0);      AddEntityCollideCallback("Player", "Area1", "Func01", true, 1);      AddEntityCollideCallback("Player", "Area2", "Func01", true, 1); } void Func01(string &in asParent, string &in asChild, int alState) {      AddLocalVarInt("Var01", 1);      Func02(); } void Func02() {      if (GetLocalVarInt("Var01") == 2)      {           SetSwingDoorLocked("Door1", false, true);           PlaySoundAtEntity("", "unlock_door.snt", "Door1", 0, false);      } }``` I'll try a more "numberized" code. You also have to remember when putting the equal sign in an "if" statement, you need double equal signs ( == ). Code: (Select All) ```void OnStart() {      int x = 1, y = 2, z = 3;      if (x + y == 2)      {           x = x + 1;      }      else if (y - x + z == 1)      {           y = y + 2;      }      else      {           z = z - 1;      } }``` If I follow this correctly based on their value, x + y = 3, so the first statement is skipped, so it moves on to the second. y - x + z = 4, so the "else if" statement is wrong. Now we move on the "else" statement. Since the variables didn't equal correctly the way the "if" and "else if" statements were, it is forced to do what is in the "else" statement. So z = 2 now. I hope this helps at least somewhat. Illumination
07-26-2011 12:23 PM
Delirium92
Senior Member

Posts: 262
Joined: Mar 2011
Reputation: 5
 Post: #7 RE: Scripting Answers Now its becoming more clear to me, but is an "x", or a "y", or an "a" hold different values? or do you make them up, forgive me as im very bad when it comes to math and things such as that :/
07-26-2011 01:06 PM
HumiliatioN
Posting Freak

Posts: 984
Joined: Dec 2010
Reputation: 10
 Post: #8 RE: Scripting Answers Why this is not working? void OnStart() { AddEntityCollideCallback("Player", "BlowDoor", "BlowDoorFunction", true, 1); } void BlowDoorFunction(string &in asParent, string &in asChild, int alState) { AddTimer("aha", 0.1f, "OpenDoor"); AddTimer("aso", 0.3f, "OpenDoor"); StartPlayerLookAt("blow_door",3.0,1.0,""); } void OpenDoor(string &in asTimer) { if(asTimer == "aha"){ AddPropImpulse("blow_door", -0.5f, 0, 0.5f, "World"); GiveSanityDamage(20.0f,true); PlaySoundAtEntity("", "scare_tingeling.snt", "Player", 0, true); } if(asTimer == "aso"){ PlaySoundAtEntity("", "react_breath.snt", "Player", 0, true); StopPlayerLookAt(); } } Why when Area activates that door it has to be "Forced open" like begin normal Amnesia that ghostdoor Investigator - WIP
07-26-2011 01:12 PM
Delirium92
Senior Member

Posts: 262
Joined: Mar 2011
Reputation: 5
 Post: #9 RE: Scripting Answers (07-26-2011 01:12 PM)HumiliatioN Wrote:  Why this is not working? void OnStart() { AddEntityCollideCallback("Player", "BlowDoor", "BlowDoorFunction", true, 1); } void BlowDoorFunction(string &in asParent, string &in asChild, int alState) { AddTimer("aha", 0.1f, "OpenDoor"); AddTimer("aso", 0.3f, "OpenDoor"); StartPlayerLookAt("blow_door",3.0,1.0,""); } void OpenDoor(string &in asTimer) { if(asTimer == "aha"){ AddPropImpulse("blow_door", -0.5f, 0, 0.5f, "World"); GiveSanityDamage(20.0f,true); PlaySoundAtEntity("", "scare_tingeling.snt", "Player", 0, true); } if(asTimer == "aso"){ PlaySoundAtEntity("", "react_breath.snt", "Player", 0, true); StopPlayerLookAt(); } } Why when Area activates that door it has to be "Forced open" like begin normal Amnesia that ghostdoor well is your script area called BlowDoor? if so then try having the door open amount 2 or something. also you have allot of } one more thing i noticed you have this AddPropImpulse("blow_door", -0.5f, 0, 0.5f, "World"); i think the "-0.5f, 0, 0.5f," are conflicting and stoping the door from opening. (This post was last modified: 07-26-2011 01:23 PM by Delirium92.)
07-26-2011 01:16 PM
Kyle
Posting Freak

Posts: 910
Joined: Sep 2010
Reputation: 7
 Post: #10 RE: Scripting Answers Try this: Code: (Select All) ```void OnStart() { AddEntityCollideCallback("Player", "BlowDoor", "BlowDoorFunction", true, 1); } void BlowDoorFunction(string &in asParent, string &in asChild, int alState) { AddTimer("aha", 0.1, "OpenDoor"); AddTimer("aso", 0.3, "OpenDoor"); StartPlayerLookAt("blow_door", 3, 1, ""); } void OpenDoor(string &in asTimer) {      if(asTimer == "aha"){           AddPropImpulse("blow_door", -0.5f, 0, 0.5f, "World");           GiveSanityDamage(20.0f,true);           PlaySoundAtEntity("", "scare_tingeling.snt", "Player", 0, true);      }      if(asTimer == "aso"){           PlaySoundAtEntity("", "react_breath.snt", "Player", 0, true);           StopPlayerLookAt();      } }``` Illumination
07-26-2011 01:34 PM
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)