Thread: Gs3
View Single Post
  #100  
Old 06-19-2013, 03:03 PM
Julien Julien is offline
Registered User
Join Date: Jun 2013
Posts: 8
Julien is on a distinguished road
Quote:
Originally Posted by Gunderak View Post
Also curious, why this didn't work.
PHP Code:
//#GS3
class Person extends TStaticVar{
  var 
nickname:string;
}
function 
onCreated():void{
  
//Create an array of type Person
  
var list:Person[];
  
//Create some Person objects.
  
var me:Person = new Person();
  
me.nickname "Nick";
  var 
them:Person = new Person();
  
them.nickname "Someone";
  
//Add them to the list
  
list.add(me);
  list.
add(them);
  
//Echo each Person element in the list
  
for(var someone:Person in list){
    echo(
"Name: "@someone.nickname);
  }

It does nothing, no errors either.
In the above code, the "list" variable was not initialized. The GS3 compiler currently fails to compile uninitialized variable declarations.

As a workaround, the following code should work:
PHP Code:
//#GS3
class Person extends TStaticVar{
  var 
nickname:string;
}
function 
onCreated():void{
  
//Create an array of type Person
  
var list:Person[] = {}; // Do not forget to initialize.
  //Create some Person objects.
  
var me:Person = new Person();
  
me.nickname "Nick";
  var 
them:Person = new Person();
  
them.nickname "Someone";
  
//Add them to the list
  
list.add(me);
  list.
add(them);
  
//Echo each Person element in the list
  
for(var someone:Person in list){
    echo(
"Name: "@someone.nickname);
  }

Reply With Quote