Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Announcements (https://forums.graalonline.com/forums/forumdisplay.php?f=240)
-   -   Gs3 (https://forums.graalonline.com/forums/showthread.php?t=134268072)

Gunderak 06-16-2013 11:23 PM

Quote:

Originally Posted by Twinny (Post 1719319)
My desires:

Constructors (being able to overload would also be awesome but perhaps taking it too far)
PHP Code:

class Test {
  var 
myname string;
  var 
myage int;

  function 
Test(mynamestring) {
    
this.myname myname;
  }
  
//Because overloading is fun
  
function Test(myname stringmyage number) {
    
this.myname myname;
    
this.myage myage;
  }

  function 
echoValues() : void {
    
printf("My name is %s and my age is %i"this.myname, (this.myagethis.myage "Unknown"));
  }
}

function 
onCreated() : void {
  var 
TestObj Test = new Test("Twinny"25);
  
TestObj.echoValues(); 

I know getters/setters will be on the way but this just seems more natural.

I added that printf as it will fail since it's not being referenced in that class(see: extern). For this, perhaps being able to simply prepend global. to global functions would be better. On a similar note, i've not tried but i hope we could use something like super.whatever to access base class items we inherited from :o

This.

Gunderak 06-17-2013 07:02 AM

I still hate the whole object:type thing. Would love it if it was more like Java and C#, object something;

Julien 06-17-2013 01:15 PM

Quote:

Originally Posted by Gunderak (Post 1719338)
I still hate the whole object:type thing. Would love it if it was more like Java and C#, object something;

Hello,

By essence, GScript is a scripting language. GScript is more close to JavaScript-like languages, rather than Java or C#.

This type syntax was chose among other language syntaxes, because it is commonly-used to annotate types in ECMAScript-based languages.

For example:

HTML Code:

// ActionScript
function foo(a:int):int {...}

// TypeScript
function foo(a: number): number {...}

// UnityScript
function foo(a : int) : int {...}

// Haxe
function foo(a : Int) : Int {...}

So, when converting from GS2 syntax to GS3 syntax, you just have to add type annotations to the original syntax.

HTML Code:

//#GS2
function foo(a) {...}

//#GS3
function foo(a : int) : int {...}

With a Java or C# syntax, this will require more semantic changes to the language, like removing the "function" keyword.
Also, you lose the ability to easily import scripts from similar languages (ActionScript, JavaScript, UnityScript, TypeScript...).

HTML Code:

// Java or C#.
int foo(int a) {...}


Twinny 06-18-2013 01:58 AM

Encountered some issues with inheritance,

PHP Code:

//#GS3

class BaseClass {
  var 
baseclassvar number 3;
  
  function 
overwriteMe() : string {
    return 
"You shouldn't see me without accessing baseclass";
  }
}

class 
InheritanceTest extends BaseClass {
  function 
overwriteMe() : string {
    return 
"You should see me!";
  }
}

function 
onCreated() : void {
  
//var BaseClassTest : BaseClass = new BaseClass();
  //echo(BaseClassTest.baseclassvar);
  
  
var TestObj InheritanceTest = new InheritanceTest();
  echo(
TestObj.baseclassvar);
  echo(
TestObj.overwriteMe());


would spit out,

PHP Code:

Weapon/GUI-script Twinny/GS3-Inheritance added/updated by Twinny
Script
Couldn't create object: type BaseClass is not existing in function onCreated in script of Twinny/GS3-Inheritance
Script: Function TestObj.overwriteMe not found in function onCreated in script of Twinny/GS3-Inheritance


Next, uncommenting the lines resulted in,

PHP Code:

Weapon/GUI-script Twinny/GS3-Inheritance added/updated by Twinny
Script
Couldn't create object: type BaseClass is not existing in function onCreated in script of Twinny/GS3-Inheritance
Script: Function TestObj.overwriteMe not found in function onCreated in script of Twinny/GS3-Inheritance
0
bytecode:1305: TypeError: Cannot read property '
name' of null
      typeName = stub.name.extends.name;
                                  ^
Will keep running the old NPC script until server restart. 


I was going to try and do a var BaseTestObj : BaseClass = TestObj; but figured it wouldn't get me too far :)

Gunderak 06-18-2013 06:06 AM

The class should extend something , try extends TStaticVar.
It will probably make it singleton but eh as long as you only use it once.
But also GS1-3 not being a proper language, it doesn't act like proper languages.
Oddly playing around, if you create the object, the class can extend it o.0 not the actual class though?
PHP Code:

//#GS3
class Foot extends TStaticVar{
  var 
id:int;
}
class 
Toe extends Foot{
  var 
id:int;
}
function 
onCreated():void{
  var 
Foot:Foot = new Foot();
  var 
toe Toe = new Toe();
  
toe.id 1;
  echo(
toe.id);



Twinny 06-18-2013 10:12 AM

Quote:

Originally Posted by Gunderak (Post 1719376)
The class should extend something , try extends TStaticVar.
It will probably make it singleton but eh as long as you only use it once.
But also GS1-3 not being a proper language, it doesn't act like proper languages.
Oddly playing around, if you create the object, the class can extend it o.0 not the actual class though?
PHP Code:

//#GS3
class Foot extends TStaticVar{
  var 
id:int;
}
class 
Toe extends Foot{
  var 
id:int;
}
function 
onCreated():void{
  var 
Foot:Foot = new Foot();
  var 
toe Toe = new Toe();
  
toe.id 1;
  echo(
toe.id);



And yet,

PHP Code:

class Animal { ... }
class 
Cat extends Animal { ... }
class 
Dog extends Animal { ... }
var 
cat Cat = new Cat();
var 
dog Dog = new Dog();
var 
cat_as_animal Animal =  cat as Animal// OK as the Cat type is a member of the Animal type.
var cat_as_cat Cat cat_as_animal as Cat// OK as the Cat type is a member of the Animal type.
var cat_as_dog Dog cat as Dog// KO as the Cat type is not a member of the Dog type.
var cat_as_animal_as_dog Dog cat_as_animal as Dog// null as the Cat as Animal type is not a member of the Dog type. 


Taken from: http://wiki.graal.net/index.php/Crea...t3#as_operator

It did resolve my query regarding referencing the base class..need to use 'as' operator :)

Gunderak 06-18-2013 11:50 AM

Ahh nice :)

Gos_pira 06-18-2013 12:05 PM

What's the point of extending if you still need to use the "as" expression? Seems rather retarded to me.

It would make sense if you used it in a foreach on an array of objects of different type.

Like:

"foreach (djur as Animal in this.Animals)"

while this.Animals contains Dog, Cat, Parrot etc.

I might just be misunderstanding something here, if so, disregard my post.

Gunderak 06-18-2013 02:06 PM

Foreach, I did for(various item:class_type in array)

Julien 06-19-2013 03:03 PM

Quote:

Originally Posted by Gunderak (Post 1719303)
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);
  }



Fulg0reSama 06-20-2013 12:07 AM

Quote:

Originally Posted by Julien (Post 1719419)
!

I am ****ing onto you Julien, we know you are one of them!
Also welcome to the community for what time you will be staying.

Crono 06-20-2013 01:41 AM

Quote:

Originally Posted by Fulg0reSama (Post 1719438)
I am ****ing onto you Julien, we know you are one of them!
Also welcome to the community for what time you will be staying.

****ing onto you?

BlueMelon 06-20-2013 03:14 AM

He was onto me the other day, but then I lagged out

Tim_Rocks 06-21-2013 02:00 AM

Are you guys hitting on each other o_O

Cubical 06-21-2013 04:38 PM

Quote:

Originally Posted by wiki.graal.net
So we have a few advantages:

Helps to write code which is more reliable and readable
The structure of objects can be analyzed for automatic script documentation
Dependencies can be analyzed so you can know which scripts access an object or function
We can make scripts running much faster (not right now but in the future
GraalScript3 can be converted to other languages and platforms, we are preparing something interesting for this to show in a few weeks

@Stefan While you're actively reviewing this thread can you elaborate on this and what you're preparing that's interesting?


All times are GMT +2. The time now is 03:00 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.