An Introduction to Squirrel: Difference between revisions

From SigMod
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 17: Line 17:
You should have a location something like this: <pre>C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf\scripts\vscripts\testing.nut</pre>
You should have a location something like this: <pre>C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf\scripts\vscripts\testing.nut</pre>


Go ahead and launch your favorite Source game which supports VScript and load into any map on a local server, then bind any key to "script_execute testing".
Go ahead and launch your favorite Source game which supports VScript and load into any map on a local server, then bind any key to <code>"script_execute testing"</code>.
For example: bind 5 "script_execute testing"
 
For example: <code>bind 5 "script_execute testing"</code>
 


Tab out of your game, open your .nut file and type:
Tab out of your game, open your .nut file and type:
Line 26: Line 28:
</syntaxhighlight>
</syntaxhighlight>


This prints the text "Hello World!" to console, we'll cover what all this means later, for now this is just to make sure you have a set up to test with as you read through the guide.
<code>'''printl'''</code> is a function that prints to the developer console, we'll go over what functions are and the syntax for it later in the guide, for now just follow along. After saving the file and pressing our script button in-game, you'll see <code>Hello World!</code> in console.
 
You just made your first program in VScript! To get started with the guide, choose a chapter in the table below. Make sure to tinker with the examples in the guide to see first hand how Squirrel works!
 
Good luck!





Latest revision as of 21:25, 22 January 2024

Overview[edit | edit source]

This is a relatively brief beginner's guide to the Squirrel language (v3.2) aimed at people with little to no programming experience. While this guide is intended to be used by people wanting to learn VScript for TF2, it doesn't cover anything regarding how to use VScript itself.

If you already have experience with C-like languages or programming in general I would recommend you visit the Squirrel Reference Manual for a more expedient learning experience aimed at developers.


Getting Started[edit | edit source]

While it's possible to compile the Squirrel source code into binaries with which you can test your code outside of a Source game, simply launching a game and executing your script is much simpler and allows you to start tinkering with Squirrel quicker, so that's what we'll do for the duration of the guide. For guides on VScript itself, the VDC has an excellent collection:

To get set up, navigate to your tf/ directory and add a scripts/vscripts folder if it doesn't already exist and create a file with any name with the extension .nut. (Mine will be named testing.nut)

You should have a location something like this:

C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf\scripts\vscripts\testing.nut

Go ahead and launch your favorite Source game which supports VScript and load into any map on a local server, then bind any key to "script_execute testing".

For example: bind 5 "script_execute testing"


Tab out of your game, open your .nut file and type:

printl("Hello World!");

printl is a function that prints to the developer console, we'll go over what functions are and the syntax for it later in the guide, for now just follow along. After saving the file and pressing our script button in-game, you'll see Hello World! in console.

You just made your first program in VScript! To get started with the guide, choose a chapter in the table below. Make sure to tinker with the examples in the guide to see first hand how Squirrel works!

Good luck!




Chapters
Variables
Comments
Data Types
Operators
Expressions
Intro to Functions
Into to Objects
Scopes
Control Flow
Exceptions
Enums
Arrays
Tables
Functions
Generators
Delegation
Weak References
Classes
Inheritance
Metamethods