5

I'm learning about wow addons and I would like to create a command that shows in chat "Hello World" when I typed "/cht". I checked http://wowwiki.wikia.com/wiki/Creating_a_slash_command but my code does not work.

My code:

SLASH_CHAT = "/cht"
SlashCmdList["CHAT"] = function(msg)
        print("Hello World!")
end

Do you have any idea why is not working?

Thanks in advance.

Pablo Expósito
  • 162
  • 1
  • 11
  • 2
    every single example on that page has a command like SLASH_. like SLASH_HELLO1 for SlashCmdList["HELLO"]. do the examples from that page work for you? is it just your code that doesn't work (maybe due to that difference? you don't have a number after chat) – Piglet Jul 23 '17 at 13:26
  • I forgot to put the number, thank you! – Pablo Expósito Jul 23 '17 at 17:24
  • 2
    sometimes its better to modify a working example. you can change it until it stops working. so you instantly know that your last modification must be the problem. – Piglet Jul 23 '17 at 17:26

2 Answers2

10

You need to change your global from SLASH_CHAT to SLASH_CHAT1, yes it's really that simple.

Milo Christiansen
  • 3,204
  • 2
  • 23
  • 36
3

I've updated http://wowwiki.wikia.com/wiki/Creating_a_slash_command, fixing the examples and I added a simple starter example at the top with a condensed explanation of the mechanism and rules.

Some of the examples were unclear, but more importantly the actual rules for naming were fairly buried, which is where the OP was having issues.

The new top example reads:

SLASH_TEST1 = "/test1"
SLASH_TEST2 = "/addontest1"
SlashCmdList["TEST"] = function(msg)
   print("Hello World!")
end 

This was not totally your fault. :)


Before edit:

Same text as above basically, except I had misremembered and the code I used to spot check was complex and I misinterpreted it. I gave wrong information above on naming above (and edited the whole wiki article the same way). Both are fixed now. Comment below complaining was to the original answer I made here.

Beeeaaar
  • 1,010
  • 9
  • 19
  • I'm pretty sure the key should not have a number, the number is used to differentiate multiple commands that have the same handler. Edit: A quick check in another source reveals that the info on wikia is now WRONG! – Milo Christiansen Jul 23 '17 at 22:16
  • @MiloChristiansen Fixed now. Thanks for the comment and letting me know. – Beeeaaar Jul 24 '17 at 18:49