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

#action #sub and #math with 0,... help

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
amelsen



Joined: 18 Jul 2017
Posts: 19

PostPosted: Tue Jul 18, 2017 12:23 pm    Post subject: #action #sub and #math with 0,... help Reply with quote

Heya,

I'm trying to set up an action, that'll calculate the unit price and and give it to me as a price number.. even if it's 0,xy something...

This is the captured text I would like to do something about:

Code:

 ITEM                          | AMOUNT | COST | SECTOR
 Armour Plating                | 1502   | 171  | Roche
 Armour Plating                | 902    | 175  | Centerpoint
 Armour Plating                | 2500   | 167  | Bilbringi
 Construction Equipment        | 4000   | 88   | Corellia
 Construction Equipment        | 2002   | 91   | Berchest



Now.. I was trying something along these lines:

#ACTION {^ Armour Plating | %1 | %2 | %3}={#math unitprice %2/%1;#sub %3 {%3 (UnitPrice=$unitprice)}}

But I'm not getting the formatting correct.. and it doesn't do the math correct.. something I just get a 0 or a 1 or something.. problably because it' can't do '0,113' type numbers, etc...

So.. a few questions:

1) How to I set up the action to ensure it captured the full text, regardless of how long it is from the unit price, cost, amount, to the | character... is it just adding %D after?
2) How do I set up a calculation preicsely, so it gives me the unit price + next 3 digits after the comma... fx. 0,113 as the first calculation of unit price would be?

Thanks.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Tue Jul 18, 2017 5:40 pm    Post subject: Reply with quote

You have to "force" MATH to use decimals, just add them (how many you need) to the values used in the operation.
I also had to add a "%s" to the ACTION of your example else it wasn't triggered, but maybe you can use just a "%*" instead of the equipment name to make it more generic.

Code:

#ACTION {^ Armour Plating%s| %1 | %2 | %3} {#math unitprice %2.0000/%1.0000;#sub %3 {%3 (UnitPrice=$unitprice)}}


Code:

#OK. {^ Armour Plating%s| %1 | %2 | %3} NOW TRIGGERS {#math unitprice %2.0000/%1.0000;#sub %3 {%3 (UnitPrice=$unitprice)}} @ {5}.
#showme { Armour Plating                | 1502   | 171  | Roche}
 Armour Plating                | 1502   | 171  | Roche (UnitPrice=0.1138)


This is more generic and will ignore the line with column titles:

Code:

#ACTION {^ {[^ITEM]}%*| %1 | %2 | %3} {#math unitprice %2.0000/%1.0000;#sub %3 {%3 (UnitPrice=$unitprice)}}


Code:

 ITEM                          | AMOUNT | COST | SECTOR
 Armour Plating                | 1502   | 171  | Roche  (UnitPrice=0.1138)
 Armour Plating                | 902    | 175  | Centerpoint  (UnitPrice=0.1940)
 Armour Plating                | 2500   | 167  | Bilbringi  (UnitPrice=0.0668)
 Construction Equipment        | 4000   | 88   | Corellia  (UnitPrice=0.0220)
 Construction Equipment        | 2002   | 91   | Berchest  (UnitPrice=0.0455)


Anyway, you have to know that all the #subs that are created by this action will remains defined and used even if the action isn't triggered, so unless you somehow delete them, everytime one of those names appears in a line the substitution will happen.

Code:

#SUBSTITUTE {Berchest}={Berchest  (UnitPrice=$unitprice)} @ {5}
#SUBSTITUTE {Bilbringi}={Bilbringi  (UnitPrice=$unitprice)} @ {5}
#SUBSTITUTE {Centerpoint}={Centerpoint  (UnitPrice=$unitprice)} @ {5}
#SUBSTITUTE {Corellia}={Corellia  (UnitPrice=$unitprice)} @ {5}
#SUBSTITUTE {Roche}={Roche  (UnitPrice=$unitprice)} @ {5}


So, this is an alternate solution without using #sub, it will delete the original line and rewrite it adding the unitprice string to the end.

Code:

#ACTION {^ {[^ITEM]}%*| %1 | %2 | %3} {#math unitprice %2.000/%1.000;#line gag;#echo {%0 (UnitPrice=$unitprice)}}


Code:

 ITEM                          | AMOUNT | COST | SECTOR
 Armour Plating                | 1502   | 171  | Roche  (UnitPrice=0.114)
 Armour Plating                | 902    | 175  | Centerpoint  (UnitPrice=0.194)
 Armour Plating                | 2500   | 167  | Bilbringi  (UnitPrice=0.067)
 Construction Equipment        | 4000   | 88   | Corellia  (UnitPrice=0.022)
 Construction Equipment        | 2002   | 91   | Berchest  (UnitPrice=0.045)
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Jul 18, 2017 10:18 pm    Post subject: Reply with quote

Only need to define the precision once, so a slightly better way to go about the math is probably:

Code:

#ACTION {^ {[^ITEM]}%*| %1 | %2 | %3} {#math unitprice 1.000 * %2 / %1;#line gag;#echo {%0 (UnitPrice=$unitprice)}}


Alternatively this is possible using a single substitution and a function:

Code:

#function math {#math result {%0}}

#SUB {^ {Armour Plating|Construction Equipment}%2| %3 | %4 | %5} {%0 (UnitPrice=@math{1.000 * %4 / %3})}
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help 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