[VScript] The index 'GetPrimaryAmmoCount' does not exist

vtf

L1: Registered
Sep 26, 2021
16
0
Hi, im new to vscript, and i have no fucking clue what im doing. I get the error that "GetPrimaryAmmoCount" does not exist when i run my .nut file.
Code:
function OnPostSpawn()
{
    printl("VScript succesfully loaded")
}
function GetPrimaryAmmoCount()

local primaryAmmoCount = activator.GetPrimaryAmmoCount()
   printl(primaryAmmoCount)
}

Here's the full log:
Code:
VScript succesfully loaded

AN ERROR HAS OCCURED [the index 'GetPrimaryAmmoCount' does not exist]

CALLSTACK
*FUNCTION [GetPrimaryAmmoCount()] pen.nut line [8]
*FUNCTION [main()] InputRunScript line [1]

LOCALS
[this] TABLE
[vargv] ARRAY
[this] TABLE
 Entity pen encountered an error in RunScript()

AN ERROR HAS OCCURED [the index 'GetPrimaryAmmoCount' does not exist]

CALLSTACK
*FUNCTION [GetPrimaryAmmoCount()] pen.nut line [8]
*FUNCTION [main()] InputRunScript line [1]

LOCALS
[this] TABLE
[vargv] ARRAY
[this] TABLE
 Entity pen encountered an error in RunScript()
 
Last edited:

vtf

L1: Registered
Sep 26, 2021
16
0
Code:
function GetPrimaryAmmoCount()
{
  activator.GetActiveWeapon().GetPrimaryAmmoCount()
}

Gives a "The Index GetActiveWeapon does not exist"
 

vtf

L1: Registered
Sep 26, 2021
16
0
by a func_button targetting a logic_function named "pen" which points to the .nut file named "pen.nut" and has the parameter "GetPrimaryAmmoCount()" (btw the .nut file is locate in tf/scripts/vscripts
 

TH3 D34DL3$$

L2: Junior Member
Jul 14, 2017
68
14
You need to pass player to the function, like

Code:
function GetPrimaryAmmoCount( player )
{
    player.GetActiveWeapon().GetPrimaryAmmoCount()
}