jkgarner
Posts: 174
Joined: 4/30/2020 Status: offline
|
Hi, There are two way to solve this issue. By passing the information forward as parameters along the chain of events, or by packing the unit and side names into the event name. Method one: Write functions for each event that takes the unit identifying data as parameters, fall them something meaningful (e.g. foo1, foo2) The script for the first event will use UnitX to get the unit identifying data and pass it to foo1. foo1, can put the info into the script generated for event 2 as follows: local script = "" script = script.."foo2('"..side-name.."', '"..unit_name.."')" The drawback to this method is that both functions must be visible, which means they must belong to a namespace (or object) that is loaded by the scenario. The best way to do this is through the use of scenario attachments. if this is too much for you right now, there is the second method. Method 2: If you pack data into the event name you can then parse the event name and get the information you need. The only trouble you will have is to guarantee uniqueness of the event name across the system. One way to do this is also pack something else unique, like the time the event was triggered. Here is a function that packs data to use as an example: (you will need to modify it for your data)StepKeyValueName =
function(side_name, unit_name, day)
local separator = 'XXX'
local stepKeyValueName = "StepValue"..separator..
side_name..separator..
unit_name..separator..
"D"..day
local retVal = RemoveSpecialChars(stepKeyValueName)
return retVal
end The justification and implementaion of RemoveSpecialChars can be found at the thread: https://www.matrixgames.com/forums/tm.asp?m=4977343 The matching parse function isParseStepEventName =
function(stepEventName)
local side = nil
local unit = nil
local day = nil
local step = nil
local suffix = nil
if (stepEventName ~= nil and type(stepEventName) == 'string') then
local separator = 'XXX'
local data = LeMay.splitString(stepEventName,separator)
if (#data > 5) then
side = data[2]
unit = data[3]
day = tonumber(string.sub(data[4], 2))
step = tonumber(string.sub(data[5], 2))
suffix = data[6]
end
end
return side, unit, day, step, suffix
end So in the first event, use UnitX function to get the unit data. Then pack it into a local vaariable eName and use that variable to set the event name when generating your event. You will need to add the following to the beginning of your script: local script = ""
script = script.."SpecialCharCodes = {".."\r\n"
script = script.." [1]={char='`', pat='%`', code='_btick_'},".."\r\n"
script = script.." [2]={char='~', pat='%~', code='_tilde_'},".."\r\n"
script = script.." [3]={char='!', pat='%!', code='_bang_'},".."\r\n"
script = script.." [4]={char='@', pat='%@', code='_at_'},".."\r\n"
script = script.." [5]={char='#', pat='%#', code='_hash_'},".."\r\n"
script = script.." [6]={char='$', pat='%$', code='_dol_'},".."\r\n"
script = script.." [7]={char='%', pat='%%', code='_pct_'},".."\r\n"
script = script.." [8]={char='^', pat='%^', code='_hat_'},".."\r\n"
script = script.." [9]={char='&', pat='%&', code='_amp_'},".."\r\n"
script = script.." [10]={char='*', pat='%*', code='_splat_'},".."\r\n"
script = script.." [11]={char='(', pat='%(', code='_op_'},".."\r\n"
script = script.." [12]={char=')', pat='%)', code='_cp_'},".."\r\n"
script = script.." [13]={char='+', pat='%+', code='_plus_'},".."\r\n"
script = script.." [14]={char='=', pat='%=', code='_eq_'},".."\r\n"
script = script.." [15]={char='{', pat='%{', code='_ocb_'},".."\r\n"
script = script.." [16]={char='}', pat='%}', code='_ccb_'},".."\r\n"
script = script.." [17]={char='|', pat='%|', code='_pipe_'},".."\r\n"
script = script.." [18]={char='[', pat='%[', code='_osb_'},".."\r\n"
script = script.." [19]={char=']', pat='%]', code='_csb_'},".."\r\n"
script = script.." [20]={char='\\', pat='%\\', code='_bslash_'},".."\r\n"
script = script.." [21]={char=':', pat='%:', code='_colon_'},".."\r\n"
script = script.." [22]={char='\"', pat='%\"', code='_quote_'},".."\r\n"
script = script.." [23]={char=';', pat='%;', code='_scolon_'},".."\r\n"
script = script.." [24]={char='\'', pat='%\'', code='_tick_'},".."\r\n"
script = script.." [25]={char='<', pat='%<', code='_lt_'},".."\r\n"
script = script.." [26]={char='>', pat='%>', code='_gt_'},".."\r\n"
script = script.." [27]={char='?', pat='%?', code='_ques_'},".."\r\n"
script = script.." [28]={char=',', pat='%,', code='_comma_'},".."\r\n"
script = script.." [29]={char='.', pat='%.', code='_stop_'},".."\r\n"
script = script.." [30]={char='/', pat='%/', code='_slash_'},".."\r\n"
script = script.." [31]={char=' ', pat='%s', code='_sp_'},".."\r\n"
script = script.."}".."\r\n"
script = script.."\r\n" as well as script = script.."ReplaceSpecialChars =".."\r\n"
script = script.."function(inputStr)".."\r\n"
script = script.." local retval = inputStr".."\r\n"
script = script.." local i = #LeMay.SpecialCharCodes -1".."\r\n"
script = script.." while i > 0 do".."\r\n"
script = script.." local cData = LeMay.SpecialCharCodes[i]".."\r\n"
script = script.." local rpl = cData.char".."\r\n"
script = script.." if (rpl == '%') then rpl = '%%' end".."\r\n"
script = script.." if (rpl ~= ' ') then ".."\r\n"
script = script.." retval= string.gsub(retval, cData.code, rpl) ".."\r\n"
script = script.." end".."\r\n"
script = script.." i = i - 1".."\r\n"
script = script.." end".."\r\n"
script = script.." --handle spaces!".."\r\n"
script = script.." local temp = ''".."\r\n"
script = script.." local strdata = LeMay.splitString(retval, '_sp_')".."\r\n"
script = script.." local j = 0".."\r\n"
script = script.." while j < #strdata do".."\r\n"
script = script.." j=j+1".."\r\n"
script = script.." if (temp ~= '') then ".."\r\n"
script = script.." temp = temp..' '".."\r\n"
script = script.." end".."\r\n"
script = script.." temp = temp..strdata[j]".."\r\n"
script = script.." end".."\r\n"
script = script.." retval = temp".."\r\n"
script = script.." return retval".."\r\n"
script = script.."end".."\r\n" After you modify the above function to pack the name and parse the name to suit, you will have to put the parse function in the script (similar to what you see above) In the script, use EventX to access the current event, and get its name, then use the parse function to extract the unit identifying information. I have used both methods successfully to pass information to later events in a chain of events. Good luck
|