Page 1 of 1
Balance and Equilibrium checker
Posted: Sat Dec 05, 2009 6:25 am
by Mordocai
I would like to set up a generic function that will check for balance/equilibrium then, if i don't have it, wait until it comes back and then continue with the alias/trigger/whatever that called the function. I have triggers to set variables bal and equil to 0 when i use it and 1 when it's recovered. However, if i do a simple loop that loops and does nothing until bal or equil = 1, It basically just assumes it is 1 and goes on.
I can't show what i've tried because copying from mudlet doesn't work on my system, but i was wondering if anyone could show me how to do this.
Thanks,
Mordocai
Re: Balance and Equilibrium checker
Posted: Sat Dec 05, 2009 4:29 pm
by Vadi
Well, this is possible... but are you sure you want to go with this architecture? I can see it being messy when things start getting queued up / not finishing in time and etc.
The typical way to do this is to have your triggers set flags for the actions you'd need to do, and when you get both balance and eq back, run a check over all the flags, and do the things you need.
ie, when you fall down, you do
prone = 1
and when you get balance or eq back, you'd to this:
Code: Select all
if balance ~= true and equilibrium ~= true then return end
if prone == 1 then
send ('stand')
end
Re: Balance and Equilibrium checker
Posted: Sat Dec 05, 2009 8:54 pm
by Mordocai
So, would i have a trigger that goes off when i get my equilibrium/balance back and then checks to see what it needs to do based on variables set by other triggers? I'm sorry, fairly new to coding in general... and really new to coding for a MUD.
Re: Balance and Equilibrium checker
Posted: Sun Dec 06, 2009 12:15 am
by Mordocai
By the way, i originally came up with this because i wanted one alias that would set up all my defenses in order and not have to be run multiple times.
Re: Balance and Equilibrium checker
Posted: Sun Dec 06, 2009 12:55 am
by Vadi
So, would i have a trigger that goes off when i get my equilibrium/balance back and then checks to see what it needs to do based on variables set by other triggers?
Yep.
By the way, i originally came up with this because i wanted one alias that would set up all my defenses in order and not have to be run multiple times.
Well that's a nice idea, but what if you want to pause the defup? And how will the alias not defup stuff you already have? and such
Re: Balance and Equilibrium checker
Posted: Sun Dec 06, 2009 7:02 am
by Iocun
If it's really just for a defup alias and isn't supposed to keep defences up all the time, then a coroutine might be a suitable implementation for this, yes? (I'm may be wrong since I'm a total Lua noob and only learned about coroutines yesterday
). Start with the defup, after putting up the first defence, yield and wait till you get balance or equilibrium back, then resume the coroutine, and repeat this for all defs. This would also allow you to pause it.
Re: Balance and Equilibrium checker
Posted: Sun Dec 06, 2009 12:55 pm
by Vadi
Heh, well... having an alias that has a whole bunch of ifs and yields instead of if, elseifs would do I guess. But unfortunately Mudlet doesn't support coroutines yet, it requires some special implementations which we'll get to later.
Re: Balance and Equilibrium checker
Posted: Wed Dec 09, 2009 11:47 am
by Caled
Assuming this is for an IRE mud.
In your prompt trigger, capture the part of your prompt stats that tells you whether you have balance/equilibrium or not. For example, the bolded part:
[pcsdb
eb]
or for Lusternia:
-ex
You want to match the eb, --, e- and -b
Use: ([eb-]{2}) in the appropriate part of your prompt trigger pattern.
In your prompt script:
Code: Select all
eqbal = matches[5] -- assuming "5" is the capture group the above matches
-- Check if time to raise onEqbal --
if eqbalcheck == 1 then
eqbalCall()
end
In a script object:
Code: Select all
eqbalcheck = 0
function eqbalCheck()
x=0
if eqbal == "eb" then x=1 end
return x
end
function eqbalCall()
if eqbalCheck() == 1 then
eqbalcheck = 0
onEqbal()
end
end
function onEqbal()
-- here you have your commands to check for actions that require balance/eq, such as lighting pipes, ordering entities, blah blah
-- here you have your commands to check for actions that require and use balance, like rejecting people, or putting back critical defences such as spirit bonding
-- here you have your commands to execute actions from a queue, such as your next attack.
end
Re: Balance and Equilibrium checker
Posted: Wed Dec 09, 2009 2:56 pm
by Vadi