Python dict, and iteration

Posted by Rakon on Tue 15 Nov 2005 01:27 AM — 5 posts, 26,491 views.

USA #0
Greetings once agian.Simple question, hopefully has a simple answer.Im attemping to put a curelist together through scripting, and well, I cant figure out how to get the right cure for a certian affliction.Heres a part of what I have so far



def cureit(name,output,wildcards):

	pbal = world.GetVariable("pbal")
	anor = world.GetVariable("anorexia")
	eq = world.GetVariable("eq")
	paralysis = world.GetVariable("paralysis")
	pipes = int(world.GetVariable("pipes"))
	pipe1 = world.GetVariable("pipe1")
	pipe2 = world.GetVariable("pipe2")
	pipe3 = world.GetVariable("pipe3")
	asleep = world.GetVariable("asleep")
	cures1 = {"stupidity":"goldenseal"}

	if pbal == "no":
		return
		
	if anor == "yes":
		world.Send("smoke " + pipe2)
		return
	else:
		cures = {"stupidity":"goldenseal","paralysis":"bloodroot","confusion":"ash"}
		for c, v in cures.iteritems():
			world.SetVariable("pbal","no")
			world.Send("outr %s" % (v))--now here,no matter the affliction, script sends "outr ash" to the world.
			world.Send("eat %s" % (v))--and here it always sends "eat ash" 
			return
		


What I am trying to do is have a trigger call cureit, and use the approatie cure.Heres is the test trigger I have for it


<triggers>
<trigger
enabled="y"
match="* casts a net of stupidity over your mind."
script="cureit"
send_to="12"
sequence="100"
>
<send>world.ColourTell ("red", "black", "[AFFLICTED]: ")
world.ColourNote ("white", "black", "Stupidity")
world.SetVariable("stupidity", "on")</send>
</trigger>
</triggers>



Thanks. --Rakon
USA #2
Well, I decided not to muck around ith the Dictionary, and all, Just have a standard if/elif clause going.Thanks though!

--Rakon
#3
You can use a dictionary you just need to use it properly. Your For loop is just iterating through the dictionary without checking whats on so it will always cure what it sets as first.
USA #4
Jestre,thanks for your reply.I have the if/elif working like I need it to, but the whole issue with the Python Dict, was to try and use less memory so that MUSHclient wouldn't crash when it gets to be too much.So far, no problems,so I hope it stays that way.

--Rakon