GameMonkey Script

GameMonkey Script Forums
It is currently Tue Oct 23, 2018 5:01 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Aug 31, 2012 6:01 pm 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
Is there a way to call function in 'super class' in game monkey script?
something like this:
Code:
global GameObject = function() {
    gameObject = table();

    gameObject.Update = function() {
        print("GameObject.Update");
    };
   
    return gameObject;
};

global Player = function() {
    player = GameObject();

    player.Update = function() {
        super.Update();
       
        print("Player.Update");
    };

    return player;
};



Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 01, 2012 12:14 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 707
There is no built in way to accomplish that.
You could try hacking something like this (below) and see if there's a way to make it a little prettier.
Code:
global GameObject = function() {
    gameObject = table();

    gameObject.Update = function() {
        print("GameObject.Update");
    };
   
    return gameObject;
};

global Player = function() {
    player = GameObject();

    // Real version would duplicate functions only
    player.Super = tableDuplicate(player);

    player.Update = function() {

       if( this.Super.Update )       
       {
          this.Super.Update();
       }
       
        print("Player.Update");
    };

    return player;
};

Player().Update();

// Output:
// GameObject.Update
// Player.Update


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group