What is the "<-" meaning ??

ngocson389

  • Newbie
  • Posts: 13
What is the "<-" meaning ??
«  »
Hi guy, i'm new in squirrel, idk what is "<-" mean and usefor ? Can u explain it for me. Thanks!!

Athanatos

  • Hero Member
  • Working on maybe the best VC:MP server ever
  • Posts: 755
Re: What is the "<-" meaning ??
« Reply #1,  »
You use the <- operator for creating a global variable.

Example
Code: [Select]
MyCar <- 5;
MyCarInstance <- FindVehicle(5);

MyCar is a global variable with the value 5, And MyCarInstance references to the car with ID 5.

dracc

  • Jr. Member
  • Posts: 82
Re: What is the "<-" meaning ??
« Reply #2,  »
Athanatos is not wrong, however he simplified a bit.

`<-` is the "new slot" assignment operator. It inserts a new slot in a table if there is not already one with that name and if there is, it's just regular assignment to that slot. Squirrel has a root table which means that assigning to a slot without a parent table will put a new slot in the root table leading to it being global.

Example:
Code: [Select]
local myLocalTable = {}; // An empty table.
myLocalTable.myInt <- 5; // Local integer value stored in the slot 'myInt' in the table 'myLocalTable'.

myInt <- 5; // Notice the lack of an explicit parent table.
            // This will become a slot 'myInt' in the root table effectively creating a global variable.

Sources and more information:
http://www.squirrel-lang.org/squirreldoc/reference/language/expressions.html#assignment
http://www.squirrel-lang.org/squirreldoc/reference/language/tables.html