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
XonDK
Apprentice


Joined: 01 Dec 2006
Posts: 178

PostPosted: Tue Aug 07, 2012 10:34 am   

best way to capture float variables
 
So I'm having a little trouble with capturing floating variables of late. for some reason when using (%f) and converting it to regex via the buildin converter the variables don't return anything and if I try to use it to set a value it sets it to .
This being inside a %db using #ADDKEY to set it.

#ADDKEY variable {key} {value}

and the value is set from the capture to .

what am I doing wrong?
Reply with quote
shalimar
GURU


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

PostPosted: Tue Aug 07, 2012 10:38 am   
 
show us the code you have so far so we can better understand the issue
_________________
Discord: Shalimarwildcat
Reply with quote
XonDK
Apprentice


Joined: 01 Dec 2006
Posts: 178

PostPosted: Tue Aug 07, 2012 10:45 am   
 
Code:
^You take a moment to assess how damaged your limbs are\.\n^Head:.*([+-]?[0-9,]*\.?[0-9]*)\% \((.*)\)\n^Torso:.*([+-]?[0-9,]*\.?[0-9]*)\% \((.*)\)\n^Left Arm:.*([+-]?[0-9,]*\.?[0-9]*)\% \((.*)\)\n^Right Arm:.*([+-]?[0-9,]*\.?[0-9]*)\% \((.*)\)\n^Left Leg:.*([+-]?[0-9,]*\.?[0-9]*)\% \((.*)\)\n^Right leg:.*([+-]?[0-9,]*\.?[0-9]*)\% \((.*)\)$


the trigger pattern works however if I use #SAY %1-%3-%5-%7 and so on to get what should be the floating values it simply returns ----
and setting it with #ADDKEY variable {key} {%1}
sets the value to .
Reply with quote
shalimar
GURU


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

PostPosted: Tue Aug 07, 2012 10:48 am   
 
Hmm.. i really need to learn to read raw regex...
Out of curiosity, why not use separate triggers for each line?
At least i assume that is a multiline.
_________________
Discord: Shalimarwildcat
Reply with quote
XonDK
Apprentice


Joined: 01 Dec 2006
Posts: 178

PostPosted: Tue Aug 07, 2012 10:55 am   
 
No particular reason, I find it a bit easier to edit a whole line at the time when multiline works. but that said the pattern works fine, its what it returns that is a mess. (%f) gets turned into ([+-]?[0-9,]*\.?[0-9]*)
Reply with quote
shalimar
GURU


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

PostPosted: Tue Aug 07, 2012 11:31 am   
 
well, %f is not a valid pattern matching symbol.. try:     %d.%d
_________________
Discord: Shalimarwildcat
Reply with quote
XonDK
Apprentice


Joined: 01 Dec 2006
Posts: 178

PostPosted: Tue Aug 07, 2012 11:32 am   
 
Found a work around namely using
Code:
^You take a moment to assess how damaged your limbs are\.\n^Head:\s+([[0-9\.]+)\% \((.*)\)\n^Torso:\s+([0-9\.]+)\% \((.*)\)\n^Left Arm:\s+([0-9\.]+)\% \((.*)\)\n^Right Arm:\s+([0-9\.]+)\% \((.*)\)\n^Left Leg:\s+([0-9\.]+)\% \((.*)\)\n^Right leg:\s+([0-9\.]+)\% \((.*)\)$


instead
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Aug 07, 2012 4:14 pm   
 
%f is definitely a valid pattern matching symbol, it matches floating point numbers.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Aug 07, 2012 6:49 pm   
 
[0-9\.]+ is going to be the best way to match floating point numbers in regex. And yes, as Daern stated, %f is used to match floating points in zscript. It's new to CMUD, though.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Aug 07, 2012 6:58 pm   
 
[0-9\.]+ is a pretty flawed regex, actually. It'll pick up everything you need, sure, and it'll probably be good enough in this case because of all the text around it, but if you were just trying to match a floating point number, you're going to get a lot of false positives with that pattern. It'll match things like 1.6.942.658, or even ........ Something like [0-9]*\.[0-9]+ would be better - any number of digits (or even none), then a decimal point, then any number of digits (one or more this time).
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