Data Realms Fan Forums
http://45.55.195.193/

Script can't detect the magazine
http://45.55.195.193/viewtopic.php?f=73&t=45750
Page 1 of 1

Author:  ATOS Productions [ Fri Jun 27, 2014 4:12 pm ]
Post subject:  Script can't detect the magazine

Long story short, I have a script that is activated via pie button:



When I select the pie button, this is what pops up in the console:

Code:
ERROR: Ronin.rte/Devices/Weapons/Script.lua:6: attempt to index field 'Magazine' (a nil value)


What am I doing wrong?

Author:  Bad Boy [ Fri Jun 27, 2014 6:41 pm ]
Post subject:  Re: Script can't detect the magazine

Try changing line 2 to:
Code:
local gun = ToHDFirearm(ToAHuman(actor).EquippedItem);

Right now it's probably treating it as a generic attachable or helddevice or whatever, something that doesn't have a magazine. Cast it to an HDFirearm before trying to access the magazine.

Also, I believe line 3 is incorrect, you can't create/access variables like that for an object*. You can see if it works as is, I may be misremembering now, but if it doesn't, try changing line 3 to:
Code:
local roundsInMag = gun.Magazine.RoundCount;

All subsequent calls for gun.roundsInMag would have to be replaced as well of course, though I see none here so I'm not sure what the point of that variable is.




*Technically you can with metatables and a bit of clever scripting, but I'm pretty sure you can't do it straightforwardly like this.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/