Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Script object reference in C++


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
6 replies to this topic

#1 brumi   Members   -  Reputation: 171

Like
0Likes
Like

Posted 19 September 2013 - 07:09 AM

Hi,

 

I'm writing a debugger for my project using AngelScript 2.27.1. I've registered a callback and able to extract the variables. I have a nice display showing the variables. For references I'd like to write if it is null or not.

for ( int varIx = 0; varIx < context->GetVarCount( level ); varIx++ )
  watch->Show( context->GetVarName( varIx, level )
             , context->GetVarTypeId( varIx, level )
             , context->GetAddressOfVar( varIx, level ) );

This way I enumerate the variables. In Show, I get the object type:

asIObjectType* objType = ScriptEngine::Instance().GetAsEngine()->GetObjectTypeById( typeId );

And then I have a TODO now smile.png

if ( objType->GetFlags() & asOBJ_REF )
{
  const asIScriptObject* object = (const asIScriptObject*)address;
  bool isValidRef = true; // TODO
  
  item->setText( 2, isValidRef ? "valid ref" : "null ref" );
}

I can cast the address of the property to an asIScriptObject, but I can't still determine if it is null reference or not. I've checked if the address pointer is maybe null, but it is not null even for null ref objects.

 

Is there a way to check if it is a null ref or not?

 

Thank you.


Edited by brumi, 19 September 2013 - 07:10 AM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
1Likes
Like

Posted 19 September 2013 - 10:56 AM

GetAddressOfVar() will return the address of the value in the variable. If the variable is a primitive type then the address will point to the value of the primitive, if the variable is a handle then the address will point to the handle, if the variable is local object (even if it is a ref type) then the address will point to the object.

 

You can use the typeId to know if the variable is a handle or not by checking for the bit asTYPEID_OBJHANDLE. If it is not a handle, then the variable will not be null.

 

I suggest you take a look at the CDebugger add-on in the SDK, particularly the ToString() and PrintValue() methods. It shows how to interpret the information you get about the variables.

 

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

#3 brumi   Members   -  Reputation: 171

Like
0Likes
Like

Posted 20 September 2013 - 04:09 AM

I wasn't aware of the Debugger addon. Thank you, checked it, and now I have a nice game editor with a full angelscript IDE. :) Like this:

 

editor.jpg



#4 BlackMoons   Members   -  Reputation: 441

Like
0Likes
Like

Posted 20 September 2013 - 04:18 AM

Wow nice work! that looks amazingly useful. I'll have to look into that, maybe not a full blown GUI like that, but at least a Debug() function that could automatically output all the local variables to log file as best it can sure would beat hacking in output to console statements for each var I want to look at.


Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com


#5 brumi   Members   -  Reputation: 171

Like
0Likes
Like

Posted 20 September 2013 - 04:47 AM

Thank you, I now have only one feature left before I'll release it to the public; Skinned animation.



#6 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 20 September 2013 - 11:41 AM

This looks really nice indeed.

 

Do you have a site for your project that I can link to on the users list?


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

#7 brumi   Members   -  Reputation: 171

Like
0Likes
Like

Posted 21 September 2013 - 01:18 AM

It is http://brumisoft.com.

 

Thank you.






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