WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Passing itemlinks to slash commands (https://www.wowinterface.com/forums/showthread.php?t=56505)

myName 08-06-18 01:46 PM

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?

Rilgamon 08-06-18 01:54 PM

arg1 is the full command. Skip the 'add'.

myName 08-06-18 01:58 PM

Quote:

Originally Posted by Rilgamon (Post 329337)
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.

Kanegasi 08-06-18 02:11 PM

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>"

myName 08-06-18 05:08 PM

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

Vrul 08-06-18 05:31 PM

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).

myName 08-06-18 06:30 PM

Mkay, that got me on track.

Seerah 08-06-18 06:39 PM

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)


All times are GMT -6. The time now is 08:40 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI