Announcement

Collapse
No announcement yet.

Mudlet: Scripting and Optimization

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mudlet: Scripting and Optimization

    Hi folks!

    As a semi-competent Mudlet user, one knowing full well the frustrations of both setting up and using the client for Akanbar specifically, I thought it would be nice to open a thread for quick explanations and questions on making the client "work" for you. An earlier thread [[here]] has a nice overview of basics, such as how to reference variables, create aliases and echoes, but this thread will start off with some simple configuration within the client itself.

    Problem: Everything looks weird, why does it look weird!

    When you create a new profile in Mudlet for Akanbar, you'll notice that things look...strange. There's a notable issue with linebreaks, to start off. Annoying, right? Ironically the display option that's supposed to fix linebreaks is the one that causes this. Too much fixing! While you can fiddle with all sorts of other, more obscure options and punch the screen a few times to patch it up, you'll find the one you need under the Main Display tab in Settings: Fix unnecessary linebreaks on GA servers.

    Keeping this unchecked will make everything read normally. This is also the tab you'll want for changing both the abysmal default font and the weird, edge-hugging text, as you can plainly see...

    Problem: Repeating repeating myself myself!

    Even using the newest, most stable version of Mudlet, you'll notice that logging in is sort of a pain - you have to enter your name twice, as the first command is sort of 'eaten up' by the client. Unfortunately this is a problem with the client itself, rather than user-end - it's also apparently unique to select games, for some reason. Jaethor has provided a tentative fix in a later post on this thread.

    Problem: The map, it does nothing!

    This has been solved! Your friendly neighbourhood Jaethor has compiled a functioning mapper script for Akanbar, which has its own thread [right here].

    Problem: But why are the variables gone?
    You will note that Mudlet does -not- store world variables, as clients like Portal, zMUD and MUSHClient do. However, they can be compiled into a script that will set the necessary ones on login, a topic breached [in that earlier thread]. You can also follow the guide in a later post in this thread to export/import your variables in a file.

    So! I'll be updating this post as more things come to mind, as well as answering any questions on the client and its capabilities that I'm able.
    Last edited by Nakarym; 16 February 2015, 02:53 AM.

  • #2
    Good guide to how to fix the "fun quirks" of mudlet.

    Originally posted by Nakarym View Post
    However, we're told this should be fixed in the next update.
    Happy one year anniversary of being constantly told "It will be fixed in the next update". Were I not a representation of Akanbar, I would have very strong words to say about Mudlet's empty promises.
    Tick tock goes the clock until you feel my ire. You'll lose your voice and turn to rock and lose what you desire.

    Comment


    • #3
      GMCP.lua.zip

      Fix for "Problem: Repeating repeating myself myself!"

      I've attached a zip file. It contains a fixed version of the GMCP file for mudlet. You can either manually fix your existing file following the changes in this github or you can replace your existing file with the one located in the zip file I've attached.

      You can discover the file location by right-clicking on your mudlet icon, then going to properties and it'll tell you the path. Copy the location at Start In, paste it in File Explorer and look for GMCP.lua

      If you're modifying the file, modify only the lines shown in the link. Should you have questions, please feel free to contact me. If you use this, please thank your friendly neighborhood Zycandos for finding the fix.
      Tick tock goes the clock until you feel my ire. You'll lose your voice and turn to rock and lose what you desire.

      Comment


      • #4
        Exporting and Importing Variables

        A big challenge for people moving to Mudlet from other popular clients, namely zMUD and MUSHClient, is the fact that variables are not stored locally - once you close your profile, unless you've preserved them/set them to reload from a list, your variables are all just gone when you come back. This is just a quick example of one way to store your important stuff and recall it later.

        First thing's first, you'll want a place to keep your variables. It's easiest to use your Mudlet profile folder, which you can find with getMudletHomeDir(). Either plug this in as the script of an alias, or run it from the command line if you have the capabilities (which I think I covered in another thread). The resulting print should be something like this:

        Code:
        "C:\Users\yourname\.config\mudlet\profiles\yourcharacter"
        It's not important to save this, as the getMudletHomeDir function can be plugged right into a script, but just in case you're wondering how it works!

        So now that you have the where, you need the what - you have to tell Mudlet what to save, when to save it. So make a trigger from the QUIT line, and plug something like this into the script:

        Code:
        saved = {
          variableFoo = "string",
          variableBar = 1
          }
         
        table.save(getMudletHomeDir() .. "/saved", saved) -- where first saved is the file to be made, and second saved is our table
        echo("\nSaved to "..getMudletHomeDir().."/saved") -- I like echoing things
        Then it's just as easy as using the table.load function to do the reverse, set to a login trigger, "Welcome to Akanbar" blah blah:

        Code:
        saved = saved or {} -- create the table, so it can be filled with the old data
        table.load(getMudletHomeDir() .. "/saved", saved) -- load said data, both file and table
        cecho("\nVariables loaded!") -- yay echoes
        Now, important fact to note (something I learned in working this all out myself): you cannot call variables in the usual fashion (table[1], table[key] etc.) when loading from an external file, as this only works for locally stored variables - you have to utilize the following format:

        Code:
        table.variable
        So if your table had a variable fruit, whose value was banana, you could not call table[1] or even table[fruit] to utilize the value banana in your scripting - you MUST call it as table.fruit. Alternatively, follow Jaethor's example in the next post and concatenate the lot of it:

        Code:
        "..table[1].." or "..table[fruit].."
        I, however, think this is hideous and unintuitive.
        Last edited by Nakarym; 16 February 2015, 04:03 AM.

        Comment


        • #5
          Originally posted by Nakarym View Post
          [B][SIZE=3]
          So if your table had a variable fruit, whose value was banana, you could not call table[1] or even table[fruit] to utilize the value banana in your scripting - you MUST call it as table.fruit.

          dances={
          tango = 1,
          salsa = 2,
          worm = "tra-la-la",
          chacha =4
          }

          display(dances)
          echo("I like to do the ".. dances["tango"].. "\n")
          echo("Nakarym tries to do the ".. dances["worm"].. "\n")
          Tick tock goes the clock until you feel my ire. You'll lose your voice and turn to rock and lose what you desire.

          Comment


          • #6
            Originally posted by Jaethor View Post

            dances={
            tango = 1,
            salsa = 2,
            worm = "tra-la-la",
            chacha =4
            }

            display(dances)
            echo("I like to do the ".. dances["tango"].. "\n")
            echo("Nakarym tries to do the ".. dances["worm"].. "\n")
            You like to do the 1, and I try to do the tra-la-la? I'm not sure you know how dancing works, Jaethor...

            Also here's another thing to help with the mapping: an alias to manipulate room placement. Definitely beats doing it with the mouse.

            Code:
            Pattern:
            ^rm (\w+)$
            
            Script:
            ox, oy, oz = getRoomCoordinates(mapper.currentRoom)
            if matches[2]=="west" or matches[2]=="w" then
                x = (x or ox) - 1; y = (y or oy); z = (z or oz)
              elseif matches[2]=="east" or matches[2]=="e" then
                x = (x or ox) + 1; y = (y or oy); z = (z or oz)
              elseif matches[2]=="north" or matches[2]=="n" then
                x = (x or ox); y = (y or oy) + 1; z = (z or oz)
              elseif matches[2]=="south" or matches[2]=="s" then
                x = (x or ox); y = (y or oy) - 1; z = (z or oz)
              elseif matches[2]=="northwest" or matches[2]=="nw" then
                x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)
              elseif matches[2]=="northeast" or matches[2]=="ne" then
                x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)
              elseif matches[2]=="southeast" or matches[2]=="se" then
                x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)
              elseif matches[2]=="southwest" or matches[2]=="sw" then
                x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)
              elseif matches[2]=="up" or matches[2]=="u" then
                x = (x or ox); y = (y or oy); z = (z or oz) + 1
              elseif matches[2]=="down" or matches[2]=="d" then
                x = (x or ox); y = (y or oy); z = (z or oz) - 1
            end
            setRoomCoordinates(mapper.currentRoom,x,y,z)
            centerview(mapper.currentRoom)
            Shamelessly stolen and mutilated to fit. RM E will move your current room one placement to the right. RM NW, one up and over to the left. Etc etc. Unfortunately I'm terrible with loops and therefore cannot get it work as intended (picking apart strings of directions), so for now you'll have to move it one step at a time.

            Results may vary. At present it's "broken" in that, once you move a room, then proceed to move another room, your first directional input will in fact place the second room as if you were placing the first, still. I'm sure I can fix this at a time when I'm not falling asleep, or at the very least beg Jaethor to do it for me.
            Last edited by Nakarym; 16 February 2015, 10:12 AM.

            Comment


            • #7
              Originally posted by Nakarym View Post
              You like to do the 1, and I try to do the tra-la-la? I'm not sure you know how dancing works, Jaethor...

              Also here's another thing to help with the mapping: an alias to manipulate room placement. Definitely beats doing it with the mouse.

              Code:
              Pattern:
              ^rm (\w+)$
              
              Script:
              ox, oy, oz = getRoomCoordinates(mapper.currentRoom)
              if matches[2]=="west" or matches[2]=="w" then
                  x = (x or ox) - 1; y = (y or oy); z = (z or oz)
                elseif matches[2]=="east" or matches[2]=="e" then
                  x = (x or ox) + 1; y = (y or oy); z = (z or oz)
                elseif matches[2]=="north" or matches[2]=="n" then
                  x = (x or ox); y = (y or oy) + 1; z = (z or oz)
                elseif matches[2]=="south" or matches[2]=="s" then
                  x = (x or ox); y = (y or oy) - 1; z = (z or oz)
                elseif matches[2]=="northwest" or matches[2]=="nw" then
                  x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)
                elseif matches[2]=="northeast" or matches[2]=="ne" then
                  x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)
                elseif matches[2]=="southeast" or matches[2]=="se" then
                  x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)
                elseif matches[2]=="southwest" or matches[2]=="sw" then
                  x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)
                elseif matches[2]=="up" or matches[2]=="u" then
                  x = (x or ox); y = (y or oy); z = (z or oz) + 1
                elseif matches[2]=="down" or matches[2]=="d" then
                  x = (x or ox); y = (y or oy); z = (z or oz) - 1
              end
              setRoomCoordinates(mapper.currentRoom,x,y,z)
              centerview(mapper.currentRoom)
              Shamelessly stolen and mutilated to fit. RM E will move your current room one placement to the right. RM NW, one up and over to the left. Etc etc. Unfortunately I'm terrible with loops and therefore cannot get it work as intended (picking apart strings of directions), so for now you'll have to move it one step at a time.

              Results may vary. At present it's "broken" in that, once you move a room, then proceed to move another room, your first directional input will in fact place the second room as if you were placing the first, still. I'm sure I can fix this at a time when I'm not falling asleep, or at the very least beg Jaethor to do it for me.

              Why not just do (if you're using my mapper):
              Code:
              Pattern:
              ^rm (\w+)$
              
              Script:
              ox, oy, oz = getRoomCoordinates(mapper.currentRoom)
              
              -- Converts your inputted directional string into a number
              local direction = convertDirToNum(matches[2]);
              -- Moves from the old coordinates, using gotten direction, to new coordinates
              x, y, z = calculateRoomCoord(direction, ox, oy, oz)
              
              setRoomCoordinates(mapper.currentRoom,x,y,z)
              centerview(mapper.currentRoom)
              If you then wanted to loop it

              Code:
              Pattern:
              ^rm (\w+)\s?(\d*)$
              
              Script:
              local timesToMove = 1
              
              if matches[3] ~= "" then
              	timesToMove = matches[3]
              end
              
              x, y, z = getRoomCoordinates(mapper.currentRoom)
              
              -- Converts your inputted directional string into a number
              local direction = convertDirToNum(matches[2]);
              
              for i = 1, timesToMove, 1 do
              -- Moves from the old coordinates, using gotten direction, to new coordinates
                 x, y, z = calculateRoomCoord(direction, x, y, z)
              end
              
              setRoomCoordinates(mapper.currentRoom,x,y,z)
              centerview(mapper.currentRoom)
              Tick tock goes the clock until you feel my ire. You'll lose your voice and turn to rock and lose what you desire.

              Comment


              • #8
                Originally posted by Jaethor View Post
                If you wanted to loop it
                The loop was more for the string, using string.gmatch to accept 'nw nw w' and other such things as opposed to one movement at a time. Also, for some reason I never thought of hooking in to the directional table, you truly are a god amongst gods. Will try this out.

                ALSO THIS IS TOTALLY NOT EVEN THE RIGHT THREAD OOPS.
                Last edited by Nakarym; 16 February 2015, 06:08 PM.

                Comment


                • #9
                  Code:
                  Pattern:
                  ^rm (.*)$
                  
                  Script:
                  local directions = string.split(matches[2], " ")
                  
                  x, y, z = getRoomCoordinates(mapper.currentRoom)
                  
                  -- Converts your inputted directional string into a number
                  
                  for index, dir in pairs(directions) do
                  -- Moves from the old coordinates, using gotten direction, to new coordinates
                     local dirNum = convertDirToNum(dir);
                     x, y, z = calculateRoomCoord(dirNum, x, y, z)
                  end
                  
                  setRoomCoordinates(mapper.currentRoom,x,y,z)
                  centerview(mapper.currentRoom)
                  Tick tock goes the clock until you feel my ire. You'll lose your voice and turn to rock and lose what you desire.

                  Comment


                  • #10
                    Thought I should mention, the double login problem is now a non-issue with the latest stable version of Mudlet, 3.0.0-delta, which is available [here].

                    Comment

                    Working...
                    X