Cycling through a list

Posted by Cron0 on Sat 04 Oct 2003 01:20 AM — 3 posts, 14,073 views.

United Kingdom #0
Lets say i have a variable, @poison, and i have a list of different values that this variable can be (all the different poisons my character has access to). How can i set up aliases to step forwards and backwards through the list, changing the value of @poison each time?

The list of poisons could be hardcoded into the script, but it would add flexibility if i could use aliases to manage the list, ie 'addpoison *' and 'removepoison *' or somesuch.

I have a feeling this shouldn't be difficult, but i couldn't find anything on the forums already, can anybody help me out please?
Australia Forum Administrator #1
I would do something like store the list in one variable, and the current item number in another. eg.

poisons = hemlock, root of carrot, floggle juice
poison_count = 2

Then use "split" to split the list into an array, eg.

poisonlist = Split (GetVariable ("poisons"), ",")


Use poison_count to work out which one to use, and then add 1 to it, reverting back to the start when ubound (poisonlist) was reached.

Then you could make aliases to add or remove from the list.
United Kingdom #2
Thanks Nick, in case anyone is looking for something similar, this is what I have so far:


world.setvariable "poisons", "NONE,kly,wyg,bukandas,nann,grimleaf,acaana,mandrake,quirrog,kaskamak,exaar,vaxvarna"
world.setvariable "poison_current", 0
dim poison_count

sub step_forward (thename, theoutput, thewildcards)
	poison_count = poison_count +1
	dim poisonlist
	poisonlist = Split(world.getvariable("poisons"), ",")
	if ubound(poisonlist) < poison_count Then
			poison_count = 0
	end if
	world.setvariable "poison_current", poisonlist(poison_count)	
	world.note "poison : " & world.getvariable("poison_current")
end sub

sub step_back (thename, theoutput, thewildcards)
	poison_count = poison_count -1
	dim poisonlist
	poisonlist = Split(world.getvariable("poisons"), ",")
	if lbound(poisonlist) > poison_count Then
			poison_count = ubound(poisonlist)
	end if
	world.setvariable "poison_current", poisonlist(poison_count)
	world.note "poison : " & world.getvariable("poison_current")
end sub


I am not a programmer and have no idea if this is 'good' code or not, but it seems to work.