Jump to content

GetClass values in Lua


thehankinator
 Share

Recommended Posts

I'm looking at Object:GetClass() ( http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/objectgetclass-r19 ) I'd like to use this function to determine if an entity is a light. Is there a constant some place that these numbers are defined? I know I could find out what the magic number is for say a SpotLight but I have no way of knowing that the value for SpotLight would not change in a later release.

Link to comment
Share on other sites

Of course I figured it out soon after I posted this. It's missing from the documentation but apparently you can do something like:

 

if entity:GetClass() == Object.SpotLightClass then
blah blah
end

 

The lua example is somewhat misleading in that it uses a magic number of 2 to check for a model class. It'd be better if it used Object.ModelClass instead. Also maybe list these as members of Object so we know what class ids we could check for. Or maybe it's there and I am looking in the wrong spot?

Link to comment
Share on other sites

  • 2 weeks later...

The lua example is somewhat misleading in that it uses a magic number of 2 to check for a model class. It'd be better if it used Object.ModelClass instead. Also maybe list these as members of Object so we know what class ids we could check for. Or maybe it's there and I am looking in the wrong spot?

 

It is hidden in the forums here: http://www.leadwerks.com/werkspace/topic/10139-leadwerks-map-class/#entry75115

 

Hopefully this will be one of the things that Josh and Aggror add to the revamped documentation/tutorials.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I know I could find out what the magic number is for say a SpotLight but I have no way of knowing that the value for SpotLight would not change in a later release.

 

That's what the OP was saying. These constants don't seem to be available in the docs. Mack added to the comment section so we can see the constant name (and we make the assumption it's the same name in Lua).

Link to comment
Share on other sites

You don't need to know what the value is, just use the declared constant. The values may change without warning.

 

And thats fine but like what everyone is pointing out, we don't know the name of the constants. And the one's that are mentioned, there might be confusion on what the lua declared constant is or in some cases the declared constants do not work as advertised.

 

The lua code example for Camera Get/Set ProjectionMode is one such example. I have to use the values 1 or 2 because the supposed declared constants 'Camera.Perspective' and 'Camera.Orthographic' will cause an error because they are nil.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Why would you need to know the name? It is just the name of the class.

 

huh? you dont see how we would we need to know the name of the constants you are using? Without that, it makes using some of the Get/Set commands kind of difficult to use. The second post here shows exactly why we would need that information. thehankinator figured it out by trial and error but why should everyone have to guess what the constants would be named?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

This type of documentation problem isn't limited to the subject I presented in this thread. Take Context::DrawRect for example. It has an optional argument for style which is a 0 by default. What does 0 mean? I suspect there is a constant some place but without access to the C++ source I have no way of determining what style means or could be(without brute force checking every possible value). Same with the class id, these constants need to be in the API documentation for those who do not have (or want) access to C++ headers. Some things do have the constants defined like collisiontype argument for Entity::Pick but there is not a link or blurb of text that points the reader to the Collision class documentation. MSDN is a great example of how the API could be documented, each argument of a function that takes a constant has every acceptable constant listed and described. While it'd be nice to have that kind of detail I think it would be acceptable to simply have a link to the page that has all the constants defined(not the value but what the constant means) that apply to that particular function or argument. As someone who is a programmer by trade this has tripped me up more than once guessing how to test the result of a return value or possible values of an argument.

Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...