Additional input and inventory management

Metraxis

Member
I'm working on a daily inventory cleanup script for my basement dives and for after defeating her Naughtiness. The script has two functional parts. The first processes a map of instructions, and that part was not difficult, but I am having difficulty with the second part, which (hopefully) adds to the map. The map is of type instructionRecord [item], where instructionRecord is defined like this:

Code:
record instructionRecord {
 string action1;
 int amount1;
 string action2;
};

The script processes each record by doing action1 to amouint1 of the items in inventory, and action2 to the rest. For example, the record for "obsidian dagger" would read "keep", 2, "display", which would keep 2 in inventory and stuff the rest in my display case, or "tiny plastic anime smiley" might read "display", 1, "send", which would stick 1 into my display case, and send the rest to my wife, who collects the things.

What I need to finish the second part are two things. First, a way to load my current inventory into a map, and I think I remember seeing that somewhere among the tthreads. The first part can be made to function without this by parsing through an exhaustive list, but 'tis inelegant, I think. The second thing I need is a way to get input in mid-stream, something along the lines of:

Code:
foreach Thing in iinvList {
 if(invList[Thing].action == "") {
  [Pop up input dialogs to collect the pieces of the record]
 } else {
  [Normal record processing]
 }
}

Of course, this can be made to work in other ways, but I'd rather not build my map by stuffing everything recognizable into my closet and then manually adding records for what's left in inventory.
 

macman104

Member
Yes, there is now a getInventory function. I forget the exact but if you ashref inventory, it should pop up.
 

Metraxis

Member
ashref and get_inventory both appear to be incredibly awesome, and will certainly help cut down on processing time and spam. Now all I need is mid-stream input.
 
for yes/no type questions there is boolean user_confirm( string )
for other there is a cluncky workaround, starting another script with parameters to main(), and saving the answers in properties.
 

Metraxis

Member
It looks like there are two versions of file_to_map(). What is the purpose of the boolean parameter #3 in the second version? get_inventory() doesn't seem to have made it into the wiki yet. Also, would executio0n of another script be done through some ASH function, or through cli_execute("call foo.ash")

EDIT: Also, is there an ASH equivalent to the 'contains' operator?

EDIT again: While tinkering, I've noticed that there seems to be no ASH function that sticks things in the mall. Is that a deliberate omission?
Re-edit:The function exists, but doesn't contain 'mall' in its name and doesn't let you control the quantity sold in a server-friendly manner.
 
[quote author=Metraxis link=topic=1722.msg8145#msg8145 date=1211380171]
It looks like there are two versions of file_to_map(). What is the purpose of the boolean parameter #3 in the second version?
[/quote]

I am unsure of the answer to that one.

Also, would executio0n of another script be done through some ASH function, or through cli_execute("call foo.ash")

cli_execute("call foo.ash")

EDIT: Also, is there an ASH equivalent to the 'contains' operator?

Code:
boolean contains()
{

}
result:
Code:
> call scripts\contains.ash
Reserved word 'contains' cannot be used as a function name (contains.ash, line 1)

I would say there is.

EDIT again: While tinkering, I've noticed that there seems to be no ASH function that sticks things in the mall. Is that a deliberate omission?
Re-edit:The function exists, but doesn't contain 'mall' in its name and doesn't let you control the quantity sold in a server-friendly manner.

the ash version is not server friendly anyway. None of the inventory movement functions in ASH are server friendly when handling multiple items. The CLI versions can put multiple items at once into the mall. closet, and all other locations

Code:
int maxint = 2147483647;

typedef int [item] itemset;

//mapname.do_dump(command)
void do_dump(itemset set, string command)
{
	string temp_command = command;
	foreach key in set
	{
		if(set[key] == maxint)
			temp_command = temp_command + "* " + key + ", ";
		else
			temp_command = temp_command + set[key] + " " + key + ", ";
	}
	if( temp_command != command )
	{
		//trim last camma space pair
		temp_command = substring(temp_command, 0, last_index_of(temp_command, ", " ));
		cli_execute(temp_command);
	}
}

usage: declare a variable of the type "itemset" type defined in the above code, fill it with the list of items you want to sell in the mall, and the quantities (maxint for all), then

mapname.do_dump(command);

where command can be:
"closet put "
"display put "
"stash put "
"mallsell "

make sure the space is there.
No pricing will be done for items going into the mall.
all commands are cli commands, and will move items 11 at a time automatically for you.

Special note: Thanks again to Holatuwol for making that wrapper function possible by modifying mall management in the CLI, and for the help with repairing the broken code it was originally written to work with.
 

macman104

Member
[quote author=Metraxis link=topic=1722.msg8145#msg8145 date=1211380171]
It looks like there are two versions of file_to_map(). What is the purpose of the boolean parameter #3 in the second version?[/quote]It relates to whether the information is stored in compact mode or not. I've snipped some info, but here's some of a post from Veracity
Brianna Sollandry said:
OK, I just submitted code to write & read records in a compact format. I left the option to use the old format, but the new one is the default.

boolean map_to_file( map, filename, compact);
boolean file_to_map( filename, map, compact);

"compact" is a boolean. true means new format, false means old format.

The old versions still exist.

boolean map_to_file( map, filename);
boolean file_to_map( filename, map);

They currently default to compact = true.

wr_common.ash:
Code:
record rec {
  int int_field;
  string string_field;
  item item_field;
  record {
    int low;
    int high;
  } record_field;
  element element_field;
};
wr_write.ash:
Code:
import <wr_common.ash>;

rec [ int ] map;

map[ 1 ] = make_rec( 1, "abc", $item[toast], 10, 20, $element[hot] );
map[ 2 ] = make_rec( 2, "def", $item[snorkel], 100, 200, $element[cold] );
map[ 3 ] = make_rec( 3, "xyz", $item[seal tooth], 1000, 2000, $element[spooky] );

map_to_file( map, "rec1.out", false );
map_to_file( map, "rec2.out", true );
Here are data files. rec1.out (368 bytes):
Code:
1	int_field	1
1	string_field	abc
1	item_field	toast
1	record_field	low	10
1	record_field	high	20
1	element_field	hot
2	int_field	2
2	string_field	def
2	item_field	snorkel
2	record_field	low	100
2	record_field	high	200
2	element_field	cold
3	int_field	3
3	string_field	xyz
3	item_field	seal tooth
3	record_field	low	1000
3	record_field	high	2000
3	element_field	spooky
rec2.out (89 bytes):
Code:
1	1	abc	toast	10	20	hot
2	2	def	snorkel	100	200	cold
3	3	xyz	seal tooth	1000	2000	spooky
get_inventory() doesn't seem to have made it into the wiki yet.
Yea, wiki is in need of updating. I don't have time, but someone was talking about revamping it to make it easier to manage.
EDIT: Also, is there an ASH equivalent to the 'contains' operator?
I'm not sure what you mean. contains is a command for a map, which is an ash structure.
 
[quote author=macman104 link=topic=1722.msg8150#msg8150 date=1211398160]
I'm not sure what you mean. contains is a command for a map, which is an ash structure.
[/quote]

Contains is a common operator in other programming languages, I figure by "equivalent" what was mean was "equal to contains in other languages".
 

Metraxis

Member
I had meant, "Is equivalent to the 'contains' CLI structure, since the examples I found looked like they were from CLI scripts rather than ASH scripts. I fudged it by testing action1 for the empty string.

In any case, I've got something which seems to work, and here 'tis. Let me know if you all have any ideas for improvement or other comments.
 

Attachments

  • Input.ash
    66 bytes · Views: 56
  • DailyCleanup.ash
    2.7 KB · Views: 60
  • dailyCleanup.map
    8.3 KB · Views: 100
I looked over your code, and saw an issue (well it's something that would bug me). Depending on what you do in game that day you could be hitting the server 110 times for every 10 times you should be.

I studied your code, and tried to come up with a way to use the server friendlier code above in your situation, and gave up. That's when it slapped me in the face. Make 2 passes through your inventory calling TakeAction once rather than one pas through calling TakeAction twice, and modify TakeAction to fill the map rather than do the item movement.

I attached the modified script, but I haven't done any testing on it...not even a verify. Have a look see, maybe you'll like what I've done, or maybe it will give you your own ideas.

Note: Text messages should fly by very quickly now as they are displayed before the action is taken. I only attached the modified file, the other files are still needed.
 

Attachments

  • DailyCleanup-1-modified.ash
    4.1 KB · Views: 55

dawdawdo

Member
I'm making something similar to this, but I'm having trouble with the map_to_file() function. It doesn't seem to know how to handle the _sup{TM} as in E-Z Cook Over_sup{TM}. It show up in the .map file as a '?' instead. This, obviously, is a problem.

Do you guys think this is a (variable) typing issue? Maybe I should store the items as string types instead of item types?

I am aware that I could take care of these items manually, but it would be nice if the script recognized them.
 
Top