file_to_map

heeheehee

Developer
Staff member
file_to_map by default will parse the file as tab-separated values. First column is the key, second column is the value. If you have a multi-dimensional value (e.g. a record, or another map), then that takes up one column per dimension. Since your map value in this case is a scalar (string), map_to_file only parses the first two columns of your datafile.
 

Pazleysox

Member
file_to_map by default will parse the file as tab-separated values. First column is the key, second column is the value. If you have a multi-dimensional value (e.g. a record, or another map), then that takes up one column per dimension. Since your map value in this case is a scalar (string), map_to_file only parses the first two columns of your datafile.

How can I save the data to multiple lines? I've found a temporary way around it, which i'm not happy with.
 

fronobulax

Developer
Staff member
How can I save the data to multiple lines?

WTH does that mean?

Your file has multiple lines already.

Are you saying you want something like
message1
message1time1
message1time2
message2
message2time1
message2time2
message2time3

?

If so multiple lines is NOT the best way to manage the data in ash.

I feel like there is a disconnect between what we assume you know about maps and what you actually know about maps and I'm not sure how to bridge that.

Could we step back and look at the problem you are trying to solve and not the details of your solution?

Where is your data coming from? Specifically is it something you are reading and have no control over the format? Is it something you created, but not in ash, so you have some control over the format? Is it something you are creating in ash, in which case you need to define and use a map that supports the data and the use.

As a general rule, if it can be represented in a spreadsheet it can be represented as an ash map fairly easily.
 

Pazleysox

Member
WTH does that mean?
lol
Where is your data coming from? Specifically is it something you are reading and have no control over the format? Is it something you created, but not in ash, so you have some control over the format?

I'm working on my chatbot script. I was trying to figure out a way to record the last thing someone said, and the time they said it.

TBT, I didn't want to say that, because every time I mention chatbot, people seem to run away. I did find a way to record what I needed in a setting, so technically what I wanted works. As per our earlier talk, I really didn't want to do it this way, but it DOES work...

For future reference, here's what I did.
PHP:
	if(contains_text(to_lower_case(sender), "pazsox"))
	{
	set_property("pazsoxseen", now_to_string("EEE, h:mm"));  // here's where it records the day and time
	set_property("pazsoxsaid", message); // here's where it records the message
	}
	if(contains_text(to_lower_case(message), "seen pazsox"))
	{
	chat_clan("PazSox was last seen " + get_property("pazsoxseen") + " and said: " + get_property("pazsoxsaid")); //returns time day/time, and then message
		}
 

fronobulax

Developer
Staff member
OK.

You are parsing something and extracting a user, message and a time from it. User and message are strings and time is an int.

I would define this record.

Code:
record conversation {
   string user;
   string message;
   int time;
}

I would then declare an "array" of the record.

Code:
conversation[int] chatz;

I would read and write using the utilities.

map_to_file(chatz,"chatHistory.txt");
file_to_map("chatHistory.txt", chatz);

I would add a new conversation record by...
Code:
conversation newConv;
newConv.user = ...
newConv.message = ...
newConv.time = ...

chatz[count(chatz)+1] = newConv;

The ... means fill in the data you parsed from elsewhere.

I think you know how to iterate and search.

This assumes that the integer used to index the map is not really relevant - it doesn't matter what order the "conversations" occur in the file.

It might be important to know the date of when things happened. That could be done by using a new file for each date or by adding a date to the record or by converting the time into a timestamp yyyymmddhhmmss.

I have not tested any of the code.

I have no game or social reason to use chat and I do keep a character who has never visited the Altar of Literacy to test mafia, but I'm actually OK with you trying things with a chatbot.
 
Top