Jump to content

self.character vs getSpecificPlayer(0)


Deceptive Pastry

Recommended Posts

I'm working on adding on to the Firearm Radial Menu. For the purpose of getPrimaryHandItem() for getting currently held weapon info, what is the functional difference between self.character vs getSpecificPlayer(0) and which should I be using if I'm, say, checking if the currently held gun has access to alternate magazine types from a mod and only displaying the options to switch to them on the radial if the gun can use them.

 

In some places such as checking for magazines, timed actions, and fillMenu, FirearmRadialMenu.lua uses self.character:getPrimaryHandItem(), yet later for key presses and such it uses getSpecificPlayer(0):getPrimaryHandItem(). Looking at other mods, Gunfighter uses getSpecificPlayer(0) to check primary hand item for its functions.

Edited by Deceptive Pastry
Link to comment
Share on other sites

The table has a character field, the vanilla firearms radial uses it in various functions, but then at the end dealing with key presses it uses getSpecificPlayer(0). It seems like it's fine to continue doing it the way they originally did with self.character, I just wonder what the purpose is of defining and using self.character if getSpecificPlayer(0) can also be used and is used in the same table to do getPrimaryHandItem on the player.

 

It looks like when they define character they just use getPlayerNum(). Maybe it has to do with split-screen and having a second local player.

Edited by Deceptive Pastry
Link to comment
Share on other sites

  • 1 month later...

(Without viewing the described code)

In major, such source code is caused by one of the two following reasons:

- These functions could/might/will be called from somewhere else out of the "self scope".  So if its unclear whether you can just offer a player integer value or the player object, it makes sense to exceöt the int value for such parameters, so you can use this function in a wider range of contexts. A case distinction might be possible as well, of course, but getSpecificPlayer(int) seems to be faster.

- The function is a so called "grown structure", which could be optimized due to such changes, but will not, to offer backwards compatibility for older mods/versions.

Link to comment
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
×
×
  • Create New...