Forum Discussion

RobertFromDresd's avatar
RobertFromDresd
Occasional Contributor
12 years ago

Help needed! GlobalVariables in 2 units didnt work

Hi,



I have 2 script units (jscript) and try to use the GlobVariables in both, but it didnt work. I read all helptopics about useunit, runner and related but dont get it.



My setup:

////////////////////////////////////////////////////////////

// MainUnit //

var settingA = setting for A ';

var settingB = 'setting for B';



//USEUNIT SubFunctionsUnit



function mainloop()

{

   Log.Message ( 'MainLoop' + settingA );

   subfnct( settingB  );

}



////////////////////////////////////////////////////////////

// SubFunctionsUnit //

function subfnct( settingB   )

{

   Log.Message ( 'subfnct SA:' + settingA );

   Log.Message ( 'subfnct SB:' + settingB  );

}



You see, there are two functions. The MainUnit where i setup all my glob variables and with mainloop() where i control all sub functions to keep track of the scripts process and not get disturbed by all the small action-functions who doing things. But in subfnct() in another script i can not access to settingA.



Hope anyone can help me use global variables :(



Best Regards

Robert

1 Reply

  • RobertFromDresd's avatar
    RobertFromDresd
    Occasional Contributor
    Hi @ All





    for me, now I find a way..

    I modifiy the MVC Pattern from regular programming into TC-Programming and call it chained-moduleprinciple. In the construction includes every Unit the next logical Unit and the last unit is the config unit therefore all global variables are now accessible from every script. When you give all units logical names you got a tiny nice mvc patternstyle logic. I named my units this way:



    Start -> MainFunctions -> Functions -> Config



    (Every unit includes the next to its right )



    greets

    Robert