Squirrel Variables: Difference between revisions

From SigMod
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<div style="width:33.333%; top: 0px; position: sticky; height: 30px; display: inline-block; text-align: center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel BACK]</div><div style="width:33.333%; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel HOME]</div><div style="width:33.333%; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/Squirrel_Comments NEXT]</div>
<div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align: center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel BACK]</div><div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel HOME]</div><div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/Squirrel_Comments NEXT]</div>


Every program in any programming language is comprised of a set of instructions called '''statements''' which manipulate data to produce a desired result. Programs store data into regions of memory as '''objects'''. Objects which we give an '''identifier''' (name) in our programs are called '''variables'''. You can think of statements as analogous to sentences in the language we speak to each other, each requires a specific set of items to be considered valid, and each is ended with a specific character. Sentences are mostly ended with periods, and statements always end with a semicolon.
Every program in any programming language is comprised of a set of instructions called '''statements''' which manipulate data to produce a desired result. Programs store data into regions of memory as '''objects'''. Objects which we give an '''identifier''' (name) in our programs are called '''variables'''. You can think of statements as analogous to sentences in the language we speak to each other, each requires a specific set of items to be considered valid, and each is ended with a specific character. Sentences are mostly ended with periods, and statements always end with a semicolon.

Revision as of 03:47, 27 October 2023

BACK
HOME
NEXT

Every program in any programming language is comprised of a set of instructions called statements which manipulate data to produce a desired result. Programs store data into regions of memory as objects. Objects which we give an identifier (name) in our programs are called variables. You can think of statements as analogous to sentences in the language we speak to each other, each requires a specific set of items to be considered valid, and each is ended with a specific character. Sentences are mostly ended with periods, and statements always end with a semicolon.


Identifiers have a few considerations to keep in mind:

  • They are case-sensitive, wep is not the same as WEP
  • The first character must be alphabetical (a-z) or an underscore, afterwards they can have any combination of (a-z), (0-9), or underscores
  • Underscores are the only special character allowed, nothing else


Valid Identifiers:

  • INDEX
  • _weapon
  • weapon_sequence
  • player123

Invalid Identifiers:

  • starting-index
  • 1_ring_to_rule_them_all
  • BOLD&BRASH
  • $IMBATMAN


In addition, identifiers cannot be the same name as a keyword, which are special identifiers reserved by the language for its use in the syntax. We'll go over most of these throughout the guide, so don't worry about memorizing them just yet.

Keywords
base break case catch class clone
continue const default delete else enum
extends for foreach function if in
local null resume return switch this
throw try typeof while yield constructor
instanceof true false static __LINE__ __FILE__
rawcall
To define a variable with x as it's identifier, we use the local keyword:
local x;

We created our variable in this statement but we haven't given it a value, so currently the value for x is null, which is a special value representing the lack of a value. To give our variable an actual value we have two options; we can set it at the time of definition (which is called initialization), or we can assign it a value with the assignment (=) operator in a separate statement, or both!


local x;
local y = 10;

printl(y);

x = 0;
y = 0;

Here we define x and initialize y to 10, print y to console, and then set them both to 0 afterwards.