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

[Mudlet] Code Snippets

2»

Comments

  • TysandrTysandr Posts: 342Member ✭✭✭✭ - Eminent
    Tysandr said:


    Someone asked for the trigger pattern that I was asked to use, here it is:


    Proof of Concepts: LogrSailing MapTrading
    Simple Nexus things: jqol
    "It's not rocket surgery."

  • VadimusesVadimuses Posts: 1,058Member @ - Epic Achaean
    That could be part of the mapper script, seems pretty handy to have
    CaelanTysandr
  • SobriquetSobriquet Posts: 1,874Member @@ - Legendary Achaean
    That is really cool script, Thanks!
    image
  • KeneanungKeneanung Posts: 573Member ✭✭✭✭ - Eminent
    Vadimuses said:
    That could be part of the mapper script, seems pretty handy to have
    It is now!
    VadimusesTysandrLaerinCailin
  • VadimusesVadimuses Posts: 1,058Member @ - Epic Achaean
    Have no idea where your function is getting called from? Find out with:

    echo(debug.traceback())

    RomTysandrKlendathu
  • TysandrTysandr Posts: 342Member ✭✭✭✭ - Eminent
    Vadimuses said:
    Have no idea where your function is getting called from? Find out with:

    echo(debug.traceback())

    Damn, wish I had known that one. :(
    Proof of Concepts: LogrSailing MapTrading
    Simple Nexus things: jqol
    "It's not rocket surgery."

  • VadimusesVadimuses Posts: 1,058Member @ - Epic Achaean
    The Lua manual is just about the only language manual I've ever read and it's the most useful one
  • VadimusesVadimuses Posts: 1,058Member @ - Epic Achaean
    edited February 2
    This hasn't been mentioned on its own yet - there's another way of assembling text using string.format. It can help where things with .. get messy:


    echo("target is: "..target..", current health: "..currenthealth..", maxhealth: "..maxhealth)

    -- or:

    echo(string.format("target is: %s, current health: %s, maxhealth: %s", target, currenthealth, maxhealth))

    TysandrZulah
  • VadimusesVadimuses Posts: 1,058Member @ - Epic Achaean
    When you've filled up your screen debugging your system, clear it all with:

    lua clearWindow()

  • PyoriPyori Posts: 138Member ✭✭✭ - Distinguished
    Vadimuses said:
    When you've filled up your screen debugging your system, clear it all with:

    lua clearWindow()


    ...............................................................................

    How did I not know you could do this on the buffer... Given how much I use it everywhere else you'd think I'd have tried...
    Tysandr
  • VadimusesVadimuses Posts: 1,058Member @ - Epic Achaean
    All of the following are valid ways to call a function with one argument to it. Take your pick:

    myfunction("some value")
    myfunction('some value')
    myfunction ("some value")
    myfunction ('some value')
    myfunction"some value"
    myfunction'some value'
    myfunction "some value"
    myfunction 'some value'


    Or stick with what you do. You've got choices!

    Tysandr
  • AustereAustere TennesseePosts: 2,146Member @@ - Legendary Achaean
    Vadimuses said:
    All of the following are valid ways to call a function with one argument to it. Take your pick:

    myfunction("some value")
    myfunction('some value')
    myfunction ("some value")
    myfunction ('some value')
    myfunction"some value"
    myfunction'some value'
    myfunction "some value"
    myfunction 'some value'


    Or stick with what you do. You've got choices!

    @Zulah :)
    Zulah
  • NazihkNazihk Posts: 886Member @ - Epic Achaean
    If you really want to mess with people, pick a function call syntax at random every time you call a function. 
  • PyoriPyori Posts: 138Member ✭✭✭ - Distinguished
    Nazihk said:
    If you really want to mess with people, pick a function call syntax at random every time you call a function. 
    If you want people to never ask for your scripts, just do a dice roll every time you make a function and have it call one of the above at random. Like have one alias call myFunction"value", another one do myFunction2("value") and a third do myfunction 'value' and so on.

    Randomly alternate between tab, double space, triple space for indenting.

    For concatenation sometimes have spacing, other times don't. So like (var1 .. "+".. var2.. " - " .. var3 ), etc.

    Make the first half of your code have legible formatting, and following proper code practices. So like myFunction( value1, value2) -- if value2 > value 1 then .... Then halfway through your code start doing Myfunction( Value1, value2) etc etc.

    ...I could go on...

    I've been tempted to do it a number of times, to see how long it'd take people to notice... But I don't hate myself enough to go through with doing it :(
  • ZulahZulah Posts: 727Member @ - Epic Achaean
    Austere said:
    Vadimuses said:
    All of the following are valid ways to call a function with one argument to it. Take your pick:

    myfunction ("some value")

    Or stick with what you do. You've got choices!
    @Zulah :)
    @Austere just because you CAN do something doesn't mean you should though!
    Caelan
  • AntoniusAntonius Posts: 4,374Member @@ - Legendary Achaean
    Zulah said:
    Austere said:
    Vadimuses said:
    All of the following are valid ways to call a function with one argument to it. Take your pick:

    myfunction ("some value")

    Or stick with what you do. You've got choices!
    @Zulah :)
    @Austere just because you CAN do something doesn't mean you should though!
    This. One of the most important things when coding is to make the intention as clear as possible to the reader. By using the brackets for all of your function calls, you're making it clear to anybody else reading the code (including yourself months later) that the variable is meant to refer to a function and that you meant to call that function.

    As an example of what I mean, consider this code:
    local a, b = myvariable "some string"
    
    Did I mean to call the function that's referred to by "myvariable", passing in the string "some string" to it? Or do I have a minor syntax mistake, and I actually meant local a,b = myvariable, "some string" (i.e. assign the value of myvariable to a and the string "some string" to b)?

    The syntax is valid in both cases, but the meaning is completely different. If myvariable doesn't refer to a function (because I meant the latter - though I could have meant the latter even if myvariable did refer to a function), I get a runtime error when the code executes. If I come and look at this code six months later, there's an additional step in reasoning that myvariable should be a function with a single parameter and which returns multiple values, though I may want to go and confirm for myself again that I didn't mean to have the comma there.

    Not to mention that 1. you need to use brackets when you have a number of parameters that's not one, and 2. the bracketless syntax doesn't work in plenty of other languages. It just really doesn't seem like a good habit to get into.
  • CaledCaled Posts: 14Member
    Right-click a poorly formatted script, and select 'Format all'.

    I was dubious when I saw this feature in one of the mudlet updates, but it actually worked really nicely for me just now, when I was trying out a script from someone on this forum, that had no indentation.


    VadimusesCailinTysandr
  • BrenexBrenex Posts: 3Member
    That's neat, the only problem is it does remove spaces between code blocks which I feel can help improve readability if doing it correctly
  • KeneanungKeneanung Posts: 573Member ✭✭✭✭ - Eminent
    It is opinionated so people always have the same style and don't need to fiddle with settings.
2»
Sign In to Comment.