Small Coding Questions

13567

Comments

  • DaegonDaegon CanadaMember Posts: 89 ✭✭✭
    Awesome. Thanks for the help, both of you. I've decided to go with the first idea since it means I don't need the extra variable for the script.
    'Those that do not attempt are those with the least stories to tell.'
  • DaegonDaegon CanadaMember Posts: 89 ✭✭✭

    And I'm back! With another, probably easy, question.

     

    So I have a static prompt. Meaning that it stays in one place unless I hit enter, or something from the server is sent my way.

     

    What I would like to do is have it, if possible, to move my prompt without flooding me full of Prompt lines. I know deleteFull() will work for removing the prompt lines, but how would you's suggest I go about having it so that it actually fires the prompt without the aforementioned things happening?

     

    I don't want to have to go through every trigger line and setup a variable so that the system does an if statement within the prompt seeing if it just double fired then deleting the second prompt.... Is there an easier way? Or is this a road that plenty of people have gone down and thus there isn't much to do but have something like a timer tick once in a while?

     

    I remember an old Mudlet system, think back when Kaeus was first building his, that wouldn't have double prompts and the like. It would always have one prompt between all lines that appeared. Was this just a fluke? Or is there a way to do that?

    Thanks!

    'Those that do not attempt are those with the least stories to tell.'
  • IrruelIrruel Member Posts: 670 ✭✭✭✭
    Why are you getting double prompts? Are you gagging lines of text, and that is why you're getting prompts? If so, it's simple enough to gag line+prompt rather than just the line.

    If it happens all the time regardless, I suspect there is a preference setting to do with telnet protocols etc which you need to check/uncheck.
  • DaegonDaegon CanadaMember Posts: 89 ✭✭✭
    I'm not getting double prompts. My question is how to have my prompt continuously fire, if possible, but not flood my screen with prompts.
    'Those that do not attempt are those with the least stories to tell.'
  • IrruelIrruel Member Posts: 670 ✭✭✭✭
    edited September 2013
    You can send a blank line on a recurring timer, which will prompt a prompt. If this is with mudlet, you could then gag the previous line upon the arrival of the new prompt, though getting the code for this right is a bit finicky.

    I hate playing around with moveCursor(), as it, for some reason, never seems to work the way I plan so it winds up involving a lot of trial and error - so I'm not going to write it for you. Still, here is a list of mudlet functions you'll need, and you can find examples on how to use them in the mudlet wiki. FYI, in mudlet you can move the cursor anywhere in the scrollback, and gag, echo, whatever, anywhere you like. It's just a bit awkward to do it as the reference point is always the current line, which obviously changes - a lot.



    getLineCount()

    moveCursor()
    selectLine() (tbh, don't quite remember if this is a func or not, you may need selectString(line,1) or similar)

    check selection (is it a prompt?)

    deleteLine()  (or you may need to use replace() for this one, can't recall)

    moveCursorEnd("main")



    Daegon
  • DaegonDaegon CanadaMember Posts: 89 ✭✭✭

    Awesome, Thanks Irruel.

     

    That gives me a baseline, and at least I know it is possible! Lol, I'll give updates here if it works.

    'Those that do not attempt are those with the least stories to tell.'
  • DaegonDaegon CanadaMember Posts: 89 ✭✭✭
    Back, yet again.

    Still trying to grasp Tables properly. I'm working with gmcp.Room.players and trying to put the names in there into a table within Mudlet so it will then echo back who's all there on a side window.

    But so far all I'm successfully doing is copying exact what is under gmcp.Room.players:

    {
      {
        name = "Jensen",
        fullname = "Lion Jensen Starion, the Cannibal Cook"
      },
      {
        name = "Daegon",
        fullname = "Daegon"
      }
    }

    Is what I'm getting. Anytime I try to echo it back it gives me nothing, or simply the number of 'variables' or names within the new variable. So how do I get it to recognize only the names and only display them?
    'Those that do not attempt are those with the least stories to tell.'
  • MacavityMacavity Member Posts: 803 ✭✭✭
    There is actually already one on the forums that works great!  


    Its in there just read the posts.  You may find other things that you may find interesting.
    “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."
  • AztonAzton Member Posts: 230 ✭✭✭
    it even makes the box for you :P

  • DaegonDaegon CanadaMember Posts: 89 ✭✭✭
    Irruel said:
    You can send a blank line on a recurring timer, which will prompt a prompt. If this is with mudlet, you could then gag the previous line upon the arrival of the new prompt, though getting the code for this right is a bit finicky.

    I hate playing around with moveCursor(), as it, for some reason, never seems to work the way I plan so it winds up involving a lot of trial and error - so I'm not going to write it for you. Still, here is a list of mudlet functions you'll need, and you can find examples on how to use them in the mudlet wiki. FYI, in mudlet you can move the cursor anywhere in the scrollback, and gag, echo, whatever, anywhere you like. It's just a bit awkward to do it as the reference point is always the current line, which obviously changes - a lot.



    getLineCount()

    moveCursor()
    selectLine() (tbh, don't quite remember if this is a func or not, you may need selectString(line,1) or similar)

    check selection (is it a prompt?)

    deleteLine()  (or you may need to use replace() for this one, can't recall)

    moveCursorEnd("main")



    Just want to say thanks for this. Finally got a around to messing with it and have a working script for this. It was a pain in the arse, but we got'r working.
    'Those that do not attempt are those with the least stories to tell.'
  • KonaiKonai Member Posts: 15
    so I'm trying to make a 'highligher' system for my enemies, so far I have

    function addEnemy(name)


    name = name:title()


    table.insert(mayhem.list.enemies, name)


    cecho("<red>" .. name .. " <white>has been added as an enemy")

    end


    I've never messed with color coding and what I keep doing keeps messing up and sending EVERYthing that color.. So I am wondering if any of you would be able to advise me on a way to make ^ color the name?

    Also Keep the color for when I relogin etc
    Lamb is not the same as a SHEEP!
  • KonaiKonai Member Posts: 15
    edited October 2013
    @Irruel That's what I been trying to get to work but it wont work!

    As I dont just want to use it for 'enemies' No Worries I'll keep looking around

    Said script doesnt delete the color once its added and you remove, you can only set 1 color so everyone allies/friends/citymembers/enemies etc etc will all be the same color...
    Lamb is not the same as a SHEEP!
  • AztonAzton Member Posts: 230 ✭✭✭
    IN Mudlet how do you align the text better?

    I have a few HELP files which are like

     - Stilltongue: Hidden whispers
     - Shadowblow: hi

    but the Alignment is all wrong, Anyone know how to align it so 'Hidden whsipers' and 'hi' start on the same 'space' so to speak?

  • IrruelIrruel Member Posts: 670 ✭✭✭✭
    edited November 2013
    @azton
    I feel as though string.format() ought to be able to offer a simpler solution for this, but I've never bothered to learn how to use it. So!

    The following is a bit rough; I made it up as I went. But it seems to work, so...



    function test3( c1, c2, pos ) local pos = pos or 15 if string.len(c1) < pos then local diff = pos - string.len(c1) local spaces = string.rep( " ", diff ) c1 = c1 .. spaces end send("\n" .. c1 .. c2 .. "\n") end Edit: I seem to have screwed up the code tag thing.
    Post edited by Irruel on
  • SetneSetne The Grand Tyrant Member Posts: 835 ✭✭✭✭✭
    You can use string.format to fix spacing yes. I know Vadi posted an example either on the mudlet forums, the wiki, or both.
    Love gaming? Love gaming stuff? Sign up for Lootcrate and get awesome gaming items. Accompanying video.

    Ingram said:
    "Oh my arms are suddenly lubed"
  • AztonAzton Member Posts: 230 ✭✭✭
    edited November 2013
    Irruel said:
    @azton
    I feel as though string.format() ought to be able to offer a simpler solution for this, but I've never bothered to learn how to use it. So!

    The following is a bit rough; I made it up as I went. But it seems to work, so...




    function test3( c1, c2, pos ) local pos = pos or 15 if string.len(c1) < pos then local diff = pos - string.len(c1) local spaces = string.rep( " ", diff ) c1 = c1 .. spaces end send("\n" .. c1 .. c2 .. "\n") end Edit: I seem to have screwed up the code tag thing.

     @Irruel Thanks soo much!!
    Post edited by Azton on

  • RiluoRiluo The DoctorMember Posts: 821 ✭✭✭✭
    edited December 2013

    fixed

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

  • IrruelIrruel Member Posts: 670 ✭✭✭✭
    function attwin_click(m)

    echo("\nattwin_click fires with: <" .. m .. ">\n")

    echo(type(m))


    if m == "off" then echo(hello) end

    end



    This is what is displayed/echoed when the function is run with an argument of "off". I have tried calling the function both with the intended click of a label, and directly from script. The result is the same:



    attwin_click fires with: <off>
    string


    Why won't the if statement evaluate true, when the echoes clearly prove that m is a string with a value of 'off'?

  • OleisOleis Producer Emeritus Member, Administrator, Immortal Posts: 1,393 admin
    It's erroring when it hits echo(hello), most likely. Unless you have a defined variable named hello, you're going to want to switch that to echo("hello")
    You say to Slyphe, "You're so freaking smart."
    [---]
    "^," Slyphe agrees with you.
    Irruel
  • IrruelIrruel Member Posts: 670 ✭✭✭✭
    Ah bugger. Its always something simple. Weird that the bug window didn't throw up an error, but thanks heaps!
  • KikonKikon Member Posts: 52 ✭✭✭
    I find it weird that it's echoing to you 'string'. If anything it should say nil. Hmm...
  • OleisOleis Producer Emeritus Member, Administrator, Immortal Posts: 1,393 admin
    Kikon said:

    I find it weird that it's echoing to you 'string'. If anything it should say nil. Hmm...

    String comes from the echo(type(m)) on the third line.
    You say to Slyphe, "You're so freaking smart."
    [---]
    "^," Slyphe agrees with you.
  • HavenHaven World Burner Flight SchoolMember Posts: 2,286 ✭✭✭✭✭
    edited February 2014
    I cannot figure this out and it's driving me nuts.

    [blockquote]
    company = {"list", "Lyl", "Ezalor"}
    for k,v in pairs(company) do
    if (v ~= "list") then
    list = "v, "
    end
    end
    [/blockquote]

    For some reason list is cropping up nil when I go to print it or call it. And I don't understand why... In hind sight, I'd expect the code to at the very least show me: company.list = "Ezalor, "

    Ultimately what I want is to do this:
    Send ("wt @Target is at " .. location .. " with " .. company.list)

    x_x I must be way off or something.

    Edit:

    When I do this:

    for k, v in pairs(company) do
    print (k, v, i)
    end

    I get this result:
    1 list nil
    2 Lyl nil
    3 Ezalor nil
    ¤ Si vis pacem, para bellum. ¤
    Someone powerful says, "We're going to have to delete you."
    havenbanner2
  • KaeusKaeus Member Posts: 209 ✭✭✭
    edited February 2014
    send("wt @target is at " .. location .. " with " .. table.concat(company.list), ", "))

    also, you need to format your table like this.
    company = { list = {"Lyl", "Ezalor"}} if you want to refer to it like that.
  • HavenHaven World Burner Flight SchoolMember Posts: 2,286 ✭✭✭✭✭
    edited February 2014
    Kaeus said:
    send("wt @target is at " .. location .. " with " .. table.concat(company.list), ", "))

    also, you need to format your table like this.
    company = { list = {"Lyl", "Ezalor"}} if you want to refer to it like that.
    well I only included Lyl and Ezalor for testing purposes. Normally it'd be just this:

    company = {list}

    And I'd have triggers that add/remove names from the table like when I sense someone or scent or something.

    Edit: So I tried it your way. I changed company to this:
    company = {"Lyl", "Ezalor"}

    Send ("wt Haven is in Nirvana. [Company: " .. table.concat(company)", ")

    Now the error I get is this:

    Run-time error
    World: Aetolia [Lilith]
    Immediate execution
    [string "Command line"]:1: attempt to call a string value
    stack traceback:
            [string "Command line"]:1: in main chunk
    Post edited by Haven on
    ¤ Si vis pacem, para bellum. ¤
    Someone powerful says, "We're going to have to delete you."
    havenbanner2
  • KaeusKaeus Member Posts: 209 ✭✭✭
    you need to give a separator for table.concat, so do table.concat(company, ", ")
    Haven
  • OmeiOmei Member Posts: 751 Immortal
    edited February 2014
    company = {"list", "Lyl", "Ezalor"}
    for k,v in pairs(company) do
    if (v ~= "list") then
    list = "v, "
    end
    end

    This won't work because you're using an indexed list, which is to say that it's just a series of values, rather than a key/value pair. So first off, you should be using the ipairs() function, not pairs().

    In line #4, when you're setting the value of list, you're setting a global variable called list. Unfortunately, you're also setting it improperly. If you fix the pairs() issue and then do display(list), it will probably have a value of "v, ". company.list isn't changing because you never do anything with it.

    list = "v, " --> company.list = v .. ", "

    Now, the last problem is that this won't work anyway, because list -technically- isn't defined. What you have is a string at index [1], whose value is "list". The table you had set up initially actually looks like this:

    company = {
    [1] = "list",
    [2] = "Lyl",
    [3] = "Ezalor"
    }

    As has been mentioned so far, the table structure itself could use a little work. Try this, instead:

    company = {"Lyl", "Ezalor"}
    company.list = {}
    for _, name in ipairs(company) do
    -- We only care about the value in this script.
    -- Instead of "v", let's name it "name" to make it easy to identify.
    if name ~= "Omei" then
    -- Just an example to show filtering.
    -- Set an index equal to the current size of company.list + 1
    -- If the list is empty, the index is 1.
    -- The value of this index will be the name pulled from company.
    company.list[#company.list + 1] = name
    end
    end

    This is still a little unwieldy - I don't personally like mixing up the sorts of things I put in tables, for instance, and would make company.list its own separate table. But hopefully it shows you how to fix up your code!

    With this method, you would then do:

    Send("wt Haven is in Nirvana. \(Company: " .. table.concat(company.list, ", ") .. "\)")



    Edit: Whoops, guess I was ninja'd something fierce. Oh well.
    image

    i am rapture coder
    HavenDraimanXarian
  • HavenHaven World Burner Flight SchoolMember Posts: 2,286 ✭✭✭✭✭
    Kaeus said:
    you need to give a separator for table.concat, so do table.concat(company, ", ")
    Woo! Thank you.
    ¤ Si vis pacem, para bellum. ¤
    Someone powerful says, "We're going to have to delete you."
    havenbanner2
  • KaeusKaeus Member Posts: 209 ✭✭✭
    Omei said:
    company = {"list", "Lyl", "Ezalor"}
    for k,v in pairs(company) do
    if (v ~= "list") then
    list = "v, "
    end
    end

    This won't work because you're using an indexed list, which is to say that it's just a series of values, rather than a key/value pair. So first off, you should be using the ipairs() function, not pairs().

    In line #4, when you're setting the value of list, you're setting a global variable called list. Unfortunately, you're also setting it improperly. If you fix the pairs() issue and then do display(list), it will probably have a value of "v, ". company.list isn't changing because you never do anything with it.

    list = "v, " --> company.list = v .. ", "

    Now, the last problem is that this won't work anyway, because list -technically- isn't defined. What you have is a string at index [1], whose value is "list". The table you had set up initially actually looks like this:

    company = {
    [1] = "list",
    [2] = "Lyl",
    [3] = "Ezalor"
    }

    As has been mentioned so far, the table structure itself could use a little work. Try this, instead:

    company = {"Lyl", "Ezalor"}
    company.list = {}
    for _, name in ipairs(company) do
    -- We only care about the value in this script.
    -- Instead of "v", let's name it "name" to make it easy to identify.
    if name ~= "Omei" then
    -- Just an example to show filtering.
    -- Set an index equal to the current size of company.list + 1
    -- If the list is empty, the index is 1.
    -- The value of this index will be the name pulled from company.
    company.list[#company.list + 1] = name
    end
    end

    This is still a little unwieldy - I don't personally like mixing up the sorts of things I put in tables, for instance, and would make company.list its own separate table. But hopefully it shows you how to fix up your code!

    With this method, you would then do:

    Send("wt Haven is in Nirvana. \(Company: " .. table.concat(company.list, ", ") .. "\)")



    Edit: Whoops, guess I was ninja'd something fierce. Oh well.
    That was quite an excellent explanation regardless. Always prefer to teach rather than solve (when time permits).
    HavenSetne
Sign In or Register to comment.