Gmod lua尝试使用错误的键为字符串值建立索引('addMoney'不属于字符串库)

问题描述 投票:0回答:1

[当尝试运行我的脚本时,我不断收到此错误:

[ERROR] addons/moneymanagement/lua/autorun/derma.init.lua:7: attempt to index a string value with bad 
 key ('addMoney' is not part of the string library)
  1. error - [C]:-1
   2. __index - lua/includes/extensions/string.lua:297
    3. func - addons/moneymanagement/lua/autorun/derma.init.lua:7
     4. unknown - lua/includes/extensions/net.lua:32

服务器端:

util.AddNetworkString("add_money")
net.Receive("add_money", function()
local currentplayer = net.ReadString()
local moneyamount = net.ReadUInt(24)
currentplayer:addMoney(moneyamount)

end)

客户端:

--add_money
addbutton = vgui.Create("DButton", f)
addbutton:Center()
addbutton:SetText("Add Money")
addbutton:SetSize(220, 80)
addbutton:SetPos(450, 65)
function addbutton:DoClick()
--Include net function here
--https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1b73.html
print("Sent playername " .. SelectedPlayer .. " and amount " .. input:GetValue() .. " to server") --debug
print(SelectedPlayer) --debug
net.Start("add_money")
net.WriteString(SelectedPlayer)
net.WriteUInt(input:GetValue(), 24)
net.SendToServer()
-- Still need to add server side net
-- Remember to define
    end

如果您对某些整数的来源感到困惑,那就是脚本的其他部分。虽然我已经测试了它们是否有效。只需在联网方面提供一些帮助。

提前感谢!

lua garrys-mod
1个回答
0
投票
是一个字符串,您需要类似:
local currentplayer = getPlayer(net.ReadString())
currentplayer:addMoney(moneyamount)
© www.soinside.com 2019 - 2024. All rights reserved.