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

Complex for me: Using #action to capture table to #list+more

 
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: 16

PostPosted: Sun Jul 23, 2017 10:37 am    Post subject: Complex for me: Using #action to capture table to #list+more Reply with quote

Heya,

I'm trying to simplify a shopping system, and could use some input on how to do this the right way:

In short, what we are dealing with is a merchant system where you can place bids on delivering items to various companies.

Once you have placed a bid, you normally verify your current stock of goods, and based on your current stock, you end up missing things, which you then have to purchase other places, to deliver to the customer. So sort of a drop-shipping system:

In my head, it seems sort of complicated, but might be simple enough to do.

Now.. the mud itself does not allow automatic scripting, so I'd like the ability to use the mud output, to generate lists, and then set up hotkeys, to go through the lists.

What I'm sort of imagining being able to do, is:

1) Capture the output of the needed items, creating a #list of whats needed, rounded up to nearest 100:
2) Creating an alias, where the command uses #foreach to go through the #list and requesting a list of potential vendors
3) Evaluating the list of available vendors returned, and create a new list consisting of:
3.a: What type of goods
3.b: Amount to buy from vendor (needed from #1, rounded up to nearest 100)
3.c: Name of vendor/location to place the purchase order

Notes to #3:
1) The vendor selected has to be the one with the cheapest unit price
2) Sometimes you might not be able to get the full amount needed, then we need to add two vendors, where the second vendor is the remaining part of of what you couldnt get at cheapest, and the vendor then added to the list is the second cheapest, with the amount being whats left)


Now... allow me to demonstrate some of the mud text:

This is the table list of items needed:
Code:

ITEM                    | HAVE | NEED | PURCH
Armour Plating          | 190  | 0    | 0
Construction Equipment  | 23   | 0    | 0
Electronic Devices      | 48   | 0    | 0
Foodstuffs              | 6    | 0    | 0
Fuel                    | 40   | 0    | 0
Holonovels              | 59   | 0    | 0
Jedi Artifacts          | 72   | 0    | 0
Light Vehicles          | 740  | 0    | 0
Livestock               | 182  | 0    | 0
Luxury Goods            | 42   | 0    | 0
Medical Supplies        | 146  | 0    | 0
Natural Resources       | 96   | 0    | 0
Refined Alloys          | 1    | 0    | 0
Starship Parts          | 61   | 0    | 0
Textiles                | 55   | 0    | 0
Unrefined Ore           | 22   | 0    | 0
Vong Biotech            | 211  | 0    | 0
Weapons                 | 41   | 0    | 0


The 1st column is naturally the resource name, 2nd column what you have in storage, 3rd column what you need to fulfill orders you have bid on, and the 4th column, is finally the amount you need to get, which is based on current storage-needed.. so as written above.. we need an #action to capture the resource name itself, add that to the list, and then take the number in the 4th column, and round that up to nearest 100.

Once we have that.. we need to find a list of potential suppliers.

We do that by doing 'l <resource name>'

Fx.: if I type 'l jedi artifacts', I get this list:

Code:

 ITEM                          | AMOUNT | COST | SECTOR
 Jedi Artifacts                | 300    | 635  | Dantooine
 Jedi Artifacts                | 906    | 550  | Factories
 Jedi Artifacts                | 501    | 620  | Yavin
 Jedi Artifacts                | 500    | 621  | Dathomir


So basically, I need an alias, that each type I run that command, it will go through the list of previously needed ressources, and go 'list' each of them.

So first time might be 'l jedi artifacts'.. next time I type the command, it would then be 'l <another ressource>' based on whats needed.

Then from the above output, we need to create a new #list, where we capture the cheapest supplier (sector) (4th column), as mentioned above.

And to reiterate.. if we can't get the full amount needed, rounded up to nearest 100 from the cheapest sector/supplier, then we need the second cheapest to the list also, with the remaining parts needed.

So the list would then be:
<ressource name> <amount needed rounded up to nearest 100> <sector/supplier name>


Then finally, an aliases that methodically goes through that list, and places purchase orders for them 1 at a time.

'p <ressource name> <amount> <sector/supplier name>'.

Again.. here we need to remember that

Finally.. we naturally need to clean up those lists for next time... so we dont end up ordering things we dont need =)


Makes sense?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Sun Jul 23, 2017 4:23 pm    Post subject: Reply with quote

I'm too sleepy now to start thinking about all of this... Confused

Anyway I can give you a clue about doing the first of the requested lists (except for the math that's too much right now)...

Let's borrow the code given on your previous thread and modify it a bit:
Code:

#ACTION {^{\s*[^ITEM].*}| %2 | %3 | %4} {#if {%4>0} {#FORMAT {result} {%p} {%1};#VAR ToPurch[$result] {%4}}}}


With this table
Code:

ITEM                    | HAVE | NEED | PURCH
Armour Plating          | 190  | 0    | 0
Construction Equipment  | 23   | 10   | 13
Electronic Devices      | 48   | 0    | 0
Foodstuffs              | 6    | 5    | 1
Fuel                    | 40   | 4    | 36
Holonovels              | 59   | 1    | 58
Jedi Artifacts          | 72   | 0    | 0


You get this:
Code:

#VARIABLE {ToPurch}={{Construction Equipment}{13}{Foodstuffs}{1 }{Fuel}{36}{Holonovels}{58}}


and you can use it's content like this:
Code:

#foreach $ToPurch[] {cnt} {#echo {$cnt}}
Construction Equipment
Foodstuffs
Fuel
Holonovels

#foreach $ToPurch[%*] {cnt} {#echo {$cnt}}
13
1
36
58


EDIT: just adding the round 100 function to the previous code, if this is what you needed

Code:

#function {round100} {#MATH {result} {%0 - (%0 % 100) + 100}}

#ACTION {^{\s*[^ITEM].*}| %2 | %3 | %4} {#if {%4>0} {#FORMAT {result} {%p} {%1};#VAR ToPurch[$result] {@round100{%4}}}}}


result:
Code:

#VARIABLE {ToPurch}={{Construction Equipment}{100}{Foodstuffs}{100}{Fuel}{100}{Holonovels}{100}
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 24, 2017 12:59 am    Post subject: Reply with quote

Ohhh.. definately on the right path here.. this works =)

The next thing to figure out is how to I handle the sector/supplier thing?
In particular, if I need to go through a purchase of multiple suppliers....

So far it's capturing correct:

Code:

ITEM                    | HAVE | NEED | PURCH
Armour Plating          | 161  | 153  | 0
Construction Equipment  | 101  | 15   | 0
Electronic Devices      | 50   | 0    | 0
Foodstuffs              | 43   | 0    | 0
Fuel                    | 177  | 162  | 0
Holonovels              | 65   | 0    | 0
Jedi Artifacts          | 46   | 40   | 0
Light Vehicles          | 100  | 30   | 0
Livestock               | 151  | 94   | 0
Luxury Goods            | 592  | 503  | 0
Medical Supplies        | 202  | 135  | 0
Natural Resources       | 53   | 0    | 0
Refined Alloys          | 446  | 432  | 0
Starship Parts          | 760  | 702  | 0
Textiles                | 800  | 782  | 0
Unrefined Ore           | 1200 | 3284 | 2084
Vong Biotech            | 700  | 644  | 0
Weapons                 | 1500 | 1403 | 0
                    TOTAL 7147 | 8379 | 2084


Captured this:

Code:
#VARIABLE {ToPurch}={{Unrefined Ore}{2100}}


So thats perfect. Now.. looking at suppliers:

I have to go through and 'list' each item.. so 'l #foreach something'.. in this case.. I'd only get Unrefined Ore.

If I manually type 'l unrefined ore', I get this:

Code:
 ITEM                          | AMOUNT | COST | SECTOR
 Unrefined Ore                 | 129    | 60   | Jubilar
 Unrefined Ore                 | 151    | 54   | Af el
 Unrefined Ore                 | 210    | 64   | Nkllon


Now.. here we naturally have a whole other issue, because all the ore we need isn't available - But ideally, it should capture enough of the 'Sector', sorted by cheapest 'cost/unit price', which then through an alias would allow me to:

p <item> <amount captured> <sector>.

How do I do that?
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 24, 2017 1:25 am    Post subject: Reply with quote

I can't even figure out how to get these out, one at a time?

Can you show me how to make an alias, which, the first time I ever it gives me first item and the amount needed for that item.
The second time it gives me second item and the amount needed for that, etc etc... ?
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 24, 2017 3:50 am    Post subject: Reply with quote

Powergod.. any chance you could send me perhaps your FB info or something.. might be easier to chat about this in real-time.. if you care to help me a bit further....
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Tue Jul 25, 2017 5:36 pm    Post subject: Reply with quote

I'm sorry, but in the little time I find for this type of things I just post on the forum, also because I like the idea that others people could find the answers for similar issues they have...

Returning to the matter at hand, to launch the alias every time with a different string, you just need to use a counter, and maybe a list with just the items:

Code:

#var {TheCounter} {1}
#List TheList CREATE {$ToPurch[]}

#alias {vendors} {l $TheList[$TheCounter];#MATH {TheCounter} {$TheCounter + 1}}


Naturally at some point you'll have to reset the counter
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 31, 2017 7:00 am    Post subject: Reply with quote

Hrmm... I think there is something wrong with the capture action, Powergod.

So.. this is what it looks like:
Code:

#ACTION {^{\s*[^ITEM].*}| %2 | %3 | %4}={#if {%4>0}{#format {result}{%p} {%1};#variable ToPurch[$result] {@round100{%4}}}}


And I have naturally added the function you said:

Code:
#FUNCTION {round100}={#math {result} {%0 - (%0 % 100) + 100}}



Now, if we look at the current needs table, this is what it looks like:
Code:

ITEM                    | HAVE | NEED | PURCH
Armour Plating          | 0    | 641  | 641
Construction Equipment  | 0    | 84   | 84
Electronic Devices      | 0    | 344  | 344
Foodstuffs              | 0    | 634  | 634
Fuel                    | 0    | 424  | 424
Holonovels              | 9    | 238  | 229
Jedi Artifacts          | 0    | 516  | 516
Light Vehicles          | 470  | 30   | 0
Livestock               | 30   | 113  | 83
Luxury Goods            | 0    | 507  | 507
Medical Supplies        | 0    | 1459 | 1459
Natural Resources       | 0    | 282  | 282
Refined Alloys          | 0    | 337  | 337
Starship Parts          | 0    | 401  | 401
Textiles                | 0    | 558  | 558
Unrefined Ore           | 0    | 5290 | 5290
Vong Biotech            | 0    | 403  | 403
Weapons                 | 0    | 1026 | 1026


However.. if I look at what it has captured through the action, it looks like this:

Code:
#VARIABLE {ToPurch}={{Armour Plating}{700}{Construction Equipment}{100}{Foodstuffs}{700}{Fuel}{500}{Holonovels}{300}{Jedi Artifacts}{600}{Livestock}{100}{Luxury Goods}{600}{Natural Resources}{300}{Refined Alloys}{400}{Starship Parts}{500}{Unrefined Ore}{5300}{Vong Biotech}{500}{Weapons}{1100}}


So.. going through it.. it for some reason hasn't captured:

- Electronic Devices
- Medical Supplies
- Textiles

?!?! What on earth could be causing that?! It leaves those 3 out every time?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Mon Jul 31, 2017 7:16 am    Post subject: Reply with quote

Oh, right, that regexp was considering the single letters of "ITEM", so everything that was starting with one of them was excluded...

This should consider the entire word:
Code:

#ACTION {^{\s*(?!ITEM).*}| %2 | %3 | %4} {#if {%4>0} {#FORMAT {result} {%p} {%1};#VAR ToPurch[$result] {@round100{%4}}}}}


by the way, this is a cool site where you can learn an test regular expressions:
http://www.regextester.com/15
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 31, 2017 9:49 am    Post subject: Reply with quote

That worked.. awesome.

How would I capture this then... this needs to be slightly different, because I need all values from here... and this is the actual listing.

When I list the the products with the 'vendors' alias... it shows a table like this:

I type 'l weapons' and get the below.

I want to capture everything returned here.. sometimes it's 3, sometimes 4 results.
The important thing is the 'cost' and the 'sector' here. Can make an action, that captures and updates a potential array for each item? So.. in other words.. it resets the array everytime I list, and adds the new updated values into the array.

so.. array would in this case be structured like:

index 1 in the array would hold all 3 elements(amount, cost, sector) in first result line
index 2 would be all 3 elements from second line,

etc etc.
?

Code:

 ITEM                          | AMOUNT | COST | SECTOR
 Weapons                       | 1864   | 374  | Roche
 Weapons                       | 412    | 383  | Rodia
 Weapons                       | 536    | 383  | Corellia
 Weapons                       | 1920   | 399  | Sullust



I guess the complex thing is the dynamic name allocation every time? Because how would we create an index we can scroll through the various prices everytime, when the item name would change when we run through the 'vendors' alias?
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 31, 2017 10:18 am    Post subject: Reply with quote

Btw.. what the 'code' quote doesn't show.. is there it's indented with one 'space'.. so it isn't from line start.. but one space in on the line that the text starts.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Mon Jul 31, 2017 2:42 pm    Post subject: Reply with quote

I just found out something... the negative regexp doesn't work on tt++ Sad

I'm not sure if it's a bug or a NOT implemented feature... Confused

So this part of the #action must be removed and it should become a stand-alone #action...
Code:

{\s*(?!ITEM).*}


Easy way is to make it with a higher priority than the other one, so to make it catch the title line first (The default priority is 5, so 4 is "higher")
Code:

#ACTION {^%sITEM} {#NOP Ignored line;} {4}

#ACTION {^%s%1 | %2 | %3 | %4} {#FORMAT {item} {%p} {%1};#FORMAT {amount} {%p} {%2};#FORMAT {cost} {%p} {%3};#FORMAT {sector} {%p} {%4};#VAR Articles[$item][$sector][COST] {$cost};#VAR Articles[$item][$sector][AMOUNT] {$amount}};


Now, giving the example table you posted for sectors, the result is this array of arrays (also called matrix) that contains everything from that table:
Code:

#VARIABLE {Articles}={{Weapons}{{Corellia}{{AMOUNT}{536}{COST}{383}}{Roche}{{AMOUNT}{1864}{COST}{374}}{Rodia}{{AMOUNT}{412}{COST}{383}}{Sullust}{{AMOUNT}{1920}{COST}{399}}}}


Some example of how it works:
Code:

#showme {$Articles[]}
{Weapons}

#showme {$Articles[Weapons][]}
{Corellia}{Roche}{Rodia}{Sullust}

#showme {$Articles[Weapons][Corellia][COST]}
383
#showme {$Articles[Weapons][Corellia][AMOUNT]}
536


As you can see, every item contains all the sectors where it can be found, and every sector has its values

Code:

#foreach {$Articles[]} {cnt} {#show {$cnt};#foreach {$Articles[$cnt][]} {cnt2} {#show {- $cnt2};#show {  - COST: $Articles[$cnt][$cnt2][COST]};#show {  - AMOUNT: $Articles[$cnt][$cnt2][AMOUNT]}}}
Weapons
- Corellia
  - COST: 383
  - AMOUNT: 536
- Roche
  - COST: 374
  - AMOUNT: 1864
- Rodia
  - COST: 383
  - AMOUNT: 412
- Sullust
  - COST: 399
  - AMOUNT: 1920
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Jul 31, 2017 11:50 pm    Post subject: Reply with quote

In theory, we're truly getting somewhere now =)

We do however have ONE large issue, that I'm unsure of how we handle?

The action you just created here, also captures the full output from the 'need' table, above?

So they conflict. With this action active, and running through the 'need' table, it fills up the $Article var, and for this case it suddenly looks lke this.

Code:

Purch [360024605 cr]: n  <<- (here I click 'n' to see 'Need table'.

ITEM                    | HAVE | NEED | PURCH
Armour Plating          | 2    | 0    | 0
Construction Equipment  | 83   | 0    | 0
Electronic Devices      | 54   | 0    | 0
Foodstuffs              | 130  | 0    | 0
Fuel                    | 98   | 0    | 0
Holonovels              | 100  | 0    | 0
Jedi Artifacts          | 2    | 0    | 0
Light Vehicles          | 90   | 0    | 0
Livestock               | 92   | 0    | 0
Luxury Goods            | 1    | 0    | 0
Medical Supplies        | 47   | 0    | 0
Natural Resources       | 87   | 0    | 0
Refined Alloys          | 6    | 0    | 0
Starship Parts          | 77   | 0    | 0
Textiles                | 5    | 0    | 0
Unrefined Ore           | 18   | 0    | 0
Vong Biotech            | 71   | 0    | 0
Weapons                 | 20   | 0    | 0
                    TOTAL 983  | 0    | 0
--More-- (95%) q
Purch [360024605 cr]: l weapons

 ITEM                          | AMOUNT | COST | SECTOR
 Weapons                       | 588    | 440  | Roche
 Weapons                       | 74     | 487  | Rodia
 Weapons                       | 212    | 433  | Corellia
 Weapons                       | 1232   | 416  | Sullust

Purch [360024605 cr]: #showme $articles
$articles
#showme $Articles
{Armour Plating}{{0}{{AMOUNT}{2}{COST}{0}}}{Construction Equipment}{{0}{{AMOUNT}{83}{COST}{0}}}{Electronic Devices}{{0}{{AMOUNT}{54}{COST
}{0}}}{Foodstuffs}{{0}{{AMOUNT}{130}{COST}{0}}}{Fuel}{{0}{{AMOUNT}{98}{COST}{0}}}{Holonovels}{{0}{{AMOUNT}{100}{COST}{0}}}{Jedi
Artifacts}{{0}{{AMOUNT}{2}{COST}{0}}}{Light Vehicles}{{0}{{AMOUNT}{90}{COST}{0}}}{Livestock}{{0}{{AMOUNT}{92}{COST}{0}}}{Luxury
Goods}{{0}{{AMOUNT}{1}{COST}{0}}}{Medical Supplies}{{0}{{AMOUNT}{47}{COST}{0}}}{Natural Resources}{{0}{{AMOUNT}{87}{COST}{0}}}{Refined
Alloys}{{0}{{AMOUNT}{6}{COST}{0}}}{Starship Parts}{{0}{{AMOUNT}{77}{COST}{0}}}{Textiles}{{0}{{AMOUNT}{5}{COST}{0}}}{Unrefined
Ore}{{0}{{AMOUNT}{18}{COST}{0}}}{Vong Biotech}{{0}{{AMOUNT}{71}{COST}{0}}}{Weapons}{{0}{{AMOUNT}{20}{COST}{0}}{Corellia}{{AMOUNT}{212}{CO
ST}{433}}{Roche}{{AMOUNT}{588}{COST}{440}}{Rodia}{{AMOUNT}{74}{COST}{487}}{Sullust}{{AMOUNT}{1232}{COST}{416}}}

Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Tue Aug 01, 2017 12:34 am    Post subject: Reply with quote

Hrmm.. I tried to work around it by creating an alias that I can remove and start the other action with.. but when I create the action through an alias, it doesn't pass the % characters, as it probably assumes its parameters.

Otherwise that would work.

So.. i created this alias:
Code:

#ALIAS {startneedcapture}={#ACTION {^%s%1 | %2 | %3 | %4} {#FORMAT {item} {%p} {%1};#FORMAT {amount} {%p} {%2};#FORMAT {cost} {%p} {%3};#FORMAT {sector} {%p} {%4};#VAR Articles[$item][$sector][COST] {$cost};#VAR Articles[$item][$sector][AMOUNT] {$amount}}} @ {5}


But.. the action it actually creates, looks like this?

Code:

#ACTION {^%s |  |  | }={#FORMAT {item} {%p} {};#FORMAT {amount} {%p} {};#FORMAT {cost} {%p} {};#FORMAT {sector} {%p} {};#VAR
Articles[$item][$sector][COST] {$cost};#VAR Articles[$item][$sector][AMOUNT] {$amount}} @ {5}
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Tue Aug 01, 2017 6:01 am    Post subject: Reply with quote

in this case you must use double "%" for parameters in the #action...
(and if that #action creates another #action, this last one must use triple "%", etc...)

example:
Code:

#ALIAS {MyALias} {#ACTION {something %%1 something} {#ECHO {%%1}}}
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Tue Aug 01, 2017 6:48 am    Post subject: Reply with quote

Oki.. I'll try that.

I think we're getting close to being there with the entire setup... from the first post Smile

Next part will be figuring out how theck we sort that last array, pass the cheapest.. and in case that doesn't hold enough, then order from second cheapest, etc...
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Wed Aug 02, 2017 3:46 pm    Post subject: Reply with quote

The sorting thing is something I've never done before with tt++... also I don't find threads that raises the argument either...

So, I'll just start to theorize while playing with the tools that this client offers... and maybe at some point something will come out of it....

Some analysis:

- Arrays are always automatically sorted by primary key, but we can't use the COST like this, because the primary key must be unique and we could lose some SECTOR with the same value...

- #LIST has a SORT function, it works only for character strings, and only for a single field... so we could sort all the COSTs directly, but then we wouldn't know to what SECTOR is referred to every value...

- A #function to sort a multidimensional array could be done, but it will not be an easy task given how arrays are managed... also could be even difficult to make it simple enough to work for other situations too... and at last it could also be overkill given the "simple" sort we need (think about how many operations it could do for every single value)...


So, given the previous speculations, I suppose that the easier and most "straightforward" way will be to somehow use the #LIST SORT...

Given to it a list of COSTs, it will return an ordered list... then the issue to be solved is that we need a connection to their respective SECTOR...

The SECTORS could be referenced also as a numerical value in their array:
Code:

#VARIABLE {Articles}={{Weapons}{{Corellia}{{AMOUNT}{536}{COST}{383}}{Roche}{{AMOUNT}{1864}{COST}{374}}{Rodia}{{AMOUNT}{412}{COST}{383}}{Sullust}{{AMOUNT}{1920}{COST}{399}}}}

#show $Articles[Weapons][Corellia]
{AMOUNT}{536}{COST}{383}

#show $Articles[Weapons][+1]
{AMOUNT}{536}{COST}{383}

#show $Articles[Weapons][+2]
{AMOUNT}{1864}{COST}{374}
#show $Articles[Weapons][+3]
{AMOUNT}{412}{COST}{383}


Maybe that could be used somehow as a linking key...

It is anyway not a fixed address, but just an indicator of their actual position, because if for some reason a new SECTOR is added and alphabetically is lesser than one of the already present fields, it will shift the position of all the fields after it...

Anyway, for this particular situation there shouldn't be issues because of that, we just have to create the ordered list from scratch every time is needed.

EDIT:

We need to have values containing both the COST and the reference to the SECTOR, in a way that the reference will not break the sorting....

Something like this:

Code:

#show $Articles[Weapons][+1]
{AMOUNT}{536}{COST}{383}


should become "00383001", where "001" is the reference... (the alfabetical sort starts from left, so also the initial zeroes are important and must be added in case of longer values)

I can't see a "zerofill" function in #FORMAT, but anyway it must be used in some way to obtain this...

EDIT:

So. after studying a bit what #FORMAT can do, I found out a trick to zerofill, adding zeroes to the start of the number, inverting it, taking only a specific number of characters (so to remove exceeding zeroes), and then re-inverting it...
Code:

#format {CostSector} {00000%d} {123};
#OK. VARIABLE {CostSector} HAS BEEN SET TO {00000123}.
#FORMAT {CostSector} {%r} {$CostSector};
#OK. VARIABLE {CostSector} HAS BEEN SET TO {32100000}.
#FORMAT {CostSector} {%.5s} {$CostSector};
#OK. VARIABLE {CostSector} HAS BEEN SET TO {32100}.
#FORMAT {CostSector} {%r} {$CostSector}
#OK. VARIABLE {CostSector} HAS BEEN SET TO {00123}.


... so now a function could be made out of this...

EDIT:

Here it is (the second parameter is the length and must be always specified):
Code:

#FUNCTION {zerofill} {#format {result} {00000000000000000000%d} {%1};#FORMAT {result} {%r} {$result};#FORMAT {result} {%.%2s} {$result};#FORMAT {result} {%r} {$result}}


#show {@zerofill{123;5}}
00123
#show {@zerofill{123;10}}
0000000123


So now we can do create a single code with COST and Index number of it's SECTOR:
Code:

#show {@zerofill{$Articles[Weapons][Corellia][COST];5}@zerofill{&Articles[Weapons][Corellia];3}}
00383001


EDIT:

Naturally we also need some functions to get back the single values from that string:
Code:

#FUNCTION {right} {#format {result} {%r} {%1};#FORMAT {result} {%.%2s} {$result};#FORMAT {result} {%r} {$result}}

#FUNCTION {left} {#format {result} {%.%2s} {%1}}

#show {@right{00383001;3}}
001
#show {@left{00383001;5}}
00383


EDIT:

Also something to get the index name giving the index position in an array:
Code:

#FUNCTION {IndexName} {#LIST {result} CREATE $%1[];#return {$result[%2]}}

#show {@IndexName{Articles[Weapons];1}}
Corellia
#show {@IndexName{Articles[Weapons];4}}
Sullust


Now everything seems ready to get some result, this alias will show the entries sorted:
Code:

#ALIAS {sortprices} {
   #LIST {ToBeSorted} CREATE;
   #LIST {AlreadySorted} CREATE;
   #foreach {$Articles[%1][]} {cnt} {
      #LIST {ToBeSorted} ADD {@zerofill{$Articles[%1][$cnt][COST];5}@zerofill{&Articles[%1][$cnt];3}}
   };
   #LIST {AlreadySorted} SORT {$ToBeSorted[%*]};
   #foreach {$AlreadySorted[%*]} {cnt} {
      #show {@IndexName{Articles[%1];@right{$cnt;3}} - COST: $Articles[%1][+@right{$cnt;3}][COST] - AMOUNT: $Articles[%1][+@right{$cnt;3}][AMOUNT]}
   };
   #unvar {ToBeSorted};
   #unvar {AlreadySorted};
}


Code:

#VARIABLE {Articles}={{Weapons}{{Corellia}{{AMOUNT}{536}{COST}{383}}{Roche}{{AMOUNT}{1864}{COST}{374}}{Rodia}{{AMOUNT}{412}{COST}{383}}{Sullust}{{AMOUNT}{1920}{COST}{399}}}}

sortprices Weapons
Roche - COST: 374 - AMOUNT: 1864
Corellia - COST: 383 - AMOUNT: 536
Rodia - COST: 383 - AMOUNT: 412
Sullust - COST: 399 - AMOUNT: 1920


Last edited by PowerGod on Wed Aug 02, 2017 7:52 pm; edited 2 times in total
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3762

PostPosted: Wed Aug 02, 2017 7:07 pm    Post subject: Reply with quote

PowerGod wrote:

I can't see a "zerofill" function in #FORMAT, but anyway it must be used in some way to obtain this...

#format %07d <value> should create a 7 digit zero filled number. You can check the linux manual on sprintf %s and %d for additional features as that is what tintin++ uses under the hood with #format.

tintin will correctly sort numbers in a table variable, but if it's not a valid number it will be sorted alphabetically.

Should be okay to use a zero filled cost with the sector name attached.

Take note on how to merge tables in the 2nd variable declaration, and on how to access the first index using +1 (use -1 to get the last index)

Code:

#var {weapons} {{0000487-Rodia}{{cost}{487}{sector}{Rodia}{amount}{74}}}

#var {weapons} {$weapons} {{0000440-Roche}{{cost}{440}{sector}{Roche}{amount}{588}}}

#showme $weapons[+1]
#showme <118>Sector of first element: $weapons[+1][sector]
#unvar weapons[+1]
#showme $weapons[+1]


Also possible to directly declare within the weapons table to avoid having to merge. Easier and less resource intensive.

Code:

#var {weapons[0000440-Roche]} {{cost}{440}{sector}{Roche}{amount}{588}}
Back to top
View user's profile Send private message Send e-mail
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Wed Aug 02, 2017 8:14 pm    Post subject: Reply with quote

Scandum wrote:
PowerGod wrote:

I can't see a "zerofill" function in #FORMAT, but anyway it must be used in some way to obtain this...

#format %07d <value> should create a 7 digit zero filled number. You can check the linux manual on sprintf %s and %d for additional features as that is what tintin++ uses under the hood with #format.


Cool, I see your post only now, so in the mean time I constantly updated the above post with dirty tricks Big Smile

I'll have a better read at your post when I'll find more time

Thank you
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Thu Aug 03, 2017 12:15 pm    Post subject: Reply with quote

I'm a bit confused with everything here.. having read through it a few times...

So to summarize.. what the ideal scenario is:

1 alias

My imagination is that is has to act based on the content in the $Articles array, and act according to the needed amounts (We captured that ealier as a rounded up figure)

I'm imagining the alias itself evaluates the $Article array with the matching rounded up number of items needed from the $ToPurch[], and "fills up" a new array with needed information, and uses a MANUAL #foreach (I am not allowed to send more than 1 command to the mud a time), then places the needed orders.
Additionally, once a order is placed, the amount needed variable needed to be adjust with the purchase order placed.. so if we buy everything, set that variable to 0.. or else subtract the amount ordered from the needed amount.

So in short, if the cheapest sector has enough amount to fill the needed items, then it's 1 command... if it isn't.. second time I run alias, it just places a second order at second cheapest sector.. etc


So: Case 1 example:

1) I check 'need' and $Article is filled with info
2) I run 'placepurchaseorder' alias
3} The alias evaluates numbers and :
3.1) see amount available in cheapest sector is enough to fullfill the order
3.2) Add cheapest sector + amount (captured before) to new array
3.3) Sends the purchase command to the mud (Ie: 'p $whichitem[name] $whichitem[amount] $whichitem[sector]' or something like that?

Which then fx would be: 'p jedi artifacts 200 roche' for example


Case 2:

1) I check 'need' and $Article is filled with info
2) I run 'placepurchaseorder' alias
3} The alias evaluates numbers and :
3.1) see amount available in cheapest sector is NOT enough to fullfill the order
3.2) Add cheapest sector + amount available at cheapest sector(captured in the $Article array) to new array
3.3) Subtract that amount from the rounded number
3.4) Compared second cheapest sectors amount with remaining amount needed
3.5) That is still not enough, so adds full amount available to array (on next array position?) with that sectors name
3.6) Subtracts that amount from remaining needed
etc etc...
3.xx?) Finally the (#foreach?) will ensure first time I run the alias it buys the full amount from cheapest sector.. second time I run the alias, it places the order for the full amount from second sector... third time, I run alias, it will buy the remaining part to fulfill the order from the potential last sector...


.. Hope that makes sense?

So I guess it's about:
1) comparing two numbers
2) If not big enough, then fill more positions in new array, or else only 1 position in the actual array to place the order
3) Use an ability to cycle through that array to 'p <item> <amount> <sector>' needed

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



Joined: 04 Aug 2014
Posts: 330

PostPosted: Fri Aug 04, 2017 11:19 am    Post subject: Reply with quote

amelsen wrote:
I'm a bit confused with everything here.. having read through it a few times...


For now:
- you get the things to be purchased in $ToPurch
- with the content of that var you can call different times the alias "vendors" that will list one at a time the sectors where can be found every item, and those results will be saved into $Articles
- and the last alias "sortprices" shows for a chosen item an ordered list of sectors starting from the cheapest
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Sat Aug 05, 2017 3:02 pm    Post subject: Reply with quote

How do I with one command just get it to return just the sector name then?

I need to parse the 'sector' name ALONE... I can't use a list for anything...

Like.. is there a variable array position thing I can use?

Right now, I use an alias with the vendor listing:

p $currentitem $ToPurch[$currentitem] %0

Can we add something instead of the %0, thats picks the sectorname?
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Mon Aug 07, 2017 6:50 am    Post subject: Reply with quote

I've tried to mingle around for a few days now.. I can't seem to make it work at all.

The sortprices doesn't return anything?

And I'm not sure how to merge Scandum's recommendation into what you wrote Powergod.

If I can just after the the 'needs' table, be able to fetch the cheapest sector as a one word, so I can parse that into the purchase command.. that would be fantastic..

I just can't see how to do that on the above? Way too advanced for me to decypher Coffee
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Mon Aug 07, 2017 4:18 pm    Post subject: Reply with quote

The first thing that scandum wrote was about the zerofill function that can can be changed like this:
Code:

#FUNCTION {zerofill} {#var {result} {%%0%2d};#format {result} {$result} {%1}}


If the sortprices alias returns nothing, either there's not the item in the Articles variable, or you have written it incorrectly (it's case sensitive)

Also, that alias uses #show just to make it visible what it does... you can change it how you want... for example, with just this little modification it returns the sectors names ordered as a list "SectorList":

Code:

#ALIAS {sortprices} {
   #LIST {ToBeSorted} CREATE;
   #LIST {AlreadySorted} CREATE;
   #foreach {$Articles[%1][]} {cnt} {
      #LIST {ToBeSorted} ADD {@zerofill{$Articles[%1][$cnt][COST];5}@zerofill{&Articles[%1][$cnt];3}}
   };
   #LIST {AlreadySorted} SORT {$ToBeSorted[%*]};
   #var {cnt2} {1};
   #foreach {$AlreadySorted[%*]} {cnt} {
      #var {SectorList[$cnt2]} {@IndexName{Articles[%1];@right{$cnt;3}}};#math {cnt2} {$cnt2 + 1};
   };
   #unvar {ToBeSorted};
   #unvar {AlreadySorted};
}


Code:

sortprices Weapons
#show {$SectorList}
{1}{Roche}{2}{Corellia}{3}{Rodia}{4}{Sullust}



For the rest I still need to find time to have a look...
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Tue Aug 08, 2017 12:27 am    Post subject: Reply with quote

Ok.. So I just copy/pasted all this.. and this is what I'm getting:

Currently, the need table looks like this:

Code:

ITEM                    | HAVE | NEED | PURCH
Armour Plating          | 1    | 778  | 777
Construction Equipment  | 42   | 0    | 0
Fuel                    | 70   | 70   | 0
Holonovels              | 50   | 50   | 0
Luxury Goods            | 15   | 199  | 184
Starship Parts          | 40   | 40   | 0
Weapons                 | 3    | 1527 | 1524
                    TOTAL 221  | 2664 | 2485


From that, we get this captured:

Code:

#VARIABLE {Articles}={{Weapons}{{Corellia}{{AMOUNT}{52}{COST}{492}}{Roche}{{AMOUNT}{52}{COST}{568}}{R
odia}{{AMOUNT}{14}{COST}{563}}{Sullust}{{AMOUNT}{78}{COST}{567}}}}
#VARIABLE {TheList}={{1}{Armour Plating}{2}{Luxury Goods}{3}{Weapons}}
#VARIABLE {ToPurch}={{Armour Plating}{800}{Luxury Goods}{200}{Weapons}{1600}}



The Weapons listing looks like this:

Code:

 ITEM                          | AMOUNT | COST | SECTOR
 Weapons                       | 52     | 568  | Roche
 Weapons                       | 14     | 563  | Rodia
 Weapons                       | 52     | 492  | Corellia
 Weapons                       | 78     | 567  | Sullust



Which captures this:
Code:
#VARIABLE {Articles}={{Weapons}{{Corellia}{{AMOUNT}{52}{COST}{492}}{Roche}{{AMOUNT}{52}{COST}{568}}{R
odia}{{AMOUNT}{14}{COST}{563}}{Sullust}{{AMOUNT}{78}{COST}{567}}}}




Now... I did a: 'Sortprices Weapons', which then creates the SectorList.. however.. it looks lke this tho:
Code:
#VARIABLE {SectorList}={{1}{@IndexName{Articles[Weapons];001}}{2}{@IndexName{Articles[Weapons];003}}{
3}{@IndexName{Articles[Weapons];004}}{4}{@IndexName{Articles[Weapons];002}}}



Which then in that case makes my #showme SectorList looks like this:

Code:

#show $SectorList
{1}{@IndexName{Articles[Weapons];001}}{2}{@IndexName{Articles[Weapons];003}}{3}{@IndexName{Articles[W
eapons];004}}{4}{@IndexName{Articles[Weapons];002}}



What could be wrong?
Back to top
View user's profile Send private message
amelsen



Joined: 18 Jul 2017
Posts: 16

PostPosted: Tue Aug 08, 2017 12:54 am    Post subject: Reply with quote

Oh btw... and supplemental question... I tried to make a similar action to capture another table, to be able to cycle through it as you showed with a different table for the vendor list.. but something is wrong in the way I set it up.. I'm sure you can spot it Powergod.

Here is the action

Code:
#ACTION {^{\s*(?!ID).*}| %2 | %3 | %4 | %5} {#if {%5=="-"} {#FORMAT {result} {%p} {%1};#VAR ToBid[$result] %1}}}


Here is the table I want to capture from:
Code:
  ID   |     EMPLOYER       |        ITEMS       | AMT  | PAYMENT | REQ

 **34  | Alpha Red          | Medical Supplies   | 4000 | 2268182 | 500
       |                    | Vong Biotech       | 2500 |         |
 BA849 | Arcon Multinode    | Vong Biotech       | 336  | 229182  | -
       | Agricorp           |                    |      |         |
 BB842 | Bimmisaari Tailors | Textiles           | 18   | 3283    | -
 BC827 | Cloud City Hotels  | Foodstuffs         | 70   | 9280    | -
       |                    | Fuel               | 30   |         |
 BC829 | Cloud City Hotels  | Foodstuffs         | 70   | 9280    | -
       |                    | Fuel               | 30   |         |
 BI826 | Interested Party   | Jedi Artifacts     | 40   | 57305   | -
       |                    | Vong Biotech       | 40   |         |
 BT828 | Trade Federation   | Refined Alloys     | 5    | 906     | -
 CF834 | Fhnark and Company | Medical Supplies   | 291  | 41306   | -
 CS832 | Silvertree         | Armour Plating     | 23   | 10950   | -
       | Enterprises        | Weapons            | 3    |         |


Now all I want to capture, is the ID's, so I with an alias like the vendor alias you created, can cycle through them one by one.

Definately something wrong with the way I'm capturing it though.. because the ToBid array looks like this:

Code:
#VARIABLE {ToBid}={{}{}{BA849 | Arcon Multinode}{BA849 | Arcon Multinode    }{BB842 | Bimmisaari
Tailors}{BB842 | Bimmisaari Tailors }{BC827 | Cloud City Hotels}{BC827 | Cloud City Hotels  }{BC829 |
Cloud City Hotels}{BC829 | Cloud City Hotels  }{BI826 | Interested Party}{BI826 | Interested Party
}{BT828 | Trade Federation}{BT828 | Trade Federation   }{CF834 | Fhnark and Company}{CF834 | Fhnark
and Company }{CS832 | Silvertree}{CS832 | Silvertree         }{DA843 | Anonymous}{DA843 | Anonymous
       }{FA835 | Arcon Multinode}{FA835 | Arcon Multinode    }{FI836 | Incom Corporation}{FI836 |
Incom Corporation  }{FN838 | NRI Special}{FN838 | NRI Special        }{FN841 | NRI Special}{FN841 |
NRI Special        }{GG848 | Geonosis Foundry}{GG848 | Geonosis Foundry   }{ID   |     EMPLOYER}{ID
|     EMPLOYER       }{KF840 | Fhnark and Company}{KF840 | Fhnark and Company }{KK839 | Korriban
Tourist}{KK839 | Korriban Tourist   }{MA846 | Arcon Multinode}{MA846 | Arcon Multinode    }{MO830 |
Obsidian Arms}{MO830 | Obsidian Arms      }{MU833 | Unlimited Horizons}{MU833 | Unlimited Horizons
}{RB847 | BioFusion}{RB847 | BioFusion          }}
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 330

PostPosted: Tue Aug 08, 2017 9:59 am    Post subject: Reply with quote

amelsen wrote:

Which then in that case makes my #showme SectorList looks like this:

Code:

#show $SectorList
{1}{@IndexName{Articles[Weapons];001}}{2}{@IndexName{Articles[Weapons];003}}{3}{@IndexName{Articles[W
eapons];004}}{4}{@IndexName{Articles[Weapons];002}}



What could be wrong?


Have you declared the "IndexName" function ? (And maybe also the "right" function ?)


About the other action, seems to me you are missing a column... the comparison should be made with "%6"
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 -> 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