Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Object Communication


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Edgyr45   Members   -  Reputation: 127

Like
1Likes
Like

Posted 14 February 2013 - 04:20 PM

Hi,

I'm integrating AngelScript into our game engine and I'm facing one problem I would like to ask here.

Lets say I have a GameObject class, which can own a asIScriptObject* and call function in it. (Like in the "game" sample).

I have two GameObjects, "Go1" with "player.as" and "Go2" with "zombie.as"

If a player kills a zombie, a function "void Kill()" must be called from player.as inside the zombie.as script.

 

I would like to avoid using a Send/Receive message function but to directly call Kill() inside player.as (a lots like in Unity) : 

 

class player
{
    //This is call from the engine on the GameObject's controller script:
    void DoSomething()
    {
        GameObject go2 = Engine.FindObjectByName("Go2");

        //What I would like to do, or something like that:
        Controller go2Controller = go2.GetController("zombie");
        go2Controller.kill();
    }
}

 

 

The "void Kill()" function is unknown from the engine, but an "instance" of zombie.as is created in Angelscript's engine. Can I get that instance and call function on it? I'm lost here.

 

Thank you very much



Sponsor:

#2 InvalidPointer   Members   -  Reputation: 1374

Like
0Likes
Like

Posted 14 February 2013 - 07:55 PM

Is there a reason casting wouldn't work here?


clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#3 Andreas Jonsson   Moderators   -  Reputation: 3241

Like
0Likes
Like

Posted 15 February 2013 - 07:01 AM

Either the engine can register the Kill() method on the IController interface, or you can have the script implement an extra interface that all script objects know about. 

 

// Declare the interface that living entities must implement
// Make it shared so all modules share the exact same implementation
shared interface ILiving
{
   void Kill();
}
 
// The player class and all enemies implement both the IController and the ILiving interfaces
class Player : IController, ILiving
{
   void DoSomething()
   {
     GameObject go2 = engine.GetGameObject("Go2");
     ILiving @ctrl = cast<ILiving>(go2.GetController());
     ctrl.KillI();
   }
}

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#4 Edgyr45   Members   -  Reputation: 127

Like
0Likes
Like

Posted 15 February 2013 - 08:05 AM

Thanks for the reply!

 

I cannot predict in advance what functions the "production" programmer will want to use. In your example, you wrote : go2.GetController(). What type does it returns exactly? An asIScriptObject* from a script that implement IController ?

 

Does that mean, like InvalidPointer suggested, that I can simply cast it?

 

Zombie @ctrl = cast<Zombie>(go2.GetController());

 

And let the production programmer call whatever they want in Zombie.as? Or I tell them to use interfaces?

 

Thank you very much



#5 Andreas Jonsson   Moderators   -  Reputation: 3241

Like
1Likes
Like

Posted 15 February 2013 - 09:26 AM

Yes, the C++ implementation of go2.GetController() should return a asIScriptObject *. It should be registered in AngelScript as returning a IController @.

 

If you plan on having separate modules for the entity controllers as in the game sample, then you need to tell your programmers to use shared interfaces like I posted earlier, because one module doesn't know the actual class type in the other module. If on the other hand you put all the scripts in the same module, then you can cast directly to the actual class without the need for an extra interface.

 

Regards,

Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#6 Edgyr45   Members   -  Reputation: 127

Like
0Likes
Like

Posted 15 February 2013 - 11:01 AM

I'll run some test with this info.

 

Thank you very much






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS