Mudlet Scripting

1121314151618»

Comments

  • AnetteAnette Member Posts: 729 ✭✭✭
    edited July 5
    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 28
    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: 23 ✭✭
    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 Posts: 424 ✭✭✭
    ^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: 729 ✭✭✭
    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: 23 ✭✭
    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
Sign In or Register to comment.