Thread Tools Display Modes
08-06-18, 01:46 PM   #1
myName
A Deviate Faerie Dragon
 
myName's Avatar
Join Date: Jul 2018
Posts: 10
Passing itemlinks to slash commands

I am wanting to pass an itemlink to a slash command such as
Code:
/fs add <Linen Cloth>
but when I use GetItemInfo() BugSack returns "Usage: GetItemInfo(ItemID|"name"|"itemLink")

Presently I am add
Code:
SLASH_SERVANT1 = "/fs"
SlashCmdList.SERVANT = function(func, arg1)
	local infoType, itemID, itemLink = GetItemInfo(arg1)
end
What am I doing wrong here?
  Reply With Quote
08-06-18, 01:54 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
arg1 is the full command. Skip the 'add'.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-06-18, 01:58 PM   #3
myName
A Deviate Faerie Dragon
 
myName's Avatar
Join Date: Jul 2018
Posts: 10
Originally Posted by Rilgamon View Post
arg1 is the full command. Skip the 'add'.
The "add" will be needed as I am adding to table.
Func does return add when printed, so that's not a problem.
  Reply With Quote
08-06-18, 02:11 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
To expand further on Rilgamon's post, slash commands pass everything after the actual command into only the first variable. arg1 is nil here.

In your function,

Lua Code:
  1. func == "add <Linen Cloth>"

and

Lua Code:
  1. arg1 == nil

which means you are doing

Lua Code:
  1. GetItemInfo(nil)

which causes the error.


If you want add/remove commands, you have to "take apart" the first variable. One common method is

Lua Code:
  1. SlashCmdList.SERVANT = function(input)
  2. local command, link = strsplit(" ", input)

where

Lua Code:
  1. command == "add"

and

Lua Code:
  1. link == "<Linen Cloth>"
  Reply With Quote
08-06-18, 05:08 PM   #5
myName
A Deviate Faerie Dragon
 
myName's Avatar
Join Date: Jul 2018
Posts: 10
Presently I am using
Code:
SLASH_SERVANT1 = "/fs"
SlashCmdList.SERVANT = function(input)
	local command, link = strsplit(" ", input)

	print(command)
	print(link)
end
command = add
link = not a thing nor BugSack error
  Reply With Quote
08-06-18, 05:31 PM   #6
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Try:
Code:
SLASH_SERVANT1 = "/fs"
SlashCmdList.SERVANT = function(input)
	local command, link = input:match("^(%w+)%s+(.+)$")

	print(command)
	print(link)
end
If command will never contain numbers then you can change %w+ to %a+ for just letters (as outlined here).
  Reply With Quote
08-06-18, 06:30 PM   #7
myName
A Deviate Faerie Dragon
 
myName's Avatar
Join Date: Jul 2018
Posts: 10
Mkay, that got me on track.
  Reply With Quote
08-06-18, 06:39 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You were likely linking an item that had a space in it, when testing with Kanegasi's code.

strsplit accepts an optional 3rd argument that defines how many pieces to make.
https://wow.gamepedia.com/API_strsplit

You can still use Kanegasi's simpler method like this.
Lua Code:
  1. local command, link = strsplit(" ", input, 2)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Passing itemlinks to slash commands

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off