tbl = {
Resource_AtoA = { a = 1.11, b = 1.11, c = 5 },
Resource_BtoA = { a = 2.22, b = 1.11, c = 5 },
Resource_CtoA = { a = 3.33, b = 1.11, c = 5 },
Resource_AtoB = { a = 1.11, b = 9.99, c = 5 },
Resource_BtoB = { a = 2.22, b = 1.11, c = 5 },
Resource_CtoB = { a = 3.33, b = 1.11, c = 5 },
Resource_AtoC = { a = 1.11, b = 1.11, c = 999 },
Resource_BtoC = { a = 2.22, b = 2.22, c = 999 },
Resource_CtoC = { a = 3.33, b = 3.33, c = 999 },
}
Now - obviously looking above: The origin is location C. -We- can see that, because thce resources match the origin. (B-A)/C is going to equal 0. Now, while the time unit for C to C should in theory be zero, considering they're the same location, when I set the C values based on the origin (again, I'll mention later), any location it can't reach I'm sticking a high number for - in attempts to persuade the script from not selecting that value at the end of Stage 2 of the script, where it selects the most cost effective route immediately. I probably should put in more safeguards, but I can't think for the life of me -how- at the moment, and it doesn't matter. I'll be at the computer reguardless, babysitting the script - so I can pause it if it does something that I told it that it 'can' do, but I know that it shouldn't.
Anyways - back to the table. We can tell that Buying Resource A at Location C and bringing it to Location B is the most cost effective trade. (In the above example, all the constants are 5, meaning it takes 5 units of time to get from location C to B and A).
Now, pausing what we have so far, the problems I'm having thus far.
So the script starts. I initiate an alias, that says:
"origin LocationA"
This should call a script in the .lua file that sets origin = 1, and then calls for the LocationA data from the mud (by sending the appropriate command, "look chart LocationA" - where LocationA is obviously the stored variable). The chart echoing to the mud will call forth the trigger, which will call for the script "SetupLocationA" - that script should have an IfCheck, where If Origin = 1, it populates the appropriate A values in the table; then set origin = 0; the send the stacked commands to read all of the charts - which activate their own triggers. If its = 0, it should populate the B values - which once origin = 0, when the stacked commands come through, they'll populate all the B values.
In order to test it, I set up a script (below) that is called for instead of SetupLocationA, which uses the ExampleScript as a model to help me ensure all appropriate values are assigned by the trigger.
That worked great.
Then I tried making the function SetupLocationA - which I deleted last night out of frustration. Stupid me. Now I have to start over.
When I tried to assign the values to the table, I kept getting nil value errors every time I tried to call the wildcards that were pulled from the mud - and stick them in the table. So I was probably doing it entirely wrong. It looked something to the effect of (based on memory)
ResourceA = tonumber ("ResourceA")
tbl.resource_AtoB.b = ResourceA
A lot of places I probably screwed up there.
Now:
When that problem is solved, and I can populate the table correctly, the plan is to follow the end of the population script (by calling command at the end of the last chart's population function) with the aforementioned example to do the math and sort the data:
-- calculate a to b
for k, v in pairs (tbl) do
v.atob = (v.b - v.a) / v.c -- difference divided by a constant
end -- for loop
-- display results
require "tprint"
tprint (tbl)
-- sort to find highest atob
require "pairsbykeys"
function f (ka, kb)
return tbl [ka].atob > tbl [kb].atob
end -- sort comparison function
for k, v in pairsByKeys (tbl, f) do
print ("-----", k, "-----")
tprint (v)
end -- for
Now - the problem I'm going to face at THAT point - is how do I take what the script now has determined (that being the most efficient path to take the item), and assign them to two variables - the resource and destination. While I would normally at this point dump said information into the client and rely on triggers and the like, I have a feeling scripts might actually work better - due to the ability to call forth the wait function - but thats neither here nor there. I can at least make it work for now via triggers, and then upgrade the script once to include the additional bits.
But again:
I have no idea how to even pull the needed values out of the above code to populate the variables - partly because I'm not quite sure what went on there. Pairs and the like. I skimmed the help file, and it said to transverse all items in the table. I was thinking - brilliant? Now what do the augmentations in the syntax mean? I could maybe figure it out, but I keep having to split my time between writing this and actually doing it the slow way in the Mud- in the event I can't actually pull this off....
Well -
I'll reread this in about an hour, once I've cleared my head, and see if I can ammend anything to it to make it clearer. Thanks...
|