M
Mudlet•3y ago
Delra

Okay. So, I separate things out as much as possible. First, I put all my code for building a UI into

Okay. So, I separate things out as much as possible. First, I put all my code for building a UI into one folder; then, I separate out the things for building a model of the data that the UI uses into another folder. That probably sounds kinda weird, but bear with me. So, I keep a table (of tables) of all the important information that the game sends me. It often looks something like this:
me = me or {}
me.vitals = me.vitals or {
hp = 5000,
maxhp = 5000,
mp = 5000,
maxmp = 5000,
}
--etc and so on
me = me or {}
me.vitals = me.vitals or {
hp = 5000,
maxhp = 5000,
mp = 5000,
maxmp = 5000,
}
--etc and so on
Then, I create another folder of event handlers, to update my information. Those handlers look something like this:
function onVitals()
local vit = gmcp.Char.Vitals
local hp = tonumber(vit.hp)
local maxhp = tonumber(vit.maxhp)
me.vitals.hpdiff = hp - me.vitals.hp --checks old values against new values
--etc
me.vitals.hp = hp
me.vitals.maxhp = maxhp
me.vitals.hpper = me.vitals.hp/me.vitals.maxhp -- hpper as in hp percent
--etc and so on
end
function onVitals()
local vit = gmcp.Char.Vitals
local hp = tonumber(vit.hp)
local maxhp = tonumber(vit.maxhp)
me.vitals.hpdiff = hp - me.vitals.hp --checks old values against new values
--etc
me.vitals.hp = hp
me.vitals.maxhp = maxhp
me.vitals.hpper = me.vitals.hp/me.vitals.maxhp -- hpper as in hp percent
--etc and so on
end
Now, finally, I have all of my data separated out, configured into the Types that I need, and ready to go. This lets me plug it in pretty seamlessly elsewhere. I actually do end up modifying bars, etc with a prompt type trigger still, because I can guarantee that on a prompt, I have received all gmcp events that are relevant to me.
hpbar:setValue(me.vitals.hp, me.vitals.maxhp, f"{me.vitals.hp}/{me.vitals.maxhp}, {me.vitals.hpper}%")
hpbar:setValue(me.vitals.hp, me.vitals.maxhp, f"{me.vitals.hp}/{me.vitals.maxhp}, {me.vitals.hpper}%")
8 Replies
Delra
Delra•3y ago
I use values like me.vitals.hpdiff so I can put those things on my prompt. I didn't use SVO, so this was necessary for achieving feature parity. I know this seems like more up-front work, but it saves you a lot down the road, but not having to tonumber(gmcp.Char.Vitals.hp) all the time 😄 and also do fun things like:
if (me.vitals.hpdiff/me.vitals.maxhp) >= 0.5 then
cecho("<red>ALERT! YOU JUST LOST AT LEAST HALF YOUR HEALTH! YOU ARE GETTING OWNED!")
end
if (me.vitals.hpdiff/me.vitals.maxhp) >= 0.5 then
cecho("<red>ALERT! YOU JUST LOST AT LEAST HALF YOUR HEALTH! YOU ARE GETTING OWNED!")
end
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Delra
Delra•3y ago
Yes, also, that's only ever called once the code you copied there; it's just to have some values available when you turn on Mudlet the or makes sure those values don't overwrite current, real values (updated by the gmcp hooks) onVitals, for example, is registered to gmcp.Char.Vitals
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Delra
Delra•3y ago
that's right The biggest use of this process here here is that I am A) turning strings into numbers where strings are not useful for me, and B) able to derive new information from old er... no I am able to derive new information beyond what it just gives me (such as the difference between values between prompts)
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Delra
Delra•3y ago
For sure! This was the best part of Achaea for me, when I played 😂
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server