Whether Initialising variables in the 'Before Experiment' or 'Begin Experiment' module

Hi, when I run my experiment locally , I saw NO difference between these two modules in the Code Component.
However, only if I define the variable,‘Learn_graph_index’ in the ‘Begin Experiment’ module, my experiment can successfully work online.
In the ‘begin routine’ module, certain values will be determined from this variable by my selecting rules. The code is ‘value_for_subject = Learn_graph_index[row_set_by_my_rule]’

Why do my experiment get stuck but go no errors if I set ‘Learn_graph_index’ in ‘Before Experiment’? These two modules seem to have much more differences when being used online than locally.
I need your help!