Mudlet Control Across Different Profile

beckham894
Posts: 15
Joined: Thu Aug 30, 2018 2:07 pm

Mudlet Control Across Different Profile

Post by beckham894 »

I am just wondering if it is possible to control mudlet (e.g enable or disable trigger class) across different profile?
Let say if I am work on Profile A, but I want to tell Profile B to en/disable a specific trigger class without switching to Profile B.
Is this possible? Thanks.

jbrumble
Posts: 15
Joined: Sat Jan 09, 2021 4:31 am

Re: Mudlet Control Across Different Profile

Post by jbrumble »

Hello Beckham,

I'm fairly new to Mudlet, but I do have a solution that is a bit of a workaround for this.

Code: Select all

local updateStatus = "recoverStart" or {}
expandAlias(updateStatus)
raiseGlobalEvent("sysSendAllProfiles", updateStatus)
If you use this in one profile you can create an alias on the other profile that activates on "recoverStart" and has an enableTrigger() function.

I suspect that a better method does exist, but this is what I've been using currently.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Mudlet Control Across Different Profile

Post by Vadi »

raiseGlobalEvent() is the way to go!

I wouldn't use expandAlias(), but rather make a function:
Code: [show] | [select all] lua
-- profile B:
control = control or {}
function control.updateStatus()
  disableTrigger("test triggers")
  print("disabling triggers worked!")
end

-- this handles calling the right function in the control table
function control.marshaller(_, callfunction)
  if control[callfunction] then control[callfunction]()
  else
    cecho("<red>Asked to call an unknown function: "..callfunction)
  end
end

registerAnonymousEventHandler("sysSendAllProfiles", "control.marshaller")

-- profile A:
raiseGlobalEvent("sysSendAllProfiles", "updateStatus")
raiseGlobalEvent("sysSendAllProfiles", "invalidfunction")

beckham894
Posts: 15
Joined: Thu Aug 30, 2018 2:07 pm

Re: Mudlet Control Across Different Profile

Post by beckham894 »

I do know that there is a code raiseGlobalEvent()
however, that isn't what I want to do, because as far as I understand when I use raiseGlobalEvent to en/disable trigger class X; trigger class x will be en/disable in BOTH profile.
meanwhile what i want to achieve is just en/disable trigger class X in profile B from profile A, while trigger class X (let say they have the same class name) in profile A stay unchanged.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Mudlet Control Across Different Profile

Post by Vadi »

It will not disable it in both profiles, try it first :)

You can also pass the profile name with the event so you can tell which event the profile came from.

beckham894
Posts: 15
Joined: Thu Aug 30, 2018 2:07 pm

Re: Mudlet Control Across Different Profile

Post by beckham894 »

Vadi wrote:
Mon Jan 25, 2021 8:55 pm
It will not disable it in both profiles, try it first :)

You can also pass the profile name with the event so you can tell which event the profile came from.
I don't quite understand how the code works, but yay it works. Big thanks and I will try work on it.
Do I have to register each function I want to call globally?
Also let say if I have profile A, B & C, if I raise global event it will also call in both profile B & C?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Mudlet Control Across Different Profile

Post by Vadi »

Check out https://wiki.mudlet.org/w/Manual:Event_Engine which explains how to work with events, that'll get you a long way!

You can't register a function globally, you register it within each profile (so you can customise it if you want) and when the global event fires, every profile will locally call that function.

beckham894
Posts: 15
Joined: Thu Aug 30, 2018 2:07 pm

Re: Mudlet Control Across Different Profile

Post by beckham894 »

Vadi wrote:
Tue Jan 26, 2021 8:33 am
Check out https://wiki.mudlet.org/w/Manual:Event_Engine which explains how to work with events, that'll get you a long way!

You can't register a function globally, you register it within each profile (so you can customise it if you want) and when the global event fires, every profile will locally call that function.
So registerAnonymousEventHandler is required for EACH function I want to call upon globally (or set it up in script window)?
currently when I use raiseGlobalEvent("sysSendAllProfiles", "updateStatus") from profile a, two things happen in profile b:
1. the function itself (disable trigger + print)
2. it sends a cmd "updateStatus"

is that normal?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Mudlet Control Across Different Profile

Post by Vadi »

> So registerAnonymousEventHandler is required for EACH function I want to call upon globally (or set it up in script window)?

No because a single function calls all others as needed. You just need to define them in the same way control.updateStatus is

> 2. it sends a cmd "updateStatus"

That's not normal and the code above doesn't do that - I think you might have changed something locally

beckham894
Posts: 15
Joined: Thu Aug 30, 2018 2:07 pm

Re: Mudlet Control Across Different Profile

Post by beckham894 »

Vadi wrote:
Wed Jan 27, 2021 4:12 pm
> So registerAnonymousEventHandler is required for EACH function I want to call upon globally (or set it up in script window)?

No because a single function calls all others as needed. You just need to define them in the same way control.updateStatus is

> 2. it sends a cmd "updateStatus"

That's not normal and the code above doesn't do that - I think you might have changed something locally
Now I know why, it is because there is a "send-text-to-all-games" package loaded in both of my profiles (part of the default package I think).
Which means all "sysSendAllProfiles" event is duplicate, the 2nd cmd is in fact a expandAlias("updateStatus")

Should I remove the "send-text-to-all-games" package?

Post Reply