Bf_Read:ReadString()

Well, I’m trying to make a “Dynamic Vendor Menu”. Where I can pass along a function to a Npc when activated that leads to this with an arg of say…“Misc”, which would call the table “MiscDealer” and generate X icons based on the table. The function calls all the way up to here with no problems what so ever. Anyway, I digress.

When I attempt to do type:ReadString() it returns with “”, when “type” returns a Bf value.

[lua]
function DealerMenu(type)
print(type) – Returns something like “bf_read: 02C9FE18”.
print("Type: "…type:ReadString()) – Returns "Type: “” "

local client = LocalPlayer()
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame ) 

frame:SetSize(w / 2 + 40, h / 2)
frame:SetTitle(type:ReadString())
frame:MakePopup()
frame:Center()

IconList:EnableVerticalScrollbar( true ) 
IconList:EnableHorizontal( true ) 
IconList:SetPadding( 4 ) 
IconList:SetPos(10,30)
IconList:SetSize(frame:GetWide() - 20, frame:GetTall() - 20)

for k,v in pairs(string.ToTable(type:ReadString())) do
	local icon = vgui.Create( "SpawnIcon", IconList ) 
	icon:SetModel( v.Model )
	IconList:AddItem( icon )
	icon:SetToolTip( v.Name.." - $"..v.Cost )
	icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) frame:Close() BuyItem(client,v.Name,v.Cost) end
end

end
usermessage.Hook(“DealerMenu”, DealerMenu)
[/lua]

Damn all of these weird errors.

One thing to remember is that you can only read a certain value from a given usermessage once. i.e. if you do


umsg.Start("test")
umsg.String("one")
umsg.String("two")
umsg.End()

and


usermessage.Hook("test",function( u )
print( u:ReadString() )
print( u:ReadString() )
end ) 

That prints one and two. So, you need to set a variable equal to the first readstring.