Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
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.
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;
}
}
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.