# debug checking of script-function params before executing

This topic is 1767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a codepath where I receive a vector of parameters from client code, intended for passing as parameters to a script-function call. In debug mode, I'd like to do some sanity checking on these parameters (like making sure that the number of values matches the number of parameters the script-function expects).

I currently have the following code (for each param):

if ( (funcParamTypeId & asTYPEID_SCRIPTOBJECT) )
{
// no way to pass a script object from C++ to a script function call.. this is an error condition
}
else if ( (funcParamTypeId & asTYPEID_MASK_OBJECT) )
{
// check whether script-function param is a known application-registered type such as 'string' or 'Vector2' and ensure that that's what we got
}
else if ( (funcParamTypeId & asTYPEID_MASK_SEQNBR) )
{
// check whether script-function param is a script primitive type
}


I realize based on the GC comment here that this is an incorrect use of asTYPEID_MASK_SEQNBR and it's just happening to work. (I don't have a lot of experience with GC yet because all my application-registered types are the NOCOUNT variety so far... the 'number' portion of the name confused me at the time.)

Is the proper way to rewrite that condition:

else if ( funcParamTypeId >= asTYPEID_BOOL && funcParamTypeId <= asTYPEID_DOUBLE )


?

Thank you very much.

##### Share on other sites

It's funny how you associated the sequence number mentioned in the GC thread with the asTYPEID_MASK_SEQNBR you were using for the typeid checks. They are completely unrelated, but it was a good thing you made that association because using asTYPEID_MASK_SEQNBR like you did is definitely not correct.

asTYPEID_MASK_SEQNBR just masks out the sequence number, and since all types have a sequence number this condition would always be true (except for void that uses the sequence number 0).

Yes, you can use the condition ( funcParamTypeId >= asTYPEID_BOOL && funcParamTypeId <= asTYPEID_DOUBLE ) to determine if the type is a primitive. The typeids for the built-in primitive types are fixed for this very purpose.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634053
• Total Posts
3015265
×