Quick Coding Questions

1141517192024

Comments

  • Nice! Glad to hear 3.5 is working well. Let's get more people on it!
  • So I am trying to match the room name from line, say:

    The Motley Magpie (indoors).
    Centre Crossing.

    How do I only get the room name and not the (indoor) or (indoor roads) bit?

    Thanks.
  • AhmetAhmet Wherever I wanna be
    mmp.cleanroomname(blah)
    Huh. Neat.
  • Is there a function to select or deselect a specific variable on the Variables window so that I don't have to do it manually?

  • Not at the moment, just the table.save() and table.load() functions.
  • Can anyone tell me how I can make Keneanaung, the bashing system, use Jinx Bleed Bleed when I have Malign power as a Shaman? (Which is after every normal Swiftcurse Bleed basically so it goes Curse Bleed, Jinx Bleed bleed, Curse bleed, etc.)

    I've tried 'kconfig bashing attackcommand jinx bleed bleed &tar/swiftcurse &tar bleed' to set the custom alias to try and make it use Jinx every balance and when it fails, just swiftcurse, but no luck. 

    I'm terrible at Mudlet. Help?
  • You don't get Jinx charges from Swiftcurse, as far as I know. You would need to be using regular curse bleed.
  • edited November 2017
    Antonius said:
    You don't get Jinx charges from Swiftcurse, as far as I know. You would need to be using regular curse bleed.
    Hrm. You could be entirely right. I can't say for sure, because I was using the blank KILL alias which was using Curse Bleed, but SVO was keeping SWIFTCURSE up, and I was getting it every second balance.

    I don't know?\

    EDIT: According to in game sources, having Swiftcurse up wont interfere with this.

    Now to just find out how to make Keneanaung do it.
  • Swiftcurse doesn't proc jinx charges. So if you're using swift, you won't get to use jinx at all.
  • Solnir said:
    Swiftcurse doesn't proc jinx charges. So if you're using swift, you won't get to use jinx at all.
    You're correct! It wasn't swiftcursing.
  • I figured it out! It was something simple. I just had to change the original command I tried to 'kconfig bashing attackcommand jinx bleed bleed &tar/curse &tar bleed' instead of trying to use swiftcurse. 

    I thought I'd tried that. Apparently I hadn't. Derp.

    Thanks for the advice folks. :)
  • can anyone tell me why this is not working at all?

    venom1 = loki
    venom2 = delphinium
    venom3 = loki
    if juggling == true then 
    send("queue add eqbal throw axe at " .. target .." ".. venom1 ..";queue add eqbal throw axe at " .. target .." "..venom2..";queue add eqbal throw axe at " .. target .." "..venom3)
    elseif juggling == nil then
    send("unwield left;queue add eqbal juggle axe axe axe;queue add eqbal throw axe at " .. target .." "..venom1..";queue add eqbal throw axe at " .. target .." "..venom2..";queue add eqbal throw axe at " .. target .." "..venom3)
    end

    worked fine until I started throwing the venoms with variables in there.
  • Well you can’t envenom Loki, so that could be an issue. 




    Penwize has cowardly forfeited the challenge to mortal combat issued by Atalkez.
  • Dominius said:
    can anyone tell me why this is not working at all?

    venom1 = loki
    venom2 = delphinium
    venom3 = loki
    if juggling == true then 
    send("queue add eqbal throw axe at " .. target .." ".. venom1 ..";queue add eqbal throw axe at " .. target .." "..venom2..";queue add eqbal throw axe at " .. target .." "..venom3)
    elseif juggling == nil then
    send("unwield left;queue add eqbal juggle axe axe axe;queue add eqbal throw axe at " .. target .." "..venom1..";queue add eqbal throw axe at " .. target .." "..venom2..";queue add eqbal throw axe at " .. target .." "..venom3)
    end

    worked fine until I started throwing the venoms with variables in there.
    Need to wrap variable values in "" in this instance.

    venom1 = "loki"
    venom2 = "delphinium"
    venom3 = "loki"

    but yes as Atalkez said, can't envenom loki anyway.
  • Ahh, no it wasn't cause of the loki, that was just random, the quotation marks did the trick, anyone able to explain why? Things have been working without them for me for a long time..
  • It's a difference in data types. If you have the quotes, you're saying everything between them is a string (a piece of literal text). "loki" is a string containing the word loki.

    Without the quotes, you're saying it's a variable with that name. loki is a variable called loki, and its value can be anything (or nothing at all if the variable doesn't actually exist).

    In other words, venom1 = "loki" sets the value of the variable venom1 to the word loki. venom1 = loki sets the value of the variable venom1 to the value of the variable loki. Unless you've done loki = <something> at some point you're actually not setting venom1 to anything.
  • So many things all the sudden make so much sense, thanks @Antonius
  • Ok, I hope this is the right place to ask I know next to nothing about coding. I am trying to make a script to select needed venoms for me since I am unable to keep up with the speed manually. I am jester juggling 3 things and I need 3 venoms selected, so far this has been working but I am still uneasy about putting in venom2 and venom3:

    function venomprioasthma ()
       if affstrack.score.asthma<100 then
    venom1 = "kalmia"
    elseif affstrack.score.asthma>66 and 
    affstrack.score.anorexia<100 then
          venom1 = "slike"
       elseif affstrack.score.asthma>66 and
    affstrack.score.anorexia>66 and
    affstrack.score.paralysis<100 then
          venom1 = "curare"
       elseif affstrack.score.asthma>66 and
    affstrack.score.anorexia>66 and
    affstrack.score.paralysis>66 and
    affstrack.score.slickness<100 then
          venom1 = "gecko"

    appreciate any help on making this a bit simpler for venom2 and venom3 because they basically need to do whatever comes after venom1 having asthma being the priority affliction I want to give my target. If any jesters out there need help I can make this public once I have it working.
  • How about something like this?
    local venoms = {}
    local affVenomPrio = {
        {"asthma", "kalmia"},
        {"anorexia", "slike"},
        {"paralysis", "curare"},
        {"slickness", "gecko"}
    }
    local i = 0
    
    for _,v in pairs(affVenomPrio) do  -- for each affliction/venom in order
        if affstrack.score[v[1]] < 100 then -- if aff is < 100, choose that venom
            venoms[i] = v[2]
            i = i + 1
            if i > 3 then break end -- once we've gotten 3 venoms, we're through
        end
    end
    
    Main thing to note is this puts your venoms in venoms[1], venoms[2], venoms[3], instead of venom1, venom2, venom3.
    image
  • Reading these last two comments really hammers in my lack of coding skills. I understood what @Dominius was doing but as soon as @Jacen took a spin on it I couldn't understand anything. No clue what 80% of that code means, what it does, or how it does it. :frown:
  • It's been suggested that I make a video on using tables which is what Jacen is doing there - I'll get around to it. Meanwhile, maybe you can learn something from this: 
  • That really does look awesome @Jacen, maybe you can PM me letting me know what that actually does? I read through the manuals a lot, but it's largely time consumingand being very busy in general breaking it down would help immensely
  • Jacen said:
    How about something like this?
    local venoms = {}
    local affVenomPrio = {
        {"asthma", "kalmia"},
        {"anorexia", "slike"},
        {"paralysis", "curare"},
        {"slickness", "gecko"}
    }
    local i = 0
    
    for _,v in pairs(affVenomPrio) do  -- for each affliction/venom in order
        if affstrack.score[v[1]] < 100 then -- if aff is < 100, choose that venom
            venoms[i] = v[2]
            i = i + 1
            if i > 3 then break end -- once we've gotten 3 venoms, we're through
        end
    end
    
    Main thing to note is this puts your venoms in venoms[1], venoms[2], venoms[3], instead of venom1, venom2, venom3.
      
        {"asthma", "kalmia"},
        {"anorexia", "slike"},
        {"paralysis", "curare"},
        {"slickness", "gecko"}
    }</code>local venoms = {}</pre>Starts a new, local, empty table named <i>venoms</i>. The&nbsp;<i>local</i> part means that the variable&nbsp;<i>venoms</i> is local to this&nbsp;<i>scope.&nbsp;</i>That is to say, if you try to check the value of&nbsp;<i>venoms</i> outside this particular script, it will not exist.<br><br>A Lua table is a object that has&nbsp;<i>keys</i> and&nbsp;<i>values</i>, such that&nbsp;<i>table[key] = value</i>. Its like going to the post office with a PO Box number. With the PO Box number (<i>key</i>) you can open the box and see what's inside (<i>value</i>). Its important to note that in Lua,&nbsp;<i>keys</i> and <i>values&nbsp;</i>don't have to be numbers. They can be just about anything in Lua, but most usually are numbers or strings (i.e&nbsp;<i>table["Telephone Number"] = 8675309</i>)<i>&nbsp;<br></i><pre class="CodeBlock"><i><code>local affVenomPrio = {
    This makes a new, local, non-empty table affVenomPrio. The keys for this table are implicit (I didn't specify them), which in Lua, means they start numbering from 1. So, affVenomPrio[1] = {"asthma, "kalmia"}. The implicit key 1 is mapped to the value of {"asthma, "kalmia"} A table inside a table! I made this table so that I could associate afflictions with venoms (i.e. when I checked affstrack.score.affliction, I would know what the venom associated with that affliction was). 
    The main reason I made the keys of this table implicit, which numbered them from 1 to the length of the table, was that it would impose an order on the table. Now the first thing I check is affVenomPrio[1], then second will be affVenomPrio[2], and so on. I can change the priority of afflictions by changing the order of the table.
    for _,v in pairs(affVenomPrio) do  -- for each affliction/venom in order</code>local i = 0</pre>Simply a counter for us to track how much of our&nbsp;<i>venoms</i> table we've filled up. This is actually totally unnecessary, as there's a different way to accomplish the same thing, but hopefully this makes the code a little more clear.&nbsp;<i>i</i> represents how many venoms we're calculating, and when we reach that limit, we stop!<br><pre class="CodeBlock"><code>
    This is the most complicated line of the code, so bear with me. The pairs function is a native Lua function that iterates over the keys and values of a table. Step by step, this function is going to return the next key and its value. For example, at one point it will return 3{"paralysis", "curare"}. We store those results in the local variables _, v

    _, v is interesting because of the underscore. And underscore in Lua means that we know there's something there, but we don't care about it. In this case, we know that the pairs() function is returning a key there, but we don't care about it, so we immediately throw it out. We only care about the value portion, which is going to be stored in the variable v.

    </code>if affstrack.score[v[1]] < 100 then -- if aff is < 100, choose that venom</pre></span><span>This line checks the score of an affliction. Remember&nbsp;<i>v</i> is the&nbsp;<i>value</i> of a <i>key</i> from our table. Its going to hold things like&nbsp;<i></i></span><span><i>{"asthma", "kalmia"}.&nbsp;</i>The snipped&nbsp;<i>v[1]</i> checks the first element of&nbsp;<i>v</i>. In this case, it would return the string&nbsp;<i>"asthma"</i> . The table&nbsp;<i>affstrack.score</i> is an example of a table that has non-number keys. The keys of this table are afflictions in the form of strings. We can access the value of these afflictions very similarly to how we accessed the value of element 1 of&nbsp;<i>v&nbsp;</i>earlier in this paragraph. Just replace the number with the key string!&nbsp;<i>affstrack.score["asthma"]</i> is a valid call, and will return the number associated with that affliction.&nbsp;<br></span><span><i><br></i>To summarize this statement, it says: When given a&nbsp;<i>value v</i>, check the&nbsp;<i>affstrack.score</i> of that value. If its less than 100, then continue<i><br></i></span><span><i></i><i></i><br><pre class="CodeBlock"><code>        venoms[i] = v[2]
            i = i + 1
            if i > 3 then break end -- once we've gotten 3 venoms, we're through
    This bit simply says that, if the above if statement is true, then we assign v[2] (which is a venom string, like "kalmia") to the next available slot in our venoms table. Once that's done, we increment so we know we've taken up another slot. Finally, if we've filled up 3 slots of our table, then we're finished! At that point, we break out of our for statement, which takes us to the end of our code!
    image
  • edited December 2017
    Jacen said:
    for _,v in pairs(affVenomPrio) do  -- for each affliction/venom in order
    This is the most complicated line of the code, so bear with me. The pairs function is a native Lua function that iterates over the keys and values of a table. Step by step, this function is going to return the next key and its value. For example, at one point it will return 3{"paralysis", "curare"}. We store those results in the local variables _, v

    _, v is interesting because of the underscore. And underscore in Lua means that we know there's something there, but we don't care about it. In this case, we know that the pairs() function is returning a key there, but we don't care about it, so we immediately throw it out. We only care about the value portion, which is going to be stored in the variable v.
    A nice explanation! Just 2 things in this part:
    - pairs does not necessarily run over the table in order. See https://www.lua.org/manual/5.1/manual.html#pdf-pairs and subsequentially https://www.lua.org/manual/5.1/manual.html#pdf-next
    - _ is no special variable or anything. It's just common practice. See https://stackoverflow.com/questions/34475995/variable-in-lua-has-a-special-meaning
  • edited December 2017
    And I just noticed another thing that would probably help readability: If you don't use a numbered table for the inner ones, but instead a dictionary, the code would look like this:
    <div>
    </div>
    <pre class="CodeBlock"><code><div>local venoms = {}
    local affVenomPrio = {
    &nbsp; &nbsp; {
    &nbsp; &nbsp; &nbsp; &nbsp; affliction = "asthma",&nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; venom = "kalmia"
    &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp;{
    &nbsp; &nbsp; &nbsp; &nbsp; affliction = "anorexia",
    &nbsp; &nbsp; &nbsp; &nbsp; venom = "slike"
    &nbsp; &nbsp; },
    &nbsp; &nbsp; {
    &nbsp; &nbsp; &nbsp; &nbsp; affliction = "paralysis",
    &nbsp; &nbsp; &nbsp; &nbsp; venom = "curare"
    &nbsp; &nbsp; },
    &nbsp; &nbsp; {
    &nbsp; &nbsp; &nbsp; &nbsp; affliction = "slickness",
    &nbsp; &nbsp; &nbsp; &nbsp; venom = "gecko"
    &nbsp; &nbsp; }
    }
    
    local i = 0
    for _, affVenomPair in ipairs(affVenomPrio) do&nbsp; -- for each affliction/venom in order
    &nbsp; &nbsp; if affstrack.score[affVenomPair.affliction] < 100 then -- if aff is < 100, choose that venom
    &nbsp; &nbsp; &nbsp; &nbsp; venoms[i] = affVenomPair.venom
    &nbsp; &nbsp; &nbsp; &nbsp; i = i + 1
    &nbsp; &nbsp; &nbsp; &nbsp; if i > 3 then break end -- once we've gotten 3 venoms, we're through
    &nbsp; &nbsp; end
    end</div>

    I also incorporated my ipairs fix (see above) into this.

    Edit: Formatting is killing me.
  • This might be a stupid question, but what does ipairs do over pairs?
  • ipairs goes over a numerically indexed table (where the keys are 1, 2, 3, ...) in order until it reaches the first "gap". pairs iterates over all keys (independent of type and doesn't care about "holes") in undefined order.
  • Ok, so I have tried making a function that is called by an alias that does that exact script and it isn't working. Am I even able to make venom[1] a variable or is the system confused by the [ ]?? What am I missing here?
  • From your description, this could be a number of things. If you get an error message, this one would be helpful to know. Also a screenshot of your alias setup and possibly a quote of how you want to use the script help as well.
  • venomprio()
    send("queue add eqbal throw axe at " .. target .." ".. venoms[1]..";queue add eqbal throw axe at " .. target .." ".. venoms[2]..";queue add eqbal throw axe at " .. target .." ".. venoms[3])

    that's what my alias executes, I tried venom[1] and venoms[1] so far

    I want to use the script to help me make venoms 1- 3 whatever is on top of the list. The affliction tracker is the afftrack.score.affliction bit that decides what to prioritize, does that make sense?
Sign In or Register to comment.