Overview
This is guide for people new to Portal 2 Scripting!
Required Stuff
Notepadd++
[link]
Portal 2 Authoring Tools
Install through steam[http//steam]
Your first script!
Language which we will be using is squirrel. Open your notepad++, create new file and save as .nut file anywhere inside Portal 2/portal2/scripts/vscripts/ folder.
Now we are going to make our first function. Open your script file via notepad++.
Now type inside it.
yourFunctionName() is your function name, you can call it how you want for example: TreasureGhostLikeGrape. Remember to put () at end of function name, same as I did.
In this part I’m going to show you how to send text to console, to make that I’m going to use printl().
Open your script, and type
printl(“Your text goes here”) , also don’t forget to put ; at the end of line.
Script can be activated by any output and located in almost all entities but I’d recomend using logic_script entity for scripts.
Now open your logic_script, give it a name. Then add script to it. To do that go to its proporties, find entity script tab and press menage. Big script menager dialog will show up. Press + at bottom of it and open your script.
Last thing to do is output to launch it. Open your output, add onSmth -> logic_script -> RunScriptCode -> your function name
Now run your map with script, open console and type developer 2, this will let you see all input and outputs in console and top left corner of your screen.
Activate your logic_script and check your console!
Variables!
Variable is symbolic name associated with a value and whose associated value may be changed.
- integer
- float
- string
- vector
- array
- boolean
Integer
Integer is a variable that represents number.
local integer = 3;FloatFloat is simmilar to integer, however it can save fractions.
local float = 3.5;StringString is a variable that stores text.
local String = “Hello World!”;VectorVector is a variable that saves location in 3d world (x,y,z).
local vector; vector = Vector(1, 2, 3);BooleanBoolean is a variable that storage True/False.
local boolean = true;
Creating and modifying variables!
To create varriable, open your script, and type anywhere:
Now inside your function create printl() function like this:
Your code should look like this:
Now your text should appear in your console like this!
As I mentioned in previous part, variables can be modified, now I’m going to show you how.
Create 3 integer variables, and give them diffrent values.
As you see, this two variables were added to them selves. You can add, subtract, devide, multiply, intensify and square root them!
if() … else and while()!
if() is small function, that runs only if the parameter meets, otherwise function will use “else” if avible.
Example:
This is what you will get:
Now check what will happent when you will set apple as false.
while() is a logic loop that will be occuring until parametr wont meets.
Example:
This function will write numbers from 0 to yNumber value.
Try changing yNumber value to diffrent values.
Script Functions!
You can find all Sript Functions here:
[link]
I changed script holding entity to cube, here is example of function usage:
Another Example