TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Math: number variable not being treated as a number

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
balthus



Joined: 07 Jul 2009
Posts: 39

PostPosted: Fri Sep 29, 2017 9:10 am    Post subject: Math: number variable not being treated as a number Reply with quote

I appear to be having an issue with some variables not being recognised as numbers within #MATH calculations:

Code:
#echo >$mip[FFF][L][data]<

>82<

#math {testing} {$mip[FFF][L][data] * 35}

#MATH: VARIABLE {testing} HAS BEEN SET TO {0}.

#var {mip[FFF][L][data]} {82}

#OK. VARIABLE {mip[FFF][L][data]} HAS BEEN SET TO {82}.

#echo >$mip[FFF][L][data]<

>82<

#math {testing} {$mip[FFF][L][data] * 35}

#MATH: VARIABLE {testing} HAS BEEN SET TO {2870}.


It appears that the variable is initially holding the value in a non-numeric format of some kind. Is there a way I can force #MATH to parse a variable as a number, or convert the field type to numeric?

I've tried #FORMAT {blah} {%d} but it will not recognise the "non-number" value and puts in 0. The field length reported by #FORMAT is 2, so I'm assuming there's no weird non-display characters attached.

I tried using #FORMAT %r to reverse the field, and I get:

Code:
#OK. VARIABLE {test} HAS BEEN SET TO {m0[8}.


...which reverses back to 82.

I'm having the issue on a fresh compile of version 2.01.3, previously had the same issue with 2.01.1 on Ubuntu 17.04
Back to top
View user's profile Send private message
balthus



Joined: 07 Jul 2009
Posts: 39

PostPosted: Fri Sep 29, 2017 10:10 am    Post subject: Reply with quote

I found with more experimentation that I did have something attached to the end of the field, by looping through the field with #PARSE:

Code:

#parse {$mip[FFF][L][data]} {char} {#showme $char}
8
2

[
0
m


I found a work around to trim off the extra data, which uses parse to only return the number of characters reported by FORMAT string length.

Code:

#FUNCTION {fCleanData}
{
  #FORMAT {_fC[len]} {%L} {%1};
  #VAR {result} {};
  #PARSE {%1} {_fC[char]} {#MATH {_fC[i]} {$_fC[i]+1};#IF {$_fC[i] <= $_fC[len]} {#VAR {result} {$result$_fC[char]}}};
  #UNVAR {_fC};
}


It's not a great solution though (and will only work if the non-display stuff is at the end of the field)...is there an easier way of cleaning off non-display characters?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Fri Sep 29, 2017 12:34 pm    Post subject: Reply with quote

How do you get the content of that variable ?

Maybe you can try cleaning it with "#line strip"
Back to top
View user's profile Send private message
balthus



Joined: 07 Jul 2009
Posts: 39

PostPosted: Tue Oct 03, 2017 2:54 am    Post subject: Reply with quote

The variable is captured from a mud info system by a pretty complex script, something I wrote years ago that used to work fine.

Thanks for the tip on #LINE strip, I wasn't aware of that one...I'll have a think if I can use it in this case.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Tue Oct 03, 2017 7:19 am    Post subject: Reply with quote

This thread could be related to your issue:
http://tintin.sourceforge.net/board/viewtopic.php?t=2431

It could be linked to the use of "#config color patch"
Back to top
View user's profile Send private message
balthus



Joined: 07 Jul 2009
Posts: 39

PostPosted: Wed Oct 04, 2017 3:27 am    Post subject: Reply with quote

That's almost certainly the problem...the control data that I'm extracting that value from does not respect lineends/carriage returns (it is intended to be gagged) which would explain the weirdly variable nature of the results I was seeing.

Either way, #LINE STRIP fixed the issue more cleanly than my work around, so I'm happy Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group