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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Tue Mar 03, 2015 5:52 am   

help with %pos and making counts with it
 
^~~~((*)~) a preserved, (*) corpse of (*)~: Taken.$ is the pattern. I'm not using local variables as it didnt work with what i wrote

#IF %match("*", %1) {corpseq=%pos("*", %1);#show @corpseq star} {corpseq=%pos("|", %1);#show @corpseq bar}

"*" is returned as ---** = 4 and ----* = 5 for %1, i need a count of the *'s instead, can someone show me how to do that please?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Tue Mar 03, 2015 6:55 am   
 
Hmm... this is a clunky way to go about it, but it should work.

Put it inside your #IF %match

#SAY {There are (%numitems(%replace(%1, "*", "|"))-1) *'s in %1}
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Tue Mar 03, 2015 7:40 am   
 
sorry i think i misspoke...




^~~~((*)~) a preserved, (*) corpse of (*)~: Taken.$ <-- pattern

#var corpseqstar (%pos("*", %1))
#var corpseqbar %pos("|", %1)

the above works fine as far as capturing the position from %1 to a variable... however, when it's NOT a "|" corpse, i need it to count how many "*" are in the %1

so %pos is incorrect for the function i need from it.
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Tue Mar 03, 2015 7:42 am   
 
your script : #SAY {There are (%numitems(%replace(%1, "*", "|"))-1) *'s in %1}

returned this:

There are (2-1) *'s in ---|-
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Tue Mar 03, 2015 10:20 am   
 
guess i forgot the %eval
not sure why the value of %1 would change to the %replaced version since there is no way to save it though


What is the game showing you?
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34

Last edited by shalimar on Tue Mar 03, 2015 10:23 am; edited 1 time in total
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Mar 03, 2015 10:22 am   
 
Assuming there can only be stars and hyphens, I'd remove all the hyphens and the length of the remaining string is the number of stars.
Code:
%len(%replace(%1, "-", ""))


Also, %match("*", %1) will always be true. %match uses the normal trigger pattern matching, so * will match anything. If you want to check for literal stars in the string, use ~* (or just eliminate the %match entirely and use %pos).
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Tue Mar 03, 2015 10:24 am   
 
in this case %1 is the pattern to be matched, "*" is the string, i thought it was backwards at first
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Tue Mar 03, 2015 5:06 pm   
 
hmmm sorry folks, %pos("*", %1) if %1 = --*** = 3 and it always shows the position of the FIRST "*"

so %pos will not work, if there is a way to make it count how many stars in %1 that's what i need.... IE: %1 = ----* = 1 or %1 = ***** = 5 and so on.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Tue Mar 03, 2015 10:22 pm   
 
%eval(%numitems(%replace(%replace(%1, "|", " "), "*", "|"))-1)
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Tue Mar 03, 2015 11:08 pm   
 
~(--***) <-- pattern

%len(%replace(%1, "-", "")) = 3

%eval(%numitems(%replace(%replace(%1, "|", " "), "*", "|"))-1) = 3

you both rock!!! thank you so much! this was driving me insane trying to figure out a method of capture and storing into a variable for rewoking information.
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Sat Dec 09, 2017 6:35 am   
 
I have a variation of the previous post i made so im just going to reuse this post if that's ok. if not let me know and ill make a new post

trigger
|PM-------------------|

i need the position of P and M

as it can be |---P----M-------|

so i need to be able to make a trigger to "move" the P and M together, but i need to know how far apart they are.

IE: engage 6 if |------P------M-|
the left or right of p and m mean nothing, only distance between P and M

i can get the previous trigger to at least fire, but not show a numerical value of either position with this:

trigger
^~|(*)~|$

script

angel.me=%pos("M", %1)
angel.mob=%pos("P", %1)
angel.me=%eval(%numitems(%replace(%1, "-", " "))-1)
angel.mob=%eval(%numitems(%replace(%1, "-", " "))-1)


can someone please help me out with how to go about this? Thanks much!
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Sat Dec 09, 2017 7:54 am   
 
#ADDKEY might work better for you here?

#TRIGGER {^|([MP-])|} {
#ADDKEY angel me %pos("M", %1)
}

Though I have to ask... Why do you immediately redefine without using the value?
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Sat Dec 09, 2017 10:05 am   
 
because im pretty much clueless:P
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Sat Dec 09, 2017 11:23 am   
 
If the only value we actually need is the distance between, skip the angel variable altogether.

#TRIGGER {^|([MP-])|} {
#LOCAL $distance
$me=%pos("M", %1)
$mob=%pos("P", %1)
#IF ($me<$mob) {$distance=($mob-$me)} {$distance=($me-$mob)}
#SAY {They are $distance rooms away!}
}
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Sat Dec 09, 2017 8:11 pm   
 
okie, yes i don't need where they are per se, just the distance between them needs to be closed, so i need a value for between them so i can engage X times.
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Sat Dec 09, 2017 8:47 pm   
 
works like a charm, thanks much!
Reply with quote
chris123zugg
Wanderer


Joined: 23 Aug 2013
Posts: 76

PostPosted: Sat Dec 09, 2017 10:50 pm   
 
hrrm there is a minor hang up on this. i removed the localk variables as i need these variables in other places, as well as the 'distance' variable gets stuck at 1 due to the reversal of mob/me positions. i can just react to >||<2 for distance so thats doable.

unless you know a way to reassert those placements and make an 0 distance?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3513
Location: Pensacola, FL, USA

PostPosted: Sun Dec 10, 2017 8:03 pm   
 
The #IF there would always check to see which is higher prior to doing the math so you should always get a positive integer.
Other then that, I'm not sure I understand the question.
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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