Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Quick Coding Questions

1246715

Comments

  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    edited October 2015
    Sobriquet said:
    Could someone explain the significance of the letters in: "for i,v in pairs" Or when k,v is mentioned?
    Antonius explained it well, but let me also say that you can leave of the second of the two if you only need keys. Like...

    for k in pairs (blah) do
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
  • SobriquetSobriquet Posts: 1,548Member @@ - Legendary Achaean
    edited October 2015
    A nice ELI5 answer, @Antonius thank you.
    image
  • EldEld Posts: 3,946Member @@ - Legendary Achaean
    Trevize said: forums
    Sobriquet said:
    Could someone explain the significance of the letters in: "for i,v in pairs" Or when k,v is mentioned?
    Antonius explained it well, but let me also say that you can leave of the second of the two if you only need keys. Like...

    for k in pairs (blah) do
    And it's also common to use _ as a throwaway name for the first if you only want the values, as in
    for _,v in ipairs(tbl) do ...
    Trevize
  • AhmetAhmet Wherever I wanna bePosts: 3,245Member @@ - Legendary Achaean
    Eld said:
    Trevize said: forums
    Sobriquet said:
    Could someone explain the significance of the letters in: "for i,v in pairs" Or when k,v is mentioned?
    Antonius explained it well, but let me also say that you can leave of the second of the two if you only need keys. Like...

    for k in pairs (blah) do
    And it's also common to use _ as a throwaway name for the first if you only want the values, as in
    for _,v in ipairs(tbl) do ...
    Always been confused by the difference between pairs() and ipairs(), just replace whichever one doesn't work so that it does work. I'm sure it's something stupidly simple, but some clarification would be nice.
    Huh. Neat.
  • AmranuAmranu Posts: 714Member ✭✭✭✭ - Eminent
    ipairs gives you the entry number and the key, pairs gives you the key name and value.

    Basically ipairs should be used on a table acting as an array, eg { "Blah1", "Blah2" } whereas pairs should be used on a dictionary/hash format eg { ["Blah"] = "Blah", ["Blah2"] = "Blah2" }
    SuladanDochitha
  • AhmetAhmet Wherever I wanna bePosts: 3,245Member @@ - Legendary Achaean
    Amranu said:
    ipairs gives you the entry number and the key, pairs gives you the key name and value.

    Basically ipairs should be used on a table acting as an array, eg { "Blah1", "Blah2" } whereas pairs should be used on a dictionary/hash format eg { ["Blah"] = "Blah", ["Blah2"] = "Blah2" }
    Took me a second to understand what you meant, but pairs vs indexed pairs makes sense! Thanks bae.
    Huh. Neat.
  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    edited November 2015
    Ahmet said:
    Amranu said:
    ipairs gives you the entry number and the key, pairs gives you the key name and value.

    Basically ipairs should be used on a table acting as an array, eg { "Blah1", "Blah2" } whereas pairs should be used on a dictionary/hash format eg { ["Blah"] = "Blah", ["Blah2"] = "Blah2" }
    Took me a second to understand what you meant, but pairs vs indexed pairs makes sense! Thanks bae.
    To be clear, pairs works on normal and indexed just fine - but it does them in 'random' order. ipairs runs through numerically indexed keys in order from 1-whatever. my sortedpairs (link) iterator runs through keys in alphabetical order.
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
    Siodhachan
  • AntoniusAntonius Posts: 4,119Member @@ - Legendary Achaean
    Is denyCurrentSend not included in any of the online Mudlet wiki documentation? All I've found is a reference to it on the details for the sysDataSendRequest event, but nothing about the actual function itself.

    Which brings me to my actual question: Is there an event raised when a command is denied?
  • KeneanungKeneanung Posts: 528Member ✭✭✭✭ - Eminent
    No. To quote the wiki:
    Note: if you'll be making use of denyCurrentSend(), you really should notify the user that you denied their command - unexperienced ones might conclude that your script or Mudlet is buggy if they don't see visual feedback. Do not mis-use this and use it as keylogger either

    But you can overwrite denyCurrentSend to fire an event like this:

    local origCurrentSend = denyCurrentSend
    denyCurrentSend = function(what)
      raiseEvent("sysDenyCurrentSendEvent", what)
      origCurrentSend()
    end

    This new denyCurrentSend can then also be given the actual command that was denied (which in urn ands it as an argument to he event handlers)

    Vadimuses
  • GamdenGamden Posts: 225Member ✭✭✭ - Distinguished
    I cant seem to capture the rage number gained from the prompt..can anyone give me the correct perl reg format?

    I want to create a Rage Gauge

  • AntoniusAntonius Posts: 4,119Member @@ - Legendary Achaean

    Kind of depends on exactly what your prompt is set to; with custom prompts in-game there's a ton of potential options. Rage itself should just be a number, so you'd need (\d+) for that part of the prompt, but you'd also need the pattern to match the rest. That said, you can get Rage from GMCP, something like this:

    function getRage()
        for _, stat in ipairs(gmcp.Char.Vitals.charstats) do
            if string.starts(stat, "Rage") then return tonumber(string.match(stat, "(%d+)"))
        end
    end
  • AntoniusAntonius Posts: 4,119Member @@ - Legendary Achaean
    @Keneanung Forgot to reply at the time, but thanks. Unfortunately I'd need it for scripts I haven't written myself/don't want to start making changes to; if it was just a case of my own code I could raise the event at the same time as calling denyCurrentSend.
  • KeneanungKeneanung Posts: 528Member ✭✭✭✭ - Eminent
    I'm not sure about implementation details, but if you subscribed to the sysDataSendRequest and checked somehow, if the event of above overwriting was fired in conjunction with the current event (ie directly after each other), you may be able to find out...
  • DaironDairon Posts: 231Member ✭✭✭ - Distinguished
    Is anyone else having a problem where Wundersys is putting up mass/rebounding/hold breath upon switching profiles (from basic to combat) and classes (from dragon to serpent)? I've noticed that it puts those three on basic defup/keep up, but does not show on the WSHOW DEFUP/KEEPUP tables. 
  • KietKiet Posts: 1,995Member @@ - Legendary Achaean
    Those three have their own thing with masson/rebon/br aliases.
  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    Antonius said:

    Kind of depends on exactly what your prompt is set to; with custom prompts in-game there's a ton of potential options. Rage itself should just be a number, so you'd need (\d+) for that part of the prompt, but you'd also need the pattern to match the rest. That said, you can get Rage from GMCP, something like this:

    function getRage()
        for _, stat in ipairs(gmcp.Char.Vitals.charstats) do
            if string.starts(stat, "Rage") then return tonumber(string.match(stat, "(%d+)"))
        end
    end
    I use: string.sub(gmcp.Char.Vitals.charstats[2],7)
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
  • SeifurSeifur Posts: 64Member ✭✭✭ - Distinguished
    The index could change at any time. Using a for loop is slower, but safer.
    retired
  • AntoniusAntonius Posts: 4,119Member @@ - Legendary Achaean
    That works as long as the order of charstats doesn't change, or at least the position of the Rage entry doesn't. We've already seen with the addition of Rage there's no guarantee it won't change.
    Trevize
  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    True. I suppose it could, but it hasn't in a very long time.
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
  • CynlaelCynlael Posts: 3,257Member @@ - Legendary Achaean
    I just use:
     brage = tonumber(string.match(gmcp.Char.Vitals.charstats[2], "Rage: (%d+)"))

    Index won't change, unless IRE physically changes it themselves, which is highly unlikely. (possible, but not very likely). Also kind of moot to say it's slower, given that it'll only be processed about 0.0001s (if that) slower than the above example.

  • DaironDairon Posts: 231Member ✭✭✭ - Distinguished
    Kiet said:
    Those three have their own thing with masson/rebon/br aliases.
    Yep. Problem is, they come on even when I dont toggle them on. For example, I will smoke skullcap, type alias REB (toggles rebounding ON) and type REB again to remove rebounding from the keepup list 
    Medi
  • MediMedi Posts: 94Member
    @Dairon Yeah, I have that same problem but you might find better answers/support posting in the wsys thread.  I handle the same way you do for now, just toggling them back off whenever I switch.

    I have some nub questions about saving tables in external files:
    Can you save more than one table per file (Seems like you can't)
    Is this an intense process? Would it be terribly harmful if I had one function that saved all of my tables (Probably 4ish)?
  • KeneanungKeneanung Posts: 528Member ✭✭✭✭ - Eminent
    You can put all your tables in another table and save that. On loading, you will need to restore each into their original place manually though
    Medi
  • TrevizeTrevize Posts: 1,517Member @ - Epic Achaean
    edited November 2015
    Medi said:

    I have some nub questions about saving tables in external files:
    Can you save more than one table per file (Seems like you can't)
    Is this an intense process? Would it be terribly harmful if I had one function that saved all of my tables (Probably 4ish)?
    I save many top-level tables to single files, just serialize them (turn them back into the lua script that would define them properly) then load them back up when needed. Can do multiple tables, nested tables, etc. No problem.

    Me and Soludra, goofing off, even found a way in MUSHclient to serialize functions. (I'm FadedParadox, he's Twisol) http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=9512 - I haven't done that in Mudlet yet though, storing functions is more of a fun exercise than actually useful.
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
    Medi
  • GamdenGamden Posts: 225Member ✭✭✭ - Distinguished
    Is it possible to put an echolink into a party chat? For instance a room number

    And how?

  • EldEld Posts: 3,946Member @@ - Legendary Achaean
    edited November 2015
    Gamden said:
    Is it possible to put an echolink into a party chat? For instance a room number

    And how?
    If you mean something that the other people in your party will see as a link they can click on, no. If it's something you're echoing to party, and you want to make part of it a link for yourself, probably the simplest way would be to just gag the line for your party echo, and re-echo it with the echoLink added in.
  • DaironDairon Posts: 231Member ✭✭✭ - Distinguished
    I was hoping to find a way to find the string.length of the line ABOVE the current one. 
    Is it possible to do this by moveCursor? 

    moveCursor(0, getLineNumber()-1) 
    -- somehow select the string and then do
    llength = string.len(matches[1])
    deselect()
    moveCursorEnd()


  • SeifurSeifur Posts: 64Member ✭✭✭ - Distinguished
    edited December 2015
    Maybe like this:
    moveCursor(0, getLineNumber() - 1)
    local length = #getCurrentLine()
    moveCursorEnd()
    -- Do stuff with the 'length' variable here
    retired
  • DaironDairon Posts: 231Member ✭✭✭ - Distinguished
    That fixed it, thanks! 
  • SzanthaxSzanthax San DiegoPosts: 1,906Member @ - Epic Achaean
    I have @Aesi acha analyzer scripts... Can't finger out how till display those stats from the db :( too drunk when I play maybe... 



Sign In to Comment.