Checking A Variable Type

I’ve created a reusable function for clicking on an object which checks to see if an expected object has been displayed. If it has not it retries the click.

I am wanting to pass in objects and co-ordinates for clicking, but I have been unable to find a way to check if a variable that has been passed in is an object or a set of co-ordinates.

Is there an easy way to do this?

I could pass another parameter to the function but I’m trying to keep the number of input params as low as possible as the function will be re-used quite a lot.

Thanks,

Michael.

Hello Michael,

You can use the “is a” operator to verify a value’s type. For instance, you can use it when you want to know if something is a number, integer, even number, point, rectangle, date, time, boolean… etc.

You could use code like this to determine if the variable is a set of co-ordinates:

//pass a set of co-ordinates into the variable somevar

if somevar is a rectangle 
then 
	//Do something 
	log "it was a set of co-ordinates" 
else 
	//Do something else 
	log "it was an object" 
end if 

The same could be done for an object, by replacing the word “rectangle” in the above code with the word “object”. If the variable is either going to be an object or a set of co-ordinates, it is only necessary to determine if the variable is one or the other (as shown in the code above). If there are possibilities beyond that your code would be slightly more complicated, but would be based on this same concept. The code might then look something like this:

put (200,233,560,525) into somevar
if somevar is a rectangle 
then 
	//Do something
	log "it was a set of co-ordinates"
else if somevar is an object 
	//Do something else
	log "it was an object"
else 
	log "it was something else entirely!"
end if

You can also use the operators “is not a”, “is all”, “is not all” in a similar manner, and you can read about them in the SenseTalk Reference manual, which is available on the eggPlant download page: http://www.testplant.com/support/downloads/current/

-Elizabeth

Thanks for that Elizabeth, sounds like just the sort of thing I’m after.

One quick question though, the co-ordinates being passed are x,y and not a rectangle, so presumably “is a rectangle” is not a valid check?

I’ll give the “is an object” check a try, that sounds like it might work :slight_smile:

Michael,

You would be looking for “is a point”.

This shot of the SenseTalk Reference Manual page on the “is a” and related operators is really a good reference, I think.

Cheers,

Elizabeth

Thanks Elizabeth thats a big help! :slight_smile: