Thread: slash commands

  1. #1

    slash commands

    It's not about the syntax, more about what i can/can't do with them.

    The idea should be this
    Code:
    SLASH_COLD1 = "/lolcommand" 
    SlashCmdList.COLD = function (msg, editbox)
      Print("awesome lolsentence")
      -- want to set a varable here. should be something like cfg.variable = true. is it possible?
      ReloadUI() -- can i use this function?
    end
    I think code "should" be correct. Is it also logically correct? the cfg.variable should be in another file, which is imported at the beginning (so it should be visible.
    Non ti fidar di me se il cuor ti manca.

  2. #2
    Your code should be correct, except that the default Lua print function is with a lowercase p
    I think ReloadUI can be used in this case, since slash commands generally are triggered from hardware events/keypresses, which is required for this function

    and why not just check if cfg is already defined/imported?
    Code:
    SLASH_COLD1 = "/lolcommand" 
    SlashCmdList.COLD = function(msg, editbox)
        print("awesome lolsentence")
        if cfg then
            cfg.variable = true
        else
            print("cfg is not defined or visible")
        end
        --ReloadUI()
    end
    Last edited by Ketho; 2011-07-28 at 12:05 PM.

  3. #3
    Deleted
    If cfg is a global, there's no reason why it shouldn't work.
    If cfg is a local from another file, that obviously won't quite work - you can use the addon-wide table to pass it around without exposing it globally, though.
    Code:
    local addontab = (select(2,...))

  4. #4
    cfg is a variable defined in the addon namespace, i use it as a container for the config file, and it's aldready defined.

    so, if i use
    Code:
    local addon, ns = ...
    local cfg = ns.cfg
    it should work.

    Another question: let's put i have cfg.variable = false in file 1, then with the slash command i want to set cfg.variable = true.
    Does it work? I have the suspect that reloading the ui after he keeps the cfg.variable in file 1, so negating the slash command effect. Need to try as soon i get home.

    Thanks for the answers
    Non ti fidar di me se il cuor ti manca.

  5. #5
    Deleted
    Well, if you want to keep it through reloads/relogs, you'll have to make it a SavedVar, obviously.

  6. #6
    And that's what i was seraching for never done one before, methods i must use?

    A link is just fine, learning is always good.
    Non ti fidar di me se il cuor ti manca.

  7. #7
    Deleted
    ## SavedVariables: GlobalKey

    Code:
    if event == "ADDON_LOADED" and arg1 == "AddonFolderName" then
        GlobalKey = GlobalKey or {} -- defaults
    end
    Last edited by mmocba105e19de; 2011-07-28 at 02:57 PM.

  8. #8
    Quote Originally Posted by Treeston View Post
    ## SavedVariables: GlobalKey

    Code:
    if event == "ADDON_LOADED" and arg1 == "AddonFolderName" then
        GlobalKey = GlobalKey or {} -- defaults
    end
    Thanks, gonna try this weekend.

    EDIT: if i use ##SavedVariablesperCharachter, i will have a separate copy of GlobalKey for every char, right?
    Last edited by Coldkil; 2011-07-29 at 10:41 AM.
    Non ti fidar di me se il cuor ti manca.

  9. #9
    Deleted
    Yea, that's the idea.
    SVPC are saved in WTF\Account\ACC\REALM\CHAR\SavedVariables\AddonFolderName.lua.
    Personally, I'd recommend something along the following lines:
    Code:
    if event == "ADDON_LOADED" and arg1 == "AddonFolderName" then
        GlobalKey = GlobalKey or {}
        local r = GetRealmName()
        GlobalKey[r] = GlobalKey[r] or {}
        local u = UnitName("player")
        GlobalKey[r][u] = GlobalKey[r][u] or {} -- defaults
        AddonObject.savedVar = GlobalKey[r][u]
    end
    Basically does the same as SVPC, but allows you to copy settings from other characters by simply accessing GlobalKey[r][name], while you can use AddonObject.savedVar for everyday purposes.

  10. #10
    Uhm, this sounds utterly complicated. But fun. I want to have access to my wow client right now

    EDIT: the code you posted above, how can i implement into a slashcommand? it's legit code that could be copy-pasted? just trying to understand the code, you are creating an empty table if it doesn't exist, and at the "coordinates" (realmname, playername) you save the value of GlobalKey.

    It seems more like an array of arrays; what "AddonObject.savedVar" stands for? are they placeholders?
    Last edited by Coldkil; 2011-07-29 at 02:16 PM.
    Non ti fidar di me se il cuor ti manca.

  11. #11
    Deleted
    It should go into your OnEvent code. It assigns the table GlobalKey[current realm][current character] to the AddonObject.savedVar key (while making sure all those tables even exist). AddonObject should be your main addon table - savedVar can be anything.
    The reason we do this on ADDON_LOADED is that, before that event, all savedVar values are nil - ADDON_LOADED indicates that all code and savedVars are loaded.

    In your slash command, you'd do something like this:
    Code:
    AddonObject.savedVar.someValue = true

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •