Integrating focus on an IRE MUD

Post Reply
Lyco
Posts: 2
Joined: Sun Jun 15, 2014 6:36 pm

Integrating focus on an IRE MUD

Post by Lyco »

Hi guys quick question. So I am trying to integrate focus in with my system. I have it set up so that when I can focus and when I can't I have two separate affliction tables that I check so that I don't try to cure something that can be cured by focus. However, when trying to put them together I have only been able to get it to focus and eat without waiting or just focus and not try to eat when I cant focus. I have it set up like this:

function cure_herbs()

if canfocus()
then
cureherbsfocus()
if canfocus() == false and system.mechanics.focusing == false
then
cureherbsnofocus()
end
end
end

Am new to mudlet but how this reads to me is if I can focus then it should run the cureherbsfocus function then stop. If I cant focus and I am not currently focusing (which gets set to false on prompt and true from the focus line) then it runs the code in the cureherbsnofocus function.

Any insight on this would be a big help. Thanks

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Integrating focus on an IRE MUD

Post by demonnic »

Code: [show] | [select all] lua
if canfocus() then
  cureherbsfocus
elseif not canfocus() and not system.mechanics.focusing then
  cureherbsnofocus()
end
I think this is closer to what you're looking for. The two if statements aren't connected in any way in your previous code, so what it does is check to see if you can focus, and if so it runs cureherbsfocus(). Then, whether that worked or not, it would check if canfocus() == false and system.mechanics.focusing == false.

The way I wrote it above, if the first one evaluates to true then it won't even bother evaluating the second one.

Lyco
Posts: 2
Joined: Sun Jun 15, 2014 6:36 pm

Re: Integrating focus on an IRE MUD

Post by Lyco »

Thanks for the help. That plus I set some echos up to see what was happening. GMCP was removing focus balance a prompt before I actually focused so thats why both were getting run. Your help plus changing some stuff around fixed that. Thanks

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Integrating focus on an IRE MUD

Post by Oneymus »

The reason both would be run is because what you have is a nested if statement. Properly formatted, it would be this:
Code: [show] | [select all] lua
function cure_herbs()
    if canfocus() then
        cureherbsfocus()

        if canfocus() == false and system.mechanics.focusing == false then
            cureherbsnofocus() 
        end
    end
end
Basically, you would never have called cureherbsnofocus() without first calling cureherbsfocus(). While Lua can be written flat as you did here (assuming it's not just a transcription error), you should always endeavour to use proper formatting. It's not just eye candy; it can help you find subtle flaws in your logic and structure.

User avatar
SlySven
Posts: 1023
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Integrating focus on an IRE MUD

Post by SlySven »

Use "[ code ]" "[/ code ]", or hit the "Lua" button to put "[ Lua ]" "[/ Lua ]", around (though without the spaces inside the '[' ']' 's I have to put in to make them show up) previously typed in Lua code, in the editor dialog on these pages. It then formats your entry appropriately - preserving the indentation and spacing and in the latter case highlighting the stuff between the tags, which helps to make it more readable for everyone. :geek:

Especially since Demonnic fixed the buttons on the "Full" editor a few days ago. :lol:

Post Reply