Graal Forums  

Go Back   Graal Forums > Graal V6 forums > Announcements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 10 votes, 4.60 average. Display Modes
  #91  
Old 06-16-2013, 11:23 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by Twinny View Post
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #92  
Old 06-17-2013, 07:02 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
I still hate the whole object:type thing. Would love it if it was more like Java and C#, object something;
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #93  
Old 06-17-2013, 01:15 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
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) {...}
Reply With Quote
  #94  
Old 06-18-2013, 01:58 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
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
Reply With Quote
  #95  
Old 06-18-2013, 06:06 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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);

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 06-18-2013 at 06:52 AM..
Reply With Quote
  #96  
Old 06-18-2013, 10:12 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by Gunderak View Post
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
Reply With Quote
  #97  
Old 06-18-2013, 11:50 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Ahh nice
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #98  
Old 06-18-2013, 12:05 PM
Gos_pira Gos_pira is offline
Registered Pirate Ghost
Gos_pira's Avatar
Join Date: Sep 2009
Location: Pirate Ghost Ship
Posts: 175
Gos_pira is a splendid one to beholdGos_pira is a splendid one to beholdGos_pira is a splendid one to beholdGos_pira is a splendid one to beholdGos_pira is a splendid one to behold
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.
Reply With Quote
  #99  
Old 06-18-2013, 02:06 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Foreach, I did for(various item:class_type in array)
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #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
  #101  
Old 06-20-2013, 12:07 AM
Fulg0reSama Fulg0reSama is offline
Extrinsical Anomaly
Fulg0reSama's Avatar
Join Date: Sep 2009
Location: Ohio
Posts: 3,049
Fulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant future
Quote:
Originally Posted by Julien View Post
!
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.
__________________

Careful, thoughts and opinions here scare people.
Reply With Quote
  #102  
Old 06-20-2013, 01:41 AM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
Quote:
Originally Posted by Fulg0reSama View Post
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?
__________________
Reply With Quote
  #103  
Old 06-20-2013, 03:14 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
He was onto me the other day, but then I lagged out
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #104  
Old 06-21-2013, 02:00 AM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
Are you guys hitting on each other o_O
__________________
Reply With Quote
  #105  
Old 06-21-2013, 04:38 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
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?

Last edited by Cubical; 06-21-2013 at 04:49 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:29 PM.


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