is there a way to check if layer has userdata?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

is there a way to check if layer has userdata?

Post by Bugala »

Some of my layers have userdata, some dont. And they both are using function in which if there is userdata, i need to access it, but problem is, how can i check if there is userdata without crashing the program?

For now when i use GetObjectData, it crashes if there isnt userdata.

Also, I was looking for GetAttribute, "Interval"s have option to query userdata, but "Layer"s dont.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: is there a way to check if layer has userdata?

Post by airsoftsoftwair »

I hope you mean that Hollywood exits cleanly, displaying an error message by "crash".... otherwise file a bug report :) You can manually handle this error by turning off the automatic error handler using ExitOnError() and then use GetLastError() to check if everything worked or not. Then turn on the automatic error handler again. I agree it would be nicer to have a function like HaveObjectData() already inbuilt... I'll see if I can add this.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: is there a way to check if layer has userdata?

Post by Bugala »

Ah, didnt think that getlasterror.

I did that exitonerror(fail) thing for that part, but with idea of:

Code: Select all

t_userdata = {}
exitonerror(false)
t_userdata = GetObjectData(...)
exitonerror(true)
if listitems(t_userdata) > 0
...
But as a future feature request, it could be handy having that "HaveObjectData" or perhaps "ObjectDataExists"?


especially now that i came to conclusion that carrying out some data in layers themselves is actually pretty handy way of keeping track of things. I think I am going to be using that more in future too.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: is there a way to check if layer has userdata?

Post by airsoftsoftwair »

HaveObjectData() is now implemented.
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: is there a way to check if layer has userdata?

Post by Bugala »

Thanks. That was fast!
Post Reply