Q for the devs: Accessing java class fields from lua
1 1

1 post in this topic

Recommended Posts

So I'm trying to find a 'clean' way of accessing class fields from lua. Using the Base.Shotgun as a example here, it has a field ProjectileCount, there is no getProjectileCount() method.

the intuitive lua way of using item.ProjectileCount doesn't work (always returns nil)

Poking around the API, LuaManager.GlobalObject has some methods I can use:

local index = 0 -- or some other integer
local field = getClassField(item, index)
local value = getClassFieldVal(item, field)

However this requires a whole crapload of guesswork, testing and debugging mapping field descriptions to integer values.

I'm actually trying to get fields from the Item class (not HandWeapons), all the fields listed are in alphabetical order, not by actual index (theres also only 131 +1 inherited fields listed in the api there, while I was able to retrieve 225 from the class.

 

Surely there must be a better way? Or at least a list I can use to map these field descriptions to indexes?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
1 1