• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
justin12343

Pass an asIScriptObject to a script?

5 posts in this topic

I'm trying to pass a handle of a game object to a script function, but its not working properly.

 

CScriptAny *Object::GetScriptObject()
{
	CScriptAny *n = new CScriptAny( scriptManager->GetEngine());
	int typeId = scriptManager->GetEngine()->GetTypeIdByDecl("Base_Object_IMP@");
	n->Store( pScrObj, typeId);

	return n;
}

Base_Object_IMP is the interface that the parent class of all scripted game objects, Base_Object inherit. Each instance store a asIScriptObject returned from the constructor. The function above fails with an access violation and it doesn't seem to be able to find the type id for 'Base_Object'.

 

I'm trying to cast from the base type to a another child type, like so:

Base_Object @base = null;
Object @obj = find_instance( objPlayer, Player);

if (obj != null)
	obj.GetScriptObject().retrieve( @base);

objPlayer_controller @PlayerHandle = cast<objPlayer_controller>( @base);
 

 

This is what I'm trying to do:

asIScriptObject -> Base_Object_IMP@ -> Base_Object@ -> objPlayer_controller@ (or any other child type).

 

Is there a proper way to do this?

0

Share this post


Link to post
Share on other sites

I found that I could do the following:

 

asIScriptObject *Object::GetScriptObject()
{
	/*CScriptAny *n = new CScriptAny( scriptManager->GetEngine());
	int typeId = scriptManager->GetEngine()->GetTypeIdByDecl( "Base_Object_IMP@");
	n->Store( pScrObj, typeId);

	return n;*/

	pScrObj->AddRef();//<----- Crashes without calling AddRef
	return pScrObj;
}

and then cast like so:

int id = create_instance( x+(LogWidth*i), y, objBridgeNode);
objBridgeNode_controller @node;
Object @obj = get_instance( id);

if (obj != null)
	@node = cast<objBridgeNode_controller>( @obj.GetScriptObject());

 

Now the problem is the frame rate slowly drops. What could be causing this to happen?

Edited by justin12343
0

Share this post


Link to post
Share on other sites

In your original post the problem was that you told Store() that you was passing in a pointer to a handle, but in reality you were passing in a pointer to the object directly. The correct way to do it would be:

 

CScriptAny *Object::GetScriptObject()
{
    CScriptAny *n = new CScriptAny( scriptManager->GetEngine());
    int typeId = scriptManager->GetEngine()->GetTypeIdByDecl("Base_Object_IMP@");
    n->Store( &pScrObj, typeId );  // pass in a pointer to the pointer to the object as the typeId is a handle

    return n;
}

 

Still, your second post is much better. smile.png

 

With only the little information that you have shared so far it is impossible to know why your framerate decreases overtime. It can be any number of factors. 

 

Profiling your application is a good way to find out what is going on. Especially if you can do separate profiles at different time periods, then you would be able to figure out why in the later period it is slower than in the early period.

0

Share this post


Link to post
Share on other sites

I solved that frame rate problem. My debug output window was filling up with "accessing null pointer" errors. Now I'm checking for null pointers before I try to access:

 

for (int i = 0; i < NumLogs; ++i)
{
	int id = create_instance( x+(LogWidth*i), y, objBridgeNode);
	objBridgeNode_controller @node;
	Object @obj = get_instance( id);

	if (obj != null)
		@node = cast<objBridgeNode_controller>( @obj.GetScriptObject());
	else
		continue;
	
	if (node == null)
		continue;

	node.ParentBridge = GetId();
	node.Id = i;
	
	Nodes[i] = id;
}

Apparently, I'm getting null pointers every time as if the cast operator does not know what type the returned asIScriptObject really is.

 

Even this doesn't work:

 

Base_Object_IMP @base = null;

base = cast<Base_Object_IMP>( @obj.GetScriptObject());

 

The result is still null. I know asIScriptObject being passed is valid before hand, so what can this problem be?

 

Edit:

 

Here's my other Base_Object class if it helps:

class Base_Object : Base_Object_IMP
{
//========== Constructor / Destructor ===========
	Base_Object( Object @obj)
	{
		@this.object = obj;
		x = object.x;
		y = object.y;
		sprite_index = -1;
		mask_index = -1;
		image_index = object.image_index;
		depth = object.depth;
	}

//=========== Events =============
	void Create(){}
	void Destroy(){}
	void Alarm1(){}
	void Alarm2(){}
	void Alarm3(){}
	void Alarm4(){}
	void Alarm5(){}
	void Alarm6(){}
	void Alarm7(){}
	void Alarm8(){}
	void Alarm9(){}
	void Alarm10(){}
	void Alarm11(){}
	
	void BeginStep(){}
	void Step(){}
	void EndStep(){}
	
	void Collision( int objType, int objId, Object @other){}
	
	void Key( int key){}
	void KeyPressed( int key){}
	void KeyReleased( int key){}
	
	void MouseButton( int button){}
	void MouseButtonPressed( int button){}
	void MouseButtonReleased( int button){}
	
	void JoystickButton( int id, int button){}
	void JoystickButtonPressed( int id, int button){}
	void JoystickButtonReleased( int id, int button){}
	
	void OutsideRoom(){}
	void OutsideView(){}
	void IntersectBoundary(){}
	
	void GameStart(){}
	void GameEnd(){}
	
	void RoomStart(){}
	void RoomEnd(){}
	
	void NoMoreLives(){}
	void NoMoreHealth(){}
	
	void AnimationEnd(){}
	void EndOfPath(){}
	void Draw(){}

//======= Collision =========
	bool place_meeting( float mX, float mY, int type)
	{
		return object.PlaceMeeting( mX, mY, type);
	}
	
	bool place_meeting_depth( float mX, float mY, int depth, int type)
	{
		return object.PlaceMeetingDepth( mX, mY, type, depth);
	}
	
	Base_Object @object_place( float mX, float mY, int type)
	{
		Base_Object @base = null;
		Object @obj = object.ObjectPlace( mX, mY, type);
		
		if (obj == null)
			return null;
		else
			//obj.GetScriptObject().retrieve( @base);
			@base = cast<Base_Object>(@obj.GetScriptObject());
			
		return base;
	}


//========== Misc ===========
	uint GetId()
	{
		return object.GetId();
	}

	void SetRect( int l, int t, int w, int h)
	{
		object.general_rect.left = l;
		object.general_rect.top = t;
		object.general_rect.right = l+w;
		object.general_rect.bottom = t+h;
	}
	
//======= Variables =========
	Object @object;
	float x;
	float y;
	int sprite_index;
	int mask_index;
	int image_index;
	int depth;
}

 

classes are declared like:

objBridge_controller : Base_Object

{

....

}

Edited by justin12343
0

Share this post


Link to post
Share on other sites

That just might solve it. I currently using #include in each script to define Base_Object. Using shared makes a lot more sense.

 

EDIT:

That fixed it. Thanks!

Edited by justin12343
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0