Mudlet Scripting

1121314151618»

Comments

  • AnetteAnette Member Posts: 814 ✭✭✭
    edited July 2017
    Don't really feel like belabouring the point since people might be on a non-current mudlet.  So for those who aren't:
    function toboolean(value)
       if (value==true) then
          -- why are you feeding bools to something named toboolean?
          return true
       elseif (value==false) then
          -- why are you feeding bools to something named toboolean?
          return false
       elseif (tonumber(value)~=nil) then
          if (tonumber(value)>0) then
             return true
          else
             return false
          end
       else
          return false
       end
    end
    

    It was a bit confusing to me we have tostring and tonumber but not toboolean.  It would have been one of the first things I'd've added with booleans when they added a boolean type.

    [edit]: Pet peeve: WSIWYG editors that ... aren't at all what you see is what you get.

    image
  • AysariAysari Member Posts: 152 ✭✭✭
    edited July 2017
    I prefer this, personally.
    function toBoolean(s)	
       local st = (type(s) == "string" and string.lower(s) or s)
       if type(st) == "number" and st >= 1 then st = "1" end
       if st == true or st == "true" or st == "on" or st == "1" or st == "yes" or st == "yep" or st == "y" then
          return true
       else
          return false
       end
    end
    If a number greater than (or equal to) 1 is given, then it returns true. If what you pass under toBoolean(whatever) is true, "true" or anything really that's a 'positive answer' then it will return true. Anything else and it'll return false. I can parse pretty much everything my system uses through it, and it'll work perfectly.

    image
    Sarrius
  • VadiVadi Member Posts: 34 ✭✭
    I don't have a toBoolean function in my system at all... there's a reason it's not in Lua's stdlib! Here's how Svof captures balance: https://github.com/svof/svof/blob/master/raw-svo.controllers.lua#L1248
    Rokas
  • GjarrusGjarrus Member, Beta Testers Posts: 482 ✭✭✭✭
    ^repeat(?:| (\d+) (.*))$
    
    
    repeatTheThing = function()
    
    if repeater.active then
    repeater.timer = tempTimer(repeater.time,[[send(repeater.action) repeatTheThing()]])
    end
    
    end
    
    if not repeater then repeater = {} end
    if not repeater.active then repeater.active = false end
    
    if matches[2] then
    
     repeater.time = tonumber(matches[2])
     repeater.action = matches[3]
    end
     
    if not repeater.active then
      send(repeater.action)
      repeater.timer = tempTimer(repeater.time,[[send(repeater.action) repeatTheThing()]])
    	repeater.active = true
    else
      repeater.timer = nil
    	repeater.active = false
    end
    

    repeat time action to do the action every at that interval. repeat to stop and start it. You might want to add echoes.
  • EdonEdon Member Posts: 1
    Could I get someone to point me in the direction of a defenses manager, or is there one that I am somehow missing?

    Just trying to figure this whole defenses-on-queue thing.
  • AnetteAnette Member Posts: 814 ✭✭✭
    Vadi said:
    I don't have a toBoolean function in my system at all... there's a reason it's not in Lua's stdlib! Here's how Svof captures balance: https://github.com/svof/svof/blob/master/raw-svo.controllers.lua#L1248
    The actual reason is probably "they only recently actually added a boolean type and didn't add the support functions like that in when they did."
    image
  • VadiVadi Member Posts: 34 ✭✭
    That might be true too!

    Also, found this interesting tidbit while looking up the history of Lua:

    It turned out that Bret Mogilefsky was the lead programmer on Grim Fandango, the main adventure game LucasArts released in 1997. In another message he told us that "A TREMENDOUS amount of this game is written in Lua" (his emphasis). This first use of Lua in a game attracted the attention of many game developers around the world to the language.



    Wyll
  • AhruizAhruiz Member Posts: 4
    edited October 2017
    Do not know if this question has been answered before. I am trying to track purge blood and focus. Both of these sometimes cure afflictions with 3P cure messages. I need a way to have a trigger activate one piece of code if the following line is a 3P cure which I think is easy, just use a chain of length 1 on the general message and code in the two or three 3P cure messages. What I do need help with is finding a way to have a piece of code trigger only if there is no 3P affliction message after it. How can I do that?

    Edit: Can I do something like: Write a multiline AND trigger like this:
    Line 1) ^A look of extreme focus crosses the face of (\w+).$
    Line 2) ^(.*)$

    And then make each 3P affliction message an if conditional, so if none of them are met than the other piece of code for non-3P messages fires?
  • RycRyc Member, Beta Testers Posts: 33 ✭✭
    3p triggers can be tracked directly using the 3p message in a single line trigger. You can then do something like 
    Line 1) ^A look of extreme focus crosses the face of (\w+).$  Perl Regex
    Line 2) return isPrompt() Lua Function
    This trigger only fires if the line immediately after the cure is your prompt, meaning that 3p Triggers don't fire it's curing.
    AhruizAodanVadi
  • AodanAodan Member Posts: 165 ✭✭✭
    edited October 2017
    Ryc said:
    3p triggers can be tracked directly using the 3p message in a single line trigger. You can then do something like 
    Line 1) ^A look of extreme focus crosses the face of (\w+).$  Perl Regex
    Line 2) return isPrompt() Lua Function
    This trigger only fires if the line immediately after the cure is your prompt, meaning that 3p Triggers don't fire it's curing.
    Thanks so much for that, seriously. When I get bored at work I like to think about the changes I want to make to my system and the rewrite I want to do, and the problem I was running in to was figuring a way to work around having to remove 2 affs because of the 3ps. The changes I was going to make were to be a little more efficient at non 3ps. This idea will help complete the idea. 
  • AhruizAhruiz Member Posts: 4
    I think that did it for me, thank @Ryc. My code should look like this, correct?
    Trigger for non-3p cured:
    Line 1) ^A look of extreme focus crosses the face of (\w+).$ --Perl Regex-- 
    Line 2) return isPrompt() --Lua Function-

    Trigger for 3p cured - in this case, Stupidity
    Line 1) ^A look of extreme focus crosses the face of (\w+). (\w+)'s expression no longer looks so vacant. --Perl Regex--



  • RycRyc Member, Beta Testers Posts: 33 ✭✭
    The 3p trigger would look like 
    ^(\w+)'s expression no longer looks so vacant\.$ Perl Regex
    There's no need for the focus line, or really any curetype line for a 3p cure, just trigger off of the 3p message itself. (the exception being if you want to track what the last of each curetype cured is)
  • AnetteAnette Member Posts: 814 ✭✭✭
    I wouldn't say there's no need at all, it can rule out illusions and the like, but the last time I saw someone use illusions in combat was a couple IRL years ago.  That said you can get by without it.
    image
  • DimitriDimitri Somewhere coldMember Posts: 277 ✭✭✭
    I'm not sure how you could implement this, but for some lulz on your end.

    http://doom.wikia.com/wiki/Status_bar_face_hysteresis

    Seems like the doomguy status faces could be useful as a visual representation of how you're doing. Or at least entertaining.
  • AgeranuAgeranu Member Posts: 14
    Howdy guys, I'm trying to start all over again and was trying to implement some checks along the way.. I've ended up with something like..
     
    alias ss
    mountCheck()
    spearCheck()
    send("spear stab "..target)

    where:
    function mountCheck()
    if gmcp.Char.Vitals.mount == "XXXX" then
    send()
    else send("mount XXXX")
    end
    end

    and:
    function spearCheck()
    if (gmcp.Char.Vitals.leftwield == "XXXX") and (gmcp.Char.Vitals.rightwield == "XXXX") then 
    send()
    else send("quickdraw spear shield")
    end
    end

    My problem is, this works if I'm dismounted and not holding my spear... but otherwise it just stops in the functions called.. how do I get it to proceeed through to the next section?  I f -think- the issue is the send() inside the functions, but I'm not sure what I should put there instead..
  • AodanAodan Member Posts: 165 ✭✭✭
    That would be the only thing I see being weird. Just change your equal tos (==) to to not equal tos (~=) so one would look like this:

    if gmcp.Char.Vitals.mount ~= x then
      send("mount "..x)
    end

    Excuse if it's not perfect I typed from my phone, but you get the drift.
    Ageranu
  • SumieSumie Member Posts: 60 ✭✭✭
    The problem is you're trying to use the function Send() when it requires an input. Such as Send("say hi") etc. So you're getting an error from the missing string which is why the function is stopping. I'm not sure why you felt like you needed to use send at all. Just removing the send and leaving that part of the if statement blank would have done the same thing such as

    function mountCheck()
       if gmcp.Char.Vitals.mount == "XXXX" then 
       else send("mount XXXX")
       end
    end


    Ageranu
  • RokasRokas Member Posts: 63 ✭✭✭
    Do what @Aodan suggested. You don't need an else statement for every if, and it's better to negate in the original condition.
    Aodan
  • OwynOwyn USMember Posts: 158 ✭✭✭
    edited December 2017
    If you didn't have some sort of wrapper, now's a good time to start updating your systems. The way actions are queued is going to change soon to where you can stack action queues natively. This queue update also means that if you're spamming an alias that's using queue eqbal, you're now making a legit list of actions instead of just one. Friendly reminder.
    Post edited by Owyn on
    Swale
  • SeptusSeptus Member, Beta Testers Posts: 744 ✭✭✭✭✭
    Leading on from Owyn's comment, a better way to handle that kind of thing is to pass a function rather than a prefix. I tried to avoid that in the example above because that can confuse a lot of people who aren't used to first class functions, but something like:

    function queueEqbal(command)
        send("queue eqbal clear" .. your separator .. "queue eqbal " .. command)
    end

    function rawSend(command)
        send(command)
    end

    function ifeqbal(command)
        send("ifeqbal " .. command)
    end

    function dispatch(sendMethod)
        command = join(action table, your separator)
        sendMethod(command)
    end

    then you can do like:

    dispatch(queueEqbal)
    dispatch(rawSend)
    dispatch(ifeqbal)

    Etc. This is objectively  better, but its also more complicated if you're not comfortable with how functions work. It does let you weather major gameside changes like queueing rewrites etc without significant problems, however. Of course, you can achieve similar behaviour using a prefix style with something like:

    dispatch("queue eqbal clear " .. your separator .. "queue eqbal")

    However, this limits what you can do and is also fragile. At this point you're starting to make the system do something outside of the obvious and are having to compose strings as arguments to get the behaviour you want. This isn't ideal. Some people like to pass a string to their dispatch equivalent then lookup the correct function from a separate table. This does work, but is almost always because they went with a prefix approach initially then didn't want to rewrite major sections of their aliases to conform to a more function based approach. Perfectly valid, regardless.

    But basically, do what you're comfortable with. I tend to recommend a prefix approach to people who are just learning, because it works and has less abstraction from what you already understand (game mechanics). The function approach is better, overall, though.
    VadiAodanOwyn
  • VadiVadi Member Posts: 34 ✭✭
    Great example of using functions as first class variables 
    SarriusOwyn
Sign In or Register to comment.