Quick Coding Questions

1246724

Comments

  • 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.
  • edited October 2015
    A nice ELI5 answer, @Antonius thank you.

    (Party): Mezghar says, "Stop."
  • 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 ...
  • AhmetAhmet Wherever I wanna be
    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.
  • 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" }
  • AhmetAhmet Wherever I wanna be
    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.
  • 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.
  • 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?
  • 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)

  • 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

  • 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
  • @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.
  • 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...
  • 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. 
  • Those three have their own thing with masson/rebon/br aliases.
  • 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.
  • The index could change at any time. Using a for loop is slower, but safer.
    retired
  • 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.
  • 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.
  • 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.

  • 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 
  • @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)?
  • 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
  • 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.
  • Is it possible to put an echolink into a party chat? For instance a room number

    And how?

  • EldEld
    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.
  • 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()


  • edited December 2015
    Maybe like this:
    moveCursor(0, getLineNumber() - 1)
    local length = #getCurrentLine()
    moveCursorEnd()
    -- Do stuff with the 'length' variable here
    retired
  • That fixed it, thanks! 
  • 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 or Register to comment.