Change variables and maps from other scripts

Gymhgy

New member
How do I call on a map or change a variable in an imported script?
Pretend I have script A with a map of items that are true or false.
In my other script, I import script A and want to do a foreach for all that return true in the map in script A.
I see other people's scripts import EatDrink.ash, and that means there is a way to use values from other scripts.
 

fronobulax

Developer
Staff member
First thing you should do is see whether the script author has already provided something. For example, CFStat.ash has

Code:
// Record for caching sales volume hits from ColdFront
record itemdata {
   int lastupdated;
   float avePrice;
   int amountsold;
};
// Global map with CFdata - global for performance
itemdata[int] cfData;

but I don't really expect you to access cfData directly. Instead I have provided a function salesVolume that you call with an item and it returns and itemdata record of Coldfront data for that item.

So if there is something you want from CFStat and you can't get it from calling salesVolume you could consult with the author and see if there is already something or if they are willing to add something.

One reason to do things this way is that the reading and writing of the map is handled by the author. This may be important if there is data with special meaning or there are type conversions being done.

If you don't want to do that you could access cfData directly, for example foreach i in cfData, but then you are responsible for reading the map first because if you don't there will be nothing in it. You may also have to deal with the possibility that the author deliberately did not make it global in which case you can't access it directly and should probably be asking why they didn't want you to access it directly.

Clear as mud?
 
Top