My Curing System so far... and it doesn't work

Post Reply
User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

My Curing System so far... and it doesn't work

Post by Jules »

Okay, so I have my mind wrapped around a logical idea for my curing system, and here's how it goes: MUD line comes in that is picked up by the appropriate Trigger; trigger fires the function "addAff()" who's code is:

Code: Select all

function addAff(affl)
	if type(affl) == "string" then
		affs.affl = true
	end
end
"affl" is the variable that gets added depending on the trigger. So, if the trigger matches "Your left arm breaks", addAff() will add "brokenleftarm" to the list "affs".

From there, the function "cureAff()" is sent out. Here's the "cureAff()" code:

Code: Select all

function cureAff()
	for k,v in pairs(affs) do
		if affs.(affliction goes here) == true then
			send(appropriate curing alias)
		end
	end
end
What this SHOULD be doing is searching through the "aff" list and finding the appropriate key, in this case, the affliction, and if the value attached to the affliction key is "true", then it executes the appropriate alias to cure the affliction.

Now, I've been testing this on a simple trigger that breaks my left arm. I've had the debugging window open while testing this, but Mudlet doesn't seem to be picking up the affliction trigger, only the trigger that fires when the affliction is cured. Could someone help me debug this? And if you need any clarification in my explanation, please ask. I tried to be as clear as possible.

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

Re: My Curing System so far... and it doesn't work

Post by Vadi »

Could you post screenshots of your trigger & debug window?

goose
Posts: 13
Joined: Sun Jun 14, 2009 2:51 pm

Re: My Curing System so far... and it doesn't work

Post by goose »

Don't know about the trigger matching without seeing your settings, but:
> affs = { a = true, b = false, c = false }
> affl = "d"
> affs.affl = true
> for k,v in pairs(affs) do io.write(k..":"..(v and "true" or "false").."\n") end
a:true
affl:true
c:false
b:false
> affs[affl] = true
> for k,v in pairs(affs) do io.write(k..":"..(v and "true" or "false").."\n") end
a:true
c:false
b:false
d:true
affl:true
So I'd change

Code: Select all

affs.affl = true
to

Code: Select all

affs[affl] = true

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: My Curing System so far... and it doesn't work

Post by Jules »

Okay, I noticed what was going on with my code. I'm imaging my hard drive right now because I accidentally deleted something that I shouldn't have... And now I have to fix it... But that's another story for another day!

Anyhow, goose, for my FOR statement, does it have to written like

Code: Select all

for k,v in pairs(affs) do io.write(k..":" ..(v and "true" or "false")
Or can I keep it how I originally wrote it, but change affs.affl to affs[affl]?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: My Curing System so far... and it doesn't work

Post by Heiko »

I would not use aliases to do the curing. It's much simpler to do the curing with a simple function call.
Aliases are triggers that run on user input and I can't see any need for user input in this context as the system is fully automatic as I understand it. However, *IF* you still want to go the alias route, you'll need to use expandAlias() instead of send() because send() sends the output directly over the network layer to the MUD without using alias expansion to avoid recursion issues.

Lua is extremely flexible and allows for many things: checkout these links:
http://mudlet.sourceforge.net/phpBB3/vi ... ?f=6&t=448
http://www.lua.org/pil/5.html
http://www.lua.org/pil/6.html
http://www.lua.org/pil/6.1.html

goose
Posts: 13
Joined: Sun Jun 14, 2009 2:51 pm

Re: My Curing System so far... and it doesn't work

Post by goose »

The for-loop, and everything in the quote box was just copy-pasted from lua in interactive mode to show how it works. I just meant you should change "affs.affl" to "affs[affl]" in your scripts.

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: My Curing System so far... and it doesn't work

Post by Jules »

Woot! Everything is working right and proper now! Thank you, thank you everyone for all of the help!

Also, the only alias' that I use are to easily take the proper cures (herbs, vials, pipes) out of their respective containers, use them, then put them back. They make life pretty easy!

Post Reply