Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Cycling through a list
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Cron0
United Kingdom (11 posts) Bio
|
Date
| Sat 04 Oct 2003 01:20 AM (UTC) |
Message
| 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 04 Oct 2003 03:15 AM (UTC) |
Message
| 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.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Cron0
United Kingdom (11 posts) Bio
|
Date
| Reply #2 on Wed 08 Oct 2003 11:34 AM (UTC) |
Message
| 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.
| Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
10,890 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top