Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Longer numerals / Class Implementation (https://forums.graalonline.com/forums/showthread.php?t=78997)

Programmer 03-12-2008 09:09 PM

Longer numerals / Class Implementation
 
I've been working for gScript for quite a while now, and one thing that bugs me is that the numerals supported in gScript can only go to 2147483647. In C++, another language I excel at, there are extended primitive types such as 'long' and 'long double' which allow you to go to a much higher number (long double goes from 3.4e-4932 to 1.1e+4932 -- scientific notation of course).

Another thing I'd like to see implemented is the functionality to create inline classes (ones inside the weapon script, for example) to organize the things the weapon / NPC-script does. These should include inheritance.

Any comments?

[email protected] 03-12-2008 09:16 PM

i dont see why you need long integers, but inline classes can improve performance i suppose

cbk1994 03-12-2008 10:13 PM

Maybe just me, I can't think of any reason you'd need to go up to 2147483647 that there is no workaround for.

Inverness 03-12-2008 10:44 PM

For "classes" use a TStaticVar and join a class to it or define its functions manually with function objects.

Chompy 03-12-2008 11:19 PM

The numbers I agree on.. well, I would love to see that implented :(

The Exp curve I made, just goes to 2147483647 as maxexp when almost near max level :( And I don't want to make a new formula, then I need to balance everything out again.. :(

Programmer 03-12-2008 11:25 PM

Quote:

Originally Posted by Inverness (Post 1379111)
For "classes" use a TStaticVar and join a class to it or define its functions manually with function objects.

Not my point. The point is to allow classes to be included in Weapon scripts.

e.g.
PHP Code:

//#CLIENTSIDE
class Foo
{
virtual public void DoSomething() const { return "Something done..."; }
private 
int numeral;
}

class 
Bar extends Foo
{
public 
void DoSomething() const { return "Bar done..."; }
}

function 
onCreated()
{
bar = new Bar();

echo(
bar.DoSomething());


Notice the inheritance and the virtual methods.

Inverness 03-12-2008 11:46 PM

Yes and like I said, use a TStaticVar object and define its functions with function objects or a class.
PHP Code:

//// Example Script
function onCreated() {
  
this.topleft Objects.Rect(null00screenwidth 2screenheight 2);
}
function 
GraalControl.onMouseDown() {
  if (
this.topleft.inside(mousescreenxmousescreeny)) {
    
// do stuff
  
}
}
//// Weapon Script: Objects
public function Rect(objnamenxnynwnh) {
  
temp.obj = new TStaticVar(""@objname);
  
obj.int(nx);
  
obj.int(ny);
  
obj.int(nw);
  
obj.int(nh);
  
obj.join("type_rect");
  return 
obj;
}
//// Class Script: type_rect
function inside(nxny) {
  if (
nx in |this.xthis.this.w| && ny in |this.ythis.this.h|) {
    return 
true;
  }
  return 
false;
}
public function 
objecttype() {
  return 
"TRect";


It is not necessary to include what you're saying into GScript when the same functionality can already be achieved.

Programmer 03-13-2008 12:09 AM

Quote:

Originally Posted by Inverness (Post 1379128)
Yes and like I said, use a TStaticVar object and define its functions with function objects or a class.
PHP Code:

//// Example Script
function onCreated() {
  
this.topleft Objects.Rect(null00screenwidth 2screenheight 2);
}
function 
GraalControl.onMouseDown() {
  if (
this.topleft.inside(mousescreenxmousescreeny)) {
    
// do stuff
  
}
}
//// Weapon Script: Objects
public function Rect(objnamenxnynwnh) {
  
temp.obj = new TStaticVar(""@objname);
  
obj.int(nx);
  
obj.int(ny);
  
obj.int(nw);
  
obj.int(nh);
  
obj.join("type_rect");
  return 
obj;
}
//// Class Script: type_rect
function inside(nxny) {
  if (
nx in |this.xthis.this.w| && ny in |this.ythis.this.h|) {
    return 
true;
  }
  return 
false;
}
public function 
objecttype() {
  return 
"TRect";


It is not necessary to include what you're saying into GScript when the same functionality can already be achieved.

Simplicity, my friend.

Also, you're not getting my point.

read the following words:

INHERITANCE


Your argument contained no hint of inheritance at all ;)


-----
I'd also like to point out that I said classes within Weapon scripts, not class scripts.

Creating a class in a Weapon script is much different than in a class script.

Tolnaftate2004 03-13-2008 01:14 AM

OH GOD HELP I'M IN A BOX.

PHP Code:

// someclass_a
public function foo() {
  return 
3.141592653;


PHP Code:

//someclass_b
public function foo() {
  return 
589793238;


PHP Code:

function bar() {
  
temp.var = new TStaticVar();
  
with (temp.var) {
    
this.join("someclass_a");
    ...
  }
  return 
temp.var;
}

function 
baz() {
  
temp.var = new TStaticVar();
  
with (temp.var) {
    
this.join("someclass_b");
    for (
cbar().joinedclasses)
      
this.join(c);
    ...
  }
}

function 
onCreated() {
  
temp.bar();
  
temp.baz();
  echo(
temp.r.foo() @ temp.z.foo());


Also, since I'll bet you'll be wondering, yes, you can make abstract datatypes this way. And you can inherit directly (in baz: temp.var = bar()) if children do not try to overwrite functions.

As for longer numbers, you can use strings to display them, or I'm sure there are ways (not easy ways, mind you) for arbitrary precision math. I won't go into detail.

Inverness 03-13-2008 01:44 AM

Quote:

Originally Posted by Programmer (Post 1379135)
Your argument contained no hint of inheritance at all ;)

Obviously. If you know how to script then you would know how to implement inheritance on your own based on my example.
PHP Code:

// Weapon Script: Objects
public function ColoredRect(objnamenxnynwnhcrcgcbcacf) {
  
temp.obj this.Rect(objnamenxnynwnh);
  
obj.color this.Color(nullcrcgcbcacf);
  
obj.join("type_coloredrect");
  return 
obj;
}
public function 
SimpleColoredRect(objnamenxnynwnhcrcgcbca) {
  
temp.obj this.Rect(objnamenxnynwnh);
  
obj.red cr;
  
obj.green cg;
  
obj.blue cb;
  
obj.alpha ca;
  
obj.join("type_simplecoloredrect");
  return 
obj;
}
public function 
Color(objnamecrcgcbcacf) {
  
temp.obj = new TStaticVar(""@objname);
  
obj.red cr;
  
obj.green cg;
  
obj.blue cb;
  
obj.alpha ca;
  
obj.float cf;
  
obj.join("type_color");
  return 
obj;
}
// Class Script: type_color
public function toint() {
  if (
this.float) {
    
this.check();
    
this.red int(this.red 255);
    
this.green int(this.green 255);
    
this.blue int(this.blue 255);
    
this.alpha int(this.alpha 255);
    
this.float false
  }
}
public function 
tofloat() {
  if (!
this.float) {
    
this.check();
    
this.red this.red 255;
    
this.green this.green 255;
    
this.blue this.blue 255;
    
this.alpha this.alpha 255;
  }
}
public function 
check() {
  if (
this.float) {
    for (
temp.i: {"red""green""blue""alpha"}) {
      if (
this.(@ i) > 1)
        
this.(@ i) = 1;
      else if (
this.(@ i) < 0)
        
this.(@ i) = 0;
    }
  }
  else {
    for (
temp.i: {"red""green""blue""alpha"}) {
      if (
this.(@ i) > 255)
        
this.(@ i) = 255;
      else if (
this.(@ i) < 0)
        
this.(@ i) = 0;
    }
  }


I don't use inheritance myself because the time I did I found I was overcomplicating the script (a large one) and stopped doing it. Instead I now just have a single class that does everything, even stuff you might not need it for, rather like TShowImg.

So how would you implement inheritance in Graal?
Quote:

Originally Posted by Programmer (Post 1379135)
I'd also like to point out that I said classes within Weapon scripts, not class scripts.

Classes should be global in all cases. We certainly don't need classes specific to a script.
Quote:

Originally Posted by Programmer (Post 1379135)
Creating a class in a Weapon script is much different than in a class script.

Obviously. What you should have is a script to control all the classes on your server and not be specific to any object's script.

Edit: By the way PFA (?), if Graal didn't have a garbage collector you would cause memory leak with that ;)

Tolnaftate2004 03-17-2008 01:16 AM

Quote:

Originally Posted by Inverness (Post 1379156)
Edit: By the way PFA (?), if Graal didn't have a garbage collector you would cause memory leak with that ;)

It was just an example; I see that I made at least one mistake. I have a bad habit of writing code in the reply box, going to test it, changing it around and never replacing it in the reply box. :P


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

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