Posted by: the bigg
« on: December 23, 2005, 06:18:02 AM »They work like this (from a mod of mine, soon to be released, contains also example of how to pass parameters via global variables):QuoteDEFINE/LAUNCH_ACTION_MACRO (with MACRO_ACTION as synonim) added, they are similar to the so-called functions in bash (or, less precisely, to Basic's GOSUB). On the same line, DEFINE/LAUNCH_PATCH_MACRO (with MACRO_PATCH as synonim). Tutorials pending.Although no one except the bigg knows how to use it yet, this feature looks really useful. I just have a question regarding these commands, and it is on: whether the patches inside an INNER_* block in *_ACTION_MACRO, and the actions inside an OUTER_* block in *_PATCH_MACRO will work. Hope that makes sense.
Code: [Select]
/* a tp2 flag */
DEFINE_ACTION_MACRO ~FASTER_ROMANCES~ BEGIN
<<<<<<<< faster_romance/macro/fixme.d
REPLACE_ACTION_TEXT_REGEXP ~\(^aerie$\)\|\(^kalah2$\)~ ~StartDialogueNoSet()~ ~StartDialogueNoSet([PC])~
REPLACE_ACTION_TEXT ~baerie~ ~MoveGlobal("AR0607","Aerie",\[1034\.1034\],0)~ ~MoveGlobal("AR0607","Aerie",[1034.1034])~
>>>>>>>>
/* fix baerie.dlg (and others) ! */
COMPILE ~faster_romance/macro/fixme.d~
COPY_EXISTING ~sw1h01.itm~ ~override/tb#faster1.txt~
COPY_EXISTING ~gtimes.ids~ ~override~
READ_2DA_ENTRIES_NOW ~_#_#_#gtimes~ 2
BUT_ONLY_IF_IT_CHANGES
COPY_EXISTING_REGEXP GLOB ~.*\.bcs~ ~override~
DECOMPILE_BCS_TO_BAF
FOR (i = 0; i < _#_#_#gtimes; i+=1)
BEGIN
READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 0 number
READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 1 string
REPLACE_TEXTUALLY ~,%string%)~ ~,%number%)~
END
REPLACE_EVALUATE ~RealSetGlobalTimer(\(\"[^"]*\",\"[^"]*\"\),\([^)]*\))~
BEGIN
temp = multiply * MATCH2 ** (exponentiation nth_root) / divide
MATCH2 = temp < MATCH2 ? temp : MATCH2
SPRINT RESULT ~%MATCH2%~
END
~RealSetGlobalTimer(%MATCH1%,%RESULT%)~
COMPILE_BAF_TO_BCS
BUT_ONLY_IF_IT_CHANGES
IF ~^268OB~
COPY_EXISTING_REGEXP GLOB ~.*\.dlg~ ~override~
DECOMPILE_DLG_TO_D
FOR (i = 0; i < _#_#_#gtimes; i+=1)
BEGIN
READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 0 number
READ_2DA_ENTRY_FORMER ~_#_#_#gtimes~ i 1 string
REPLACE_TEXTUALLY ~,%string%)~ ~,%number%)~
END
REPLACE_EVALUATE ~RealSetGlobalTimer(\(\"[^"]*\",\"[^"]*\"\),\([^)]*\))~
BEGIN
temp = multiply * MATCH2 ** (exponentiation nth_root) / divide
MATCH2 = temp < MATCH2 ? temp : MATCH2
SPRINT RESULT ~%MATCH2%~
END
~RealSetGlobalTimer(%MATCH1%,%RESULT%)~
COMPILE_D_TO_DLG
IF ~RealSetGlobalTimer~
BUT_ONLY_IF_IT_CHANGES
END
/* the components */
/* ****************************************
FASTER ROMANCES
**************************************** */
/* RealSetGlobalTimer(_,_,x) is changed to be
multiply * x ^ (exponentiation / nth_root) / divide
(but only if the value decreases).
Values for multiply, exponentiation, nth_root and divide are computated
thanks to an external program written in C, included in the mod distribution,
see the file other/compute_faster_romance.c .
If you want me to add different pairs (not necessarily 3600->x and 36000->x),
it can be done fairly trivially, so ask away. (you can even compile and run
the 'compute_faster_romance' program yourself to find out the values yourself).
*/
BEGIN @9001
SUBCOMPONENT @9000
DESIGNATED 2500
// 3600 -> 3300
// 36000 -> 18000
OUTER_SET multiply = 795
OUTER_SET divide = 1000
OUTER_SET exponentiation = 736
OUTER_SET nth_root = 1000
LAUNCH_ACTION_MACRO ~FASTER_ROMANCES~
BEGIN @9002
SUBCOMPONENT @9000
DESIGNATED 2550
// 3600 -> 3000
// 36000 -> 12000
OUTER_SET multiply = 21689
OUTER_SET divide = 999
OUTER_SET exponentiation = 602
OUTER_SET nth_root = 1000
LAUNCH_ACTION_MACRO ~FASTER_ROMANCES~
BEGIN @9003
SUBCOMPONENT @9000
DESIGNATED 2600
// 3600 -> 2700
// 36000 -> 9000
OUTER_SET multiply = 37581
OUTER_SET divide = 1002
OUTER_SET exponentiation = 523
OUTER_SET nth_root = 1001
LAUNCH_ACTION_MACRO ~FASTER_ROMANCES~
basically, all they do is copying-pasting the code in DEFINE where is a LAUNCH (except that they *should* also be recursive), so they should work also in INNER and OUTER.
EDIT: actually, Refinements beta uses INNER_* inside a DEFINE_ACTION_MACRO and it works.
Also, macroes are recursive (IE a macro can call itself), so EG you can calculate a factorial:
Code: [Select]
DEFINE_ACTION_MACRO ~factorial~ BEGIN
ACTION_IF i != 1 THEN
BEGIN
OUTER_SET factor = factor * i
OUTER_SET i = i - 1
LAUNCH_ACTION_MACRO ~factorial~
END
END
BEGIN ~calculate a factioral~
OUTER_SET ~i~ = 5
OUTER_SET ~i_backup~ = ~%i%~
OUTER_SET ~factor~ = 1
LAUNCH_ACTION_MACRO ~factorial~
PRINT ~%i_backup%! = %factor%~
Take your time to make a mental note *never* to use global variables like that in a real programming language. Unfortunately, WeiDU ties our hands