MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / find_variable

Method find_variable

scratchattach/editor/sprite.py:411–438  ·  view source on GitHub ↗
(self, value: str, by: str = "name", multiple: bool = False)

Source from the content-addressed store, hash-verified

409 return None
410
411 def find_variable(self, value: str, by: str = "name", multiple: bool = False) -> None | vlb.Variable | list[vlb.Variable]:
412 _ret = []
413 by = by.lower()
414 for _variable in self.variables + self._local_globals:
415 if not isinstance(_variable, vlb.Variable):
416 continue
417
418 if by == "id":
419 compare = _variable.id
420 else:
421 # Defaulting
422 compare = _variable.name
423 if compare == value:
424 if multiple:
425 _ret.append(_variable)
426 else:
427 return _variable
428 # Search in stage for global variables
429 if self.project:
430 if not self.is_stage:
431 if multiple:
432 _ret += self.stage.find_variable(value, by, True)
433 else:
434 return self.stage.find_variable(value, by)
435
436 if multiple:
437 return _ret
438 return None
439
440 def find_list(self, value: str, by: str = "name", multiple: bool = False) -> None | vlb.List | list[vlb.List]:
441 _ret = []

Callers 2

find_vlbMethod · 0.95
link_using_spriteMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected