cycling through variables

Posted by Bobble on Sun 23 Jun 2002 05:54 PM — 3 posts, 16,581 views.

Canada #0
Greets all,

I'm embarassingly new to scripting and programming of any kind. Everything I've learned of scripting has been learned in the last couple of days, so I may be asking a very basic question.

Anyway, on the MUD I'm playing there are several afflictions (i.e. blindness, nausea, etc.) you can be given via poisons and what not. Each of these afflictions can be cured by eating a certain type of plant. My problem is that you're only allowed to eat a plant every two seconds, but you can be given several different afflictions at once. I need a way to keep track of what I've been afflicted with and then automatically eat the appropriate plants.

For instance, if I'm afflicted with blindness and nausea at the same time, I'll need to have "eat bloodroot" sent to the MUD to cure the blindess and then have "eat ginseng" sent two seconds later to cure the nausea.

What I've done so far is set up variables for each of the afflictions. The name of each of these variables starts with affliction_ followed by the affliction name ,so the variable for blindness is called affliction_blindness. I've set up triggers to change the contents of each of these variables if I've been afflicted with them. So if I'm given blindess, the contents of the affliction_blindness variable will be set to "on" and if I'm cured of the blindness, the contents will be set to "off"

What I need now is a script that can be run that will cycle through each of these afflictions, find all the ones that are "on" and put the appropriate plants into a queue that will send "eat <next plant in queue>" to the mud every 2 seconds until the queue is empty.

If it helps, maybe try giving me a sample script where the afflictions I've been given are blindness, nausea and stupidity. The appropriate plant cures are as follows:

blindness: bloodroot
nausea: ginseng
stupidity: goldenseal

Any help is appreciated and I'll be more than happy to clarify any ambiguities. Thanks!
#1
I think it was Magnum who was working on and successfully(?) built a spell queue, you could look into that although understanding how to use it might take quite a bit of scripting.

If you've already set up a trigger to toggle on/off the afflictions, all you have to do is use the DoAfter command and (with the way I'm doing it) another variable to keep track of the number of things you'll need to eat

var wait=blindness+nausea+stupidity (assuming you're toggling between true and false)
if blindess=1 then
world.doafter (6-wait*2), "eat bloodroot"
wait=wait-1
end if
if nausea=1 then
world.doafter (6-wait*2), "eat goldenseal"
wait=wait-1
end if
if stupidity=1 then
world.doafter (6-wait*2), "eat bloodroot"
wait=wait-1
end if

For a longer list you'd probably be better off using arrays.
Australia Forum Administrator #2
You can use "getvariablelist" to do that, quite simply. Try something like this:


dim value, spell, delay
delay = 2
For Each v In world.GetVariableList
  value = world.GetVariable (v)
  If Left (v, 11) = "affliction_" Then
   spell = Mid (v, 12)  ' spell is after "affliction_"
   If value = "on" Then  ' do if spell is active
     Select Case spell 
       case "blindness" world.doafter delay, "eat bloodroot"
       case "nausea"    world.doafter delay, "eat ginseng"
       case "stupidity" world.doafter delay, "eat goldenseal"
     End Select
     delay = delay + 2
   End If  ' end spell "on"
  End If   ' end variable starting with "affliction_"
Next


Maybe turn the affliction off afterwards? Like this:


world.setvariable v, "off"


You could do that after the line "delay = delay + 2"