@@ -34,6 +34,14 @@ func _init(store_manager):
3434 else :
3535 push_error ("execturer, VARIABLE_IN_STR compilation failed" )
3636
37+ func get_current_thread_datas () -> Dictionary :
38+ if current_thread and current_thread .is_active ():
39+ var dico = threads [current_thread .get_id ()]
40+
41+ return {"file_base_name" :dico ["file_base_name" ], "last_index" :dico ["last_index" ]}
42+
43+ return {}
44+
3745func stop_current_thread () -> int :
3846 if current_thread and current_thread .is_active ():
3947 var dico = threads [current_thread .get_id ()]
@@ -42,7 +50,7 @@ func stop_current_thread() -> int:
4250 dico ["semaphore" ].post ()
4351 return OK
4452
45- func execute_script (script_name :String , label_name :String ) -> int :
53+ func execute_script (script_name :String , label_name :String = "" , index : int = 0 ) -> int :
4654 stop_current_thread ()
4755
4856 if store_manager .parsed_scripts .has (script_name ):
@@ -52,7 +60,9 @@ func execute_script(script_name:String, label_name:String) -> int:
5260
5361 var dico = {"thread" :current_thread , "semaphore" :current_semaphore , "file_base_name" :script_name , "stop" :false }
5462
55- if ! label_name .empty ():
63+ if index > 0 :
64+ dico ["last_index" ] = index
65+ elif ! label_name .empty ():
5666 dico ["label_name" ] = label_name
5767
5868 if current_thread .start (self , "do_execute_script" , dico ) != OK :
@@ -101,8 +111,6 @@ func do_execute_script(parameters:Dictionary):
101111 var file_base_name = parameters ["file_base_name" ]
102112
103113 Rakugo .send_execute_script_start (file_base_name )
104-
105- var index := 0
106114
107115 var script = store_manager .parsed_scripts [file_base_name ]
108116
@@ -111,17 +119,26 @@ func do_execute_script(parameters:Dictionary):
111119 var labels = script ["labels" ]
112120
113121 var error = OK
122+
123+ var index := 0
124+
125+ if parameters .has ("last_index" ):
126+ index = parameters ["last_index" ]
127+ else :
128+ parameters ["last_index" ] = 0
114129
115- if parameters .has ("label_name" ):
116- var label = parameters ["label_name" ]
130+ if parameters .has ("label_name" ):
131+ var label = parameters ["label_name" ]
117132
118- index = do_execute_jump (label , labels )
133+ index = do_execute_jump (label , labels )
119134
120- if index == - 1 :
121- parameters ["error" ] = jump_error + label
122- parameters ["stop" ] = true
135+ if index == - 1 :
136+ parameters ["error" ] = jump_error + label
137+ parameters ["stop" ] = true
123138
124139 while ! parameters ["stop" ] and index < parse_array .size ():
140+ parameters ["last_index" ] = index
141+
125142 var line :Array = parse_array [index ]
126143
127144 var result = line [1 ]
@@ -212,12 +229,15 @@ func do_execute_script(parameters:Dictionary):
212229 if menu_jumps .has (menu_jump_index ):
213230 var jump_label = menu_jumps [menu_jump_index ]
214231
215- index = do_execute_jump (jump_label , labels ) - 1
232+ index = do_execute_jump (jump_label , labels )
216233
217- if index == - 2 :
234+ if index == - 1 :
218235 parameters ["error" ] = jump_error + jump_label
219236 parameters ["stop" ] = true
220237 break
238+
239+ # remove 1 because we add 1 at the end of the loop
240+ index -= 1
221241 elif ! (menu_jump_index in [0 , menu_choices .size () - 1 ]):
222242 parameters ["error" ] = "Executer::do_execute_script::MENU, menu_jump_index out of range: " + str (menu_jump_index ) + " >= " + str (menu_choices .size ())
223243 parameters ["stop" ] = true
0 commit comments