Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-06-2011, 05:48 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Function overriding

I've brought this up a few times before, but this would be insanely useful and I think it deserves its own thread.

Function overriding would allow you to essentially overwrite default commands.

For example, if you wanted to create your own tileset layout without a custom movement system (syntax up for debate):

PHP Code:
// weapon -Tiles
//#CLIENTSIDE
function onCreated() {
  
tileType = function(xy) {
    
temp.tile this.level.tiles[xy];

    if (
tile in {123}) {
      return 
0;
    } else if (
tile in {456}) {
      return 
1;
    } 
// etc
  
};

  
onWall = function(xy) {
    return 
tileType(xy) == 7// just an example
  
};

Extending object prototypes would also be extremely useful. I think the best way to do it would be to have a class with the same name as the object type. This class would then be 'joined' to all of those objects.

A simple example:
PHP Code:
// class TGraalVar
function capitalize() {
  return 
this.value.substring(01).upper() @ this.value.substring(1);

Otherwise, you could go the JavaScript route and edit object prototypes

PHP Code:
TGraalVar.prototype.capitalize = function() {
  return 
this.value.substring(01).upper() @ this.value.substring(1);
}; 
You could then do this:

PHP Code:
temp.str "hello world!";
echo(
str.capitalize()); // echoes "Hello world!" 
Ideally all of this would work both serverside and clientside.

I have no idea how hard this would be to implement, but if it's not too difficult, it would be a huge improvement to GScript.
__________________

Last edited by cbk1994; 04-06-2011 at 06:03 PM..
Reply With Quote
  #2  
Old 04-06-2011, 06:01 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
This is normally called "function overriding".

And, it is "already possible" in GS2 in some technical sense. If you have access to a variable containing a function pointer (i.e., it was defined as an anonymous function), then you can override it.

The problem is that all the existing functions are not defined as anonymous functions.


Personally, I'd like to see the libraries be written in terms of higher order functions: e.g., onwall would accept the tiletype function as a parameter. This way you would rarely need to override things. This would be more work to do though.



As for your second point, since GS2 does have some sort of OO support, I do agree that prototypes would be a good addition.


Edit: Also, it's fairly critical that we get closure support soon (meaning that you can access variables outside the anonymous function from inside it) natively, rather than using my ugly hack for it.
Reply With Quote
  #3  
Old 04-10-2011, 05:48 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
I think this is a good idea, working with type1 and noticing a lot of the functions didn't work I wanted to try and fix it.. never did but I figured out a better type1 template. >.>

But I also would have loved to override the movement system, which I could be confused about the exact message / statement, but from what I think I understand this is about overriding built in functions?

Anyway, I hate how moving north east and south east the player faces right; moving north west the player faces left. Why does the player face down in south west?

Again, assuming I got what WhiteDragon was saying about the libraries .. unless he didn't mean for us to see them.. I would love to see and edit the basic functions too. I was hoping I could find the tile system and see if I could edit that.. then looking at an online tile editor I was hoping I could at least organize that to be together in looks but still hold their functions ... like 0x1A0 could be next to 0x1D1 but I didn't understand the Online Tile Editor at all lol.. it didn't have any tile arrays..

Sorry if I got both comments all mixed up :x
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #4  
Old 04-10-2011, 06:38 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Devil_Lord2 View Post
Again, assuming I got what WhiteDragon was saying about the libraries .. unless he didn't mean for us to see them.. I would love to see and edit the basic functions too.
I did not mean that default functions should be overwriteable.


I meant something like onwall accepting the tiletype function as a parameter:
PHP Code:
temp.onwall = function (temp.tileTypetemp.blockingTypestemp.xtemp.y) {
  return (
temp.tileType(temp.xtemp.yin temp.blockingTypes);

And likewise, other functions would accept an onwall function for their needs, which could be the one defined above, or another one.

Anyways, this would be a monumental amount of work and is just a pipedream.



Snapping back to reality, it is important for overriding, prototypes, and closures to be implemented.

I'd like to see some attention be given to these 3 things, because it would let the developers 'fix' a lot of problems with the default stuff without involving Stefan or rewriting everything from scratch.
Reply With Quote
  #5  
Old 04-10-2011, 07:13 AM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Ooh I see.. I can't say I fully understand, but I know on my pet system I have a problem making move serverside and it kinda just stops the moving script.. I suppose it is better than walking on a wall though.. I suppose I could find a way around this somehow but I am not an experienced NAT lol..

Anyway, my fault. :]
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz



Reply With Quote
  #6  
Old 08-16-2011, 12:44 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Want this. Alternative syntax suggestion:

PHP Code:
//#CLIENTSIDE
function TGraalVar.capitalize() {
  return 
this.value.substring(01).upper() @ this.value.substring(1);

__________________
Quote:
Reply With Quote
  #7  
Old 08-23-2011, 07:17 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
For example, if you wanted to create your own tileset layout without a custom movement system (syntax up for debate):
If the hard-coded movement system were to use a scripted function, it would be the equivalent of using a 0.05s timeout script to check wall collisions. With a more complex custom tileset design, the custom tileType function could be slightly cpu intensive, unless you used some hackish method to streamline the function. This is just something I thought up on the spot, but I guess something like this would remove the need for conditional statements in the tileType function...

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
temp.watertiles    = {1,2,3};
  
temp.blockingtiles = {4,5,6};

  for (
temp.iwatertiles)
    (@
"tiletype_"@i) = 11;

  for (
temp.iblockingtiles)
    (@
"tiletype_"@i) = 22;

  
tileType = function(xy) {
    return (@
"tiletype_"@this.level.tiles[xy]);
  };

  
onWall = function(xy) { 
    return 
tileType(xy) == 22;
  }; 

Function overriding would be useful in some cases I guess.
I would also really like to see the prototype idea implemented.
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 12:37 PM.


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