• attempt to concatenate local 'pl_pos' (a userdata value)
    10 replies, posted
gamemodes\undergroundrp\gamemode\init.lua:6: attempt to concatenate local 'pl_pos' (a userdata value) here is the buggy code [lua] concommand.Add("GiveToolGun", function(sender, command, arguments) local pl_pos = sender:GetPos() local bot_pos = bot_toolgun:GetPos() local distance = pl_pos:Distance( bot_pos ) Msg( "Player Pos = " .. pl_pos .. "\n" ) Msg( "Bot Pos = " .. bot_pos .. "\n" ) Msg( "Distance" .. distance .. "\n" ) if not sender:IsValid() then return end local money = sender:GetNetworkedInt( "cash" ) Msg( money .. "\n" ) if money < 100 then return elseif money>= 100 then sender:SetNWInt("cash", money - 100) sender:Give("gmod_tool") end end) [/lua] here is the Entity spawn code [lua] function GM:InitPostEntity() bot_toolgun = ents.Create( "bot_toolgun" ) bot_toolgun:SetAngles( Angle(0, -45, 0) ) bot_toolgun:SetPos( Vector(-1356, 881, -196) ) bot_toolgun:Spawn() end [/lua]
Msg(string) getpos doesn't return a string
You can't concatenate a string (like "Player Pos = ") with a Vector the way you're doing it. You can break the vector into it's components and then concatenate those, like this: [lua]local pl_posx, pl_posy, pl_posz = pl:GetPos() Msg( "Player Pos = " .. tostring(pl_posx) .. " " .. tostring(pl_posy) .. " " .. tostring(pl_posz) .. "\n" ) [/lua] Edit: I assume you are displaying those values for debugging only. If so, save yourself the trouble and do it like this: [lua]print("Player Pos:") print(sender:GetPos()) [/lua]
[QUOTE=_nonSENSE;23126546]You can't concatenate a string (like "Player Pos = ") with a Vector the way you're doing it. You can break the vector into it's components and then concatenate those, like this: [lua]local pl_posx, pl_posy, pl_posz = pl:GetPos() Msg( "Player Pos = " .. tostring(pl_posx) .. " " .. tostring(pl_posy) .. " " .. tostring(pl_posz) .. "\n" ) [/lua] Edit: I assume you are displaying those values for debugging only. If so, save yourself the trouble and do it like this: [lua]print("Player Pos:") print(sender:GetPos()) [/lua][/QUOTE] [lua]print("Player Pos:" , sender:GetPos())[/lua] :eng101:
[QUOTE=|FlapJack|;23126844] [lua]print("Player Pos:" , sender:GetPos()) [/lua] :eng101:[/QUOTE] :golfclap:
its not only for debugging x)
Either way, you should use |FlapJack|'s code.[URL="http://www.facepunch.com/showthread.php?p=23126844#post23126844"][/URL]
PrintTable( derma.GetSkinTable() ) ^^ Best Method
[QUOTE=Nexus435;23265529]PrintTable( derma.GetSkinTable() ) ^^ Best Method[/QUOTE] Since when did this have to do with this thread at all?
[QUOTE=Cubar;23267054]Since when did this have to do with this thread at all?[/QUOTE] i think he posted wrong ..
He thinks you can printtable userdata values. And he is wrong.
Sorry, you need to Log In to post a reply to this thread.