Game Development Community

isObject --> isString? --- plus: Bizarre Console Errors

by Steve Acaster · in Torque 3D Professional · 06/25/2010 (3:17 pm) · 5 replies

I've been passing a variable in script and I need to check whether it's an ID or a XYZ. If it's an ID, then I need it's XYZ (getPosition).

My initial thought was isObject()
if(isObject(%var))
   %result = %var.getPosition();
else
   %result = %var;

Except it appears that when %var is passed as the XYZ string -> it decides that it is an object (kinda makes sense ... XYZ does exist in 3D space ... but ... okay ... no ... no it doesn't make sense ...) and so it attempts to call getPosition() on an XYZ ->>>> which is where the Bizarro World Console Errors come in.

It just picks anything which doesn't physically exist to call it on. It changes each time the function is run.

//Behold ... madness ...
scripts/server/players/aiPlayer.cs (2882): Unknown command getPosition.
  Object SFXTrackSet(1099) SFXTrackSet -> SimSet -> SimObject

scripts/server/players/aiPlayer.cs (2882): Unknown command getPosition.
  Object ActiveActionMapSet(1091) ActiveActionMapSet -> SimSet -> SimObject

scripts/server/players/aiPlayer.cs (2882): Unknown command getPosition.
  Object SFXSourceSet(1097) SFXSourceSet -> SimSet -> SimObject

//you get the picture!

Bizarre Console Errors aside ... everything still works, the XYZ gets passed and all is well outside of the console...

Currently I'm just using a wordcount, if it's 1 I know it's an ID and if it isn't then it's got to be an XYZ string. Works well enough ...

But, I was wondering if there was a way to determine if a variable is a string, kinda like an isString - an isObject for strings? Something that only takes up 1 line of script ...

#1
06/25/2010 (5:13 pm)
When you receive XYZ, the first part (X) is a "valid ID", as datablocks cover IDs from 3 upto the 1023, than comes normal objects created on start-up, so this is why you are getting SFXTrackSet and others.
For example you have: "120 1298 125" and 120 could be some datablock and 1298 - some object - GUI element or static object from mission.

There are many different ways to check if the passed variable is transform (XYZ) or a valid object id:
if(getWordCount(%var) == 1) echo("Valid object!");
if(strpos(%var, " ") == -1) echo("Valid object!");
if(strlen(%var) == strlen(stripChars(%var, " ")) echo("Valid object!");
if(%var $= stripChars(%var, " ")) echo("Valid object!");
if(strlen(stripChars(%var, "0123456789")) == 0) echo("Valid object!");
etc, etc, etc.
#2
06/25/2010 (5:49 pm)
That should probably be incorporated into isObject(). Odd.
#3
06/25/2010 (5:59 pm)
lol, yeah I just realised "oh yeah ... first word returned could be an ID!"

Thanks for the pointers guys ...
I had actually checked out TDN for string functions ... but found it all a bit confusing as I've not used them before ...
#4
06/26/2010 (3:25 am)
Welcome Steve! :)
Btw,
Quote:
I had actually checked out TDN for string functions ... but found it all a bit confusing as I've not used them before ...
Haven't visited TDN for a long time as I've used to check the sources when looking for something that I need.
The file I'm talking about now is:
Engine/source/console/consoleFunctions.cpp
#5
06/26/2010 (6:55 am)
nvm, i did misread the post ;)