View unanswered posts | View active topics It is currently Thu Nov 28, 2024 11:31 am



Reply to topic  [ 2 posts ] 
 Script can't detect the magazine 
Author Message
User avatar

Joined: Mon Aug 27, 2012 7:21 pm
Posts: 31
Reply with quote
Post 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?


Fri Jun 27, 2014 4:12 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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.


Fri Jun 27, 2014 6:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.037s | 13 Queries | GZIP : Off ]