bordemstirs
Member
So, I have two scripts that run concurrently, all the time, and they both, at various times, require access to the same data, and they save it.
For a while I've just been banking on the brevity of the execution time and hoping that they never try to read/write at the same time, but it's come time to actually enforce that...
What I'm using to achieve this are the following functions:
This code alone generates no errors... until I try to use it.
I have a structure defined like this:
and attempting userdata=checkOut("userdata.txt"); I get an error:
Cannot store aggregate in userdata of type userinfo [string] (login.ash, line 31)
Any idea what's going on here? Or do I just not understand how "aggregate" works?
For a while I've just been banking on the brevity of the execution time and hoping that they never try to read/write at the same time, but it's come time to actually enforce that...
What I'm using to achieve this are the following functions:
Code:
aggregate checkOut(string resourceName){
aggregate data;
file_to_map("resources.txt",resources);
while ((resources[resourceName]!="")&&(resources[resourceName]!=__FILE__)) waitq(1);
resources[resourceName]=__FILE__;
map_to_file(resources,"resources.txt");
file_to_map(resourceName,data);
return data;
}
aggregate update(string resourceName){
aggregate data;
file_to_map(resourceName,data);
return data;
}
string commit(aggregate data, string resourceName){
file_to_map("resources.txt",resources);
string owner=resources[resourceName];
if (owner==__FILE__){
map_to_file(data,resourceName);
resources[resourceName]="";
map_to_file(resources,"resources.txt");
}
return owner;
}
string commit(string resourceName){
file_to_map("resources.txt",resources);
string owner=resources[resourceName];
if (owner==__FILE__){
resources[resourceName]="";
map_to_file(resources,"resources.txt");
}
return owner;
}
This code alone generates no errors... until I try to use it.
I have a structure defined like this:
Code:
record userinfo{
int userid;
string nick;
boolean[string] multis;
int gender;//see gengers[] definition comments
int flags;//see flag bits
string[string] buffpacks;
int[int] buffs;
float lastMath;
string lastTime;
string lastTrigger;
int donated;
int wallet;
};
userinfo[string] userdata;
and attempting userdata=checkOut("userdata.txt"); I get an error:
Cannot store aggregate in userdata of type userinfo [string] (login.ash, line 31)
Any idea what's going on here? Or do I just not understand how "aggregate" works?
Last edited: