Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
symposes
Novice


Joined: 26 Apr 2006
Posts: 34

PostPosted: Fri Dec 01, 2006 4:36 am   

help with a script
 
Long story short, im trying to find a way to write a script that picks a number that is as close as possible to a predefined number, in a list that is dynamic. The length of this list changes as well, 1 day it could be 3 numbers, the next 10

Ie, i have a list = 1|2|6|7|9|11|15|23
my predefined number is 5
i want a way for zmud to say, closest number - 6

I cant really think of a way to do this.

longer story...

Im playing a mud where i can travel from point A to point B, and from point B teleport to point C. The teleporter at point B changes where it teleports to whenever the mud reboots, but the path from A to B remains constant.
Out of all of the teleporters, they can lead to the same area, So teleporter 5 can go to the same place as teleporter 10, there are only about 8 places between 52 teleporters i check, and the 60 that i know exsist...

I start at point A, and have an array that has paths to all of these teleporters, and through some fancy %additems i can make a list of teleporters based on where they go.

I am trying to avoid using the automapper, because while it can work, it is more trouble then its worth.

I have a way right now, using %pop where the scripts just use the first teleporter it finds that goes to the areas, but id like to stick to the teleporters closer to point A.

if there is a function, or expression that can do this, or a series of them that can, i think i could tweak it enough to work, so i wont need it written for me, hopefully. just some examples to play with and i think i could manage.

If such a thing can be done, i want to thank you guys in advance.
If not, well thank you for taking the time to read this note Very Happy
And if you just need more from me, ill be happy to elaberate.
-Symp
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Fri Dec 01, 2006 1:35 pm   
 
i dunno how to do it, but as a suggestion, use some loop to do some math, and report back the smallest difference.
Of course since from 5 to 1 the diff is -4 that would prolly result in not what you want at all....errr....there's a command to make a negatice # a positive ain't there?
Dammit, not having at zmud at work blows. But kinda got busted for it ;-)

so, some loop for the # of items in the var, then a math to take the predefined subtract each # in the var, store the 1st result, compare the 2nd result to see which is smaller, if smaller toss the old result and keep the new one. all the while having the results go from negative to positive cause -7 is NOT better then +1 ;-)

I should at least have kept the zmud help file here :(
_________________
http://www.Aardwolf.com
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Fri Dec 01, 2006 5:49 pm   
 
I'd use a play on the %sort function that sorts numerically not string wise then compare versus the elements one by one till I found an index that is higher then refer to the one before it.

#VAR mylist @mynumericalsortfunction(@mylist)
#VAR myindex 1
#VAR mynumber 5

#while ((@mynumber < %item(@mylist,@myindex)) AND (@myindex <= %numitems(@mylist)) {#add myindex 1}
#IF (@myindex > %numitems(@myslist)) {#SAY Nothing found in path} {#SAY Closest number below @mynumber is %item(@mylist,@myindex-1)}
Reply with quote
symposes
Novice


Joined: 26 Apr 2006
Posts: 34

PostPosted: Fri Dec 01, 2006 9:36 pm   
 
Interesting thoughts.

That is an aspect i didnt think of Vitae. and something like #forall can run a loop of dynamic lengths. hehe.
Ill need to read up on loop commands too, there may be other things that work.
I could use something like %countitems to count the number of rooms traveled through in the walk paths, and then save that for the first one, and then start the loop that first uses %pop to get the number and subract it from the list, and then go through the entire list...

my static starting point is say room 150, if my closes teleporter is in room 123, thats not exactly 27 rooms, it could be 3 rooms, due to the various paths and layout, so yea, counting the amount of rooms, and making THAT the number i go on would be a way to do it...
Hmm im having trouble thinking this out in my head without 5-6 variables....hehe

Since i have something that works, and works well enough to do the job, i wont stress out over this, but i will still look it over.

Thank you both, V and T.
Reply with quote
symposes
Novice


Joined: 26 Apr 2006
Posts: 34

PostPosted: Fri Dec 01, 2006 11:28 pm   
 
OKay now i have a new problem, with all this written out
whenever i use %arrget to put an index from an array into another variable, it puts the ( ) around the list, making %numitems consider it 1 item, thus making this whole venture obsolete... if anyone has any ideas how to keep them out, i would much appricate it.

*fixed with %replace
hehe
Reply with quote
symposes
Novice


Joined: 26 Apr 2006
Posts: 34

PostPosted: Sat Dec 02, 2006 12:41 am   
 
woot i got it to work, took 6 variables, but once i ironed out all the other bugs, it works like a charm, Thanks again guys!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net