What is the "<-" meaning ??


  • 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!!


  • Hero Member
  • sin^2(x)+cos^2(x) = 1
  • Posts: 880
Re: What is the "<-" meaning ??
« Reply #1,  »
You use the <- operator for creating a global variable.

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.
Infected City Survival Main Dev


  • Jr. Member
  • Posts: 84
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.

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: