Looking for more active discussion? Join our Discord at https://discord.gg/x2s7fY6

Small Coding Questions

24567

Comments

  • SerriceSerrice the Black Fox
    @Dasha? Where!?
     
  • I'm trying to build a check in for my affliction tracking that will identify if an affliction in one table (enemyafflictionlist) is present in another table (focusCures).

    In the future, this will be used to count the number of mental affs, to help me track reclamation. But, for now, I can't even get it to compare the two tables.

    Any help much appreciated:


    1. function CountMentalAffs()
    2.  
    3. focusCures = {
    4.         "stupidity",
    5.         "anorexia",
    6.         "recklessness",
    7.         "indifference",
    8.         "vertigo",
    9.         "confusion",
    10.         "dizziness",
    11.         "epilepsy",
    12.         "berserk",
    13.         "masochism",
    14.         "dissonance",
    15.         "agoraphobia",
    16.         "claustrophobia",
    17.         "weariness",
    18.         "paranoia",
    19.         "dementia",
    20.         "hallucinations",
    21.         "hatred",
    22.         "pacifism",
    23.         "lonely",
    24.         "premonition"
    25. }
    26.         for k,v in pairs(enemyafflictionlist) do
    27.                    for a,c in pairs(focusCures) do
    28.                                 if k == a then
    29.                                  print("Mental")
    30.                                                                  break
    31.                                 else
    32.                                      print("NotMental")
    33.                                                                          break
    34.                                 end
    35.                         end
    36.              
    37.         end    
    38. end
    When I run this, and stick a mental aff, it always returns "NotMental" Any thoughts? Cheers
  • SetneSetne The Grand Tyrant
    You're using pairs on an indexed table.
    Also, have you not checked the error console? (This is for mudlet, right?)

    Ingram said:
    "Oh my arms are suddenly lubed"
  • for k,v in pairs(enemyafflictionlist) do
    if v and table.isMember(focusCures, k) then
    print("Mental")
    else
    print("NotMental")
    end
    end

  • edited June 2013
    Thanks, @kaeus and @setne

    This is actually for MUSHclient. I haven't had the time to switch my offense over to mudlet.

    Unfortunately that doesn't work @kaeus - I'm assuming it's because I'm using MUSH.

    @setne my abilities with lua are pretty abysmal. Most of what I've created is cobbled together from examples I've found, so there are some pretty significant gaps in my basic knowledge. e.g what the significance of pairs on an indexted table is. I'll go Google that now.
  • Sorry, forgot this dependency

    function table.isMember(table, member)

    for i, m in ipairs(table) do

    if m == member then

    return true

    end

    end

    return false

    end

  • @kaeus cheers, that works!
  • OleisOleis Producer Emeritus Administrator, Immortal
    A neat efficiency trick for Lua, to avoid lots of loops like that:

    Rather than a table of unlabeled values {"a", "b", "c"} where the important information is the VALUE, make it the KEY {a = true, b = true, c = true}. With this structure, testing for a word's presence in a table is as simple as table[key], leaving the Lua engine to do all the dirty work.

    For example:
    focuscures = {
      stupidity = true,
      paranoia = true,
      confusion = true,
    }

    for k, v in pairs(enemyAfflictionList) do
      if focuscures[k] then
        -- Mental!
      end
    end

    I hope that's helpful!
    You say to Slyphe, "You're so freaking smart."
    [---]
    "^," Slyphe agrees with you.
    SetneLin
  • Trying to get my head wrapped around tracking Syssin venom afflictions on dstab.

    Since adding to a string list pops it to the -bottom- of the list, and %pop pulls from the top..I'm thinking a database would be better?

    Not as familiar with doing that, since for my Templar tracking I have left venom, and right venom for the two weapons. (I don't use dual, but this would be helpful for bastard sword too!)

    If anyone can poke me IG or on here with some assistance, that'd be super appreciated. Just on how to add to the list, and how to pull from it, the actual affliction giving/etc, I already have.


    image
  • ..I made this harder than it needs to be, I can just go off the hit messages for dstab, instead of doing discerning the venom off..right?

    I r crazy.
    image
  • edited June 2013
    @saybre
    %push will add the item to the top of a string list, then you can %pop it off :D
    Saybre
  • OMG, you're my hero.
    image
  • I try.
    Haven
  • edited July 2013

    I added this line to my system to add a alias that will fire the next time I gain balance. It seems to send the command... but instead of expanding the alias to fire it sends the whole line expandAlias("firething") when all I want is it to send this firething. Please help and this is the line I wrote to do it all.

    addToQueue([[expandAlias("firething")]])

     

     

    Carnifex failing since 2011. Fixes coming Soon ™
  • LinLin Blackbird The Moonglade
    Your addToQueue() function is probably taking an argument and using send() to send it to the game, so yes, naturally, even with the braces it'll interpret expandAlias() as a literal text command.

    You're going to need to add an argument to addToQueue, and probably your queue handling script as well. Instead of adding the expandAlias() function directly, you'll want to supply either a command or an alias name, and also pass true to false.

    Using the mockup code in http://pastebin.com/JZmT9YZP, you would instead want to use addToQueue("firething", true) for an alias, or just addToQueue("firething") if not.
    Mastema
  • SetneSetne The Grand Tyrant
    Mastema said:

    I added this line to my system to add a alias that will fire the next time I gain balance. It seems to send the command... but instead of expanding the alias to fire it sends the whole line expandAlias("firething") when all I want is it to send this firething. Please help and this is the line I wrote to do it all.

    addToQueue([[expandAlias("firething")]])

     

     

    Since you're using expandAlias I'm gonna assume mudlet. Unfortunately, having no clue how the addToQueue function works, I can't really offer a fix, but usually it's better to use a function instead of using expandAlias. Have you tried just putting firething in there by itself?

    Ingram said:
    "Oh my arms are suddenly lubed"
    Mastema
  • edited July 2013

    Woot I will edit it. I think my brain is just dead today from looking over this old system for hours on end.

    @Lin cheers that is going to give me a few ideas.

    Carnifex failing since 2011. Fixes coming Soon ™
    Lin
  • FYI Mastema, the queue should automatically execute anything in it using expandAlias, you'd literally just have to do addToQueue("firething") (provided this is some variation of Earthshaker we are talking about)
  • LinLin Blackbird The Moonglade
    Oh wow, you're right, I'm really silly. expandAlias() sends the text directly to the server if it doesn't match any aliases, so you really can use it as a catch-all. Simplifies things a lot!
  • edited July 2013

    Making a offensive script and hit a dead end. If anyone can understand what I am trying to do can you assist please.

    send("hound initiative " .. tw.target)
    send("eat vial")
    send("soul discern " .. tw.target)
    if not tw.vitals.class == "carnifex" then return false end
    if tw.bals.both() 
    and can:act() then
    if pvp.affs.shield then 
    send("soul erode " .. tw.target) 
    elseif pvp.affs.rebounding then
    send("raze " .. tw.target)
    if not tw.defenses.bruteforce then  ---this is not firing. It should fire first before (thammer). Also it should only fire if I have a hammer wielded! As it is right now it does nothing :(
       expandAlias("force")
       else 
                              expandAlias("thammer") --this fires perfectly?
              end
          end
    end

    Carnifex failing since 2011. Fixes coming Soon ™
  • LinLin Blackbird The Moonglade
    I really wish you guys would post the information from your error window when you try to run these things. 9 times out of 10 you can figure it out from that alone.
    Setne
  • HavenHaven World Burner Flight School
    It looks like you're missing an else between raze Target and "if not tw.defenses". Otherwise it'll try firing the code only when they have rebounding and after it sends the raze command.
    ¤ Si vis pacem, para bellum. ¤
    Someone powerful says, "We're going to have to delete you."
    havenbanner2
  • the correct check for defenses in Tripwire is tw.defs.active.whatever, so your if needs to be "if tw.defs.active.bruteforce then". Should have sent me a message Mastema! =p
    Mastema
  • Cheers man works like a pro :D
    Carnifex failing since 2011. Fixes coming Soon ™
  • edited July 2013
    Lua question (Mudlet)

    What is the simplest and most eloquent way to change this:
    <red>Affliction<white>: <white>LEFTLEGBROKEN
    into this:
    LEFTLEGBROKEN

    Given the following unknowns:
    1. The affliction may be any affliction
    2. The colour codes may not always be red and white, so a simple :gsub("<red>Affliction<white>: <white>", "") is not the answer.

    (I'm busy replacing Kaeus's spammy all-on-a-line-of-their-own system echoes with right-aligned echoes on the same line as prompts, but he's got colour tags that go on for days. It's my biggest only criticism of both Tripwire and Citadel - they're both spammy as hell.)

  • edited July 2013
    Ignore the above question, I solved it. I was trying to use string.findPattern() with string.gsub(), to match and remove the <colour> tags one by one. This was the long way round and was far too clunky.

    this was the solution, for anyone interested:

    local s = string.findPattern(s, "[A-Z][A-Z]+")


    Matching single words of only capital letters.


  • RiluoRiluo The Doctor
    edited July 2013

    Looking for help building a dwhisper script that will send 2 whispers each time I regain balance. I have no clue how to script in mudlet as to be blunt I am utterly illiterate when it comes to this aspect of mudlet, so everything just goes over my head no matter how hard people try.

    I am looking to add it to a system I am currently using called Tripwire. If anyone has a clue how to do this please let me know.  All it needs to do is select from a table and send the first two whispers, if  the target has them already it will go to the next on the list. I understand this is a bit sad to ask for but I want to start playing again and at this point I am not going to even be of use in a simple spar. Luckly however I have a auto envenomer script which works perfectly. In terms of what I am looking for help with I do not expect to get much respect from people for doing this, but I am again -utterly illiterate- when it comes to this stuff and just do not have the ability to graps it anymore.

     

    I can track what they have already or cured, so it is more the deliver of the whispers I need help with please.

    Abhorash says, "Ve'kahi has proved that even bastards can earn their place."

  • So I'm working on this script for Leylines. I won't go too far into it but I need help with one part.

    I'm using parts from another system and trying to tweak it. This is what I have so far.

    <code>function onLeyRoom( event )

    if not ksys.ley.checking or ksys.ley.checked then return false end


    local thisRoom = gmcp.Room.Info.area

    local checkRoom = ksys.ley.checking


    for i,v in ksys.ley.RoomCor do

    if i == checkRoom then

    ksys.ley.connecting = {}

    send("area conn")

    addToQueue("ley")

    ksys.ley.checked = true

    end

    end

    end</code>

    Now basically what that does is compare checkRoom and thisRoom. Originally it was:

     

    <code>function onLeyRoom( event )

    if not ksys.ley.checking or ksys.ley.checked then return false end


    local thisRoom = gmcp.Room.Info.area

    local checkRoom = ksys.ley.checking


     

    if checkRoom == thisRoom then

    ksys.ley.connecting = {}

    send("area conn")

    addToQueue("ley")

    ksys.ley.checked = true

    end

    end</code>

     

    But obvisouly that didn't work cause the 'checkRoom' part would look something like:

     

    checkRoom = alaqssi_inlet

     

    And the thisRoom would look like:

     

    thisRoom = Alaqssi Inlet

     

    Since there is a space in the actual GMCP room variable, and none in the checkRoom(Own personal list of areas) there's the _ to make up for a space.

     

    What I did was make a new variable that looks like thus:

     

    <code>ksys.ley.RoomCor = {


    alaqsii_inlet = {"Alaqsii Inlet"},

    the_northern_ithmia = {"the Northern Ithmia"}

     

    }</code>

     

    As a starter variable.

     

    Now I'd like it so it checks both the checkRoom and the thisRoom variable against the RoomCor variable so that it matches both. Basically what the second bit of script says... But it doesn't do cause of the _ and the lower case letters.

     

    Am I missing something obvious? Is there a way to make a table with the two various variables I need to use, then have them compared against the two variables that are set locally and then finally fire?

     

    As a last note. I checked all variables manually, even set the locals ones to onetime variables so I could check them. They all get set correctly, it's just not matching them right with the coding I did to fire off the rest.... Any suggestions?

    'Those that do not attempt are those with the least stories to tell.'
  • MacavityMacavity Chicago, Il
    you can use a gsub to make it look like what you want to compare...

    checkRoom = ksys.ley.checking:gsub("_", " ")

    this would make alaqssi_inlet look like alaqssi inlet

    you can also use

     :lower() at the end of a var and this will cause all letters to be lower case
    :upper() make all letters in the var upper case


    “Unless someone like you cares a whole awful lot,
    Nothing is going to get better. It's not.” 
    ― Dr. Seuss, The Lorax

    Veritas says, "Sorry for breaking your system Macavity."
    Veritas says, "My boss fights crash Macavity's computer now."
  • SetneSetne The Grand Tyrant
    Just change:


    alaqsii_inlet = {"Alaqsii Inlet"},

    the_northern_ithmia = {"the Northern Ithmia"}


    to


    alaqsii_inlet = "Alaqsii Inlet"

    the_northern_ithmia = "the Northern Ithmia"


    Of course putting the variables in a table if need be, and do if table[valuechecking] then blah end

    Ingram said:
    "Oh my arms are suddenly lubed"
Sign In or Register to comment.