File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -306,18 +306,21 @@ func _validate_and_run_student_code() -> void:
306
306
# Guard against infinite while loops
307
307
if "while " in script_text :
308
308
var modified_code := PoolStringArray ()
309
+ var guard_counter = 0
309
310
for line in script_text .split ("\n " ):
310
311
if "while " in line and not line .strip_edges (true , false ).begins_with ("#" ):
311
312
var indent := 0
312
313
while line [indent ] == "\t " :
313
314
indent += 1
314
315
315
316
var tabs := "\t " .repeat (indent )
316
- modified_code .append (tabs + "var __guard_counter := 0" )
317
+ var guard_counter_varname = "__guard_counter" + str (guard_counter )
318
+ guard_counter += 1
319
+ modified_code .append (tabs + "var " + guard_counter_varname + " := 0" )
317
320
modified_code .append (line )
318
- modified_code .append (tabs + "\t " + "__guard_counter += 1" )
321
+ modified_code .append (tabs + "\t " + guard_counter_varname + " += 1" )
319
322
modified_code .append (
320
- tabs + "\t " + "if __guard_counter > %s :" % MAX_WHILE_LOOP_ITERATIONS
323
+ tabs + "\t " + "if " + guard_counter_varname + " > %s :" % MAX_WHILE_LOOP_ITERATIONS
321
324
)
322
325
modified_code .append (tabs + "\t\t " + "break" )
323
326
else :
You can’t perform that action at this time.
0 commit comments