An Introduction to Squirrel: Difference between revisions
No edit summary |
No edit summary |
||
Line 25: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0;" | {| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0;" | ||
|- | |- | ||
Line 34: | Line 33: | ||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | | colspan="1" style="padding: 0; margin: 0; width: 100%;" | | ||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | {| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | ||
! colspan="1" style="border: 1px solid black; padding-right: 64px; background-color: #606060; color: #111111; height: 35px;" | Variables | ! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Variables Variables] | ||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Comments Comments] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Data_Types Data Types] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Operators Operators] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Expressions Expressions] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Intro_to_Functions Intro to Functions] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Intro_to_Objects Into to Objects] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Scopes Scopes] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Control_Flow Control Flow] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Exceptions Exceptions] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Enums Enums] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Arrays Arrays] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Tables Tables] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Functions Functions] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Generators Generators] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Delegation Delegation] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Weak_References Weak References] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Classes] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Inheritance Inheritance] | |||
|} | |||
|- | |||
| colspan="1" style="padding: 0; margin: 0; width: 100%;" | | |||
{| class="wikitable" style="margin: 0 auto; width: 100%; padding: 0; border: none;" | |||
! colspan="1" style="border: 1px solid black; padding-right:64px; background-color: #606060; color: #111111; height: 35px;" | [https://sigwiki.potato.tf/index.php/Squirrel_Metamethods Metamethods] | |||
|} | |} | ||
|} | |} | ||
|} | |} |
Revision as of 23:36, 26 October 2023
Overview
This is a relatively brief beginner's guide to the Squirrel language (v3.2) aimed at people with no programming experience interested in trying their hand at VScript. The only prerequisite knowledge you are expected to have is basic knowledge of the Source engine. While in theory this guide is not technically specific to any Source game in particular, it is for version 3.2 which is unique as TF2's version of Squirrel. L4D2, Portal, and other Source games run on older versions, so in practice this guide is directed at TF2 players. If you're following this guide for another Source game that's perfectly fine, just be aware that some features may not function, or they might behave differently in your game's version of Squirrel. You'll also need to store your .nut files in the appropriate place of whatever game you're using, rather than the tf/scripts/vscripts folder.
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 more aimed at developers.
Getting Started
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 us to test game specific code, 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. 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!");