def run_script(self, script_api, engine, callback = lambda: None): """ Runs the current script in the player_scripts folder in a seperate thread. Exposes the script_api to the script that is run. Parameters ---------- script_api : dict A dictionary from object names to their instances #TODO: explain this a bit more clearly """ if not(self.is_running_script()): #only run script if one currently isn't running. self.set_running_script_status(True) scriptrunner.start(script_api, engine.get_run_script(), self, engine, callback = callback) return
def run_script(self, script_api, engine, callback=lambda: None): """ Runs the current script in the player_scripts folder in a seperate thread. Exposes the script_api to the script that is run. Parameters ---------- script_api : dict A dictionary from object names to their instances #TODO: explain this a bit more clearly """ if not (self.is_running_script() ): #only run script if one currently isn't running. self.set_running_script_status(True) scriptrunner.start(script_api, engine.get_run_script(), self, engine, callback=callback) return
def run_script(self, script_to_run=-1, parse_error=True, callback=lambda: None): """ Runs the current script in the player_scripts folder in a seperate thread. Exposes the PyGuide API to the script to allow it to control this player. Everything in the API is bocking, however this doesn't impact regular gameplay as it's run in a seperate thread. Parameters ---------- script_to_run : int, optional A flag that indicates which script to run. -1 indicates the current script parse_error : bool, optional #TODOFILL THIS callback : func, optional Places the callback onto the engine event-queue """ engine = self.get_engine() if not (self.is_running_script() ): #only run script if one currently isn't running. if (script_to_run == -1): script_to_run = engine.get_run_script() self.set_running_script_status(True) #script_api is a python dictionary of python objects (variables, methods, class instances etc.) #available to the player. :) #eg. if there is an entry named "fart" whos entry is blob, then in the level script, any reference to fart #will be refering to what blob is known as here. #Here the list of game_objects is being looped through, and their names are being mapped to each instance :) script_api = {} # Provide all the movement functions to the player, but make them blocking. script_api["move_north"] = scriptrunner.make_blocking( self.move_north) script_api["move_east"] = scriptrunner.make_blocking( self.move_east) script_api["move_south"] = scriptrunner.make_blocking( self.move_south) script_api["move_west"] = scriptrunner.make_blocking( self.move_west) script_api["face_north"] = scriptrunner.make_blocking( self.face_north) script_api["face_east"] = scriptrunner.make_blocking( self.face_east) script_api["face_south"] = scriptrunner.make_blocking( self.face_south) script_api["face_west"] = scriptrunner.make_blocking( self.face_west) script_api["turn_left"] = scriptrunner.make_blocking( self.__turn_left) script_api["turn_right"] = scriptrunner.make_blocking( self.__turn_right) script_api["can_move"] = self.__can_move script_api["move"] = scriptrunner.make_blocking(self.__move) script_api["scan"] = self.__scan script_api["wait"] = scriptrunner.make_blocking( lambda callback: self.wait(0.3, callback)) #the method to get the position of the player script_api["get_position"] = self.get_position script_api["yell"] = self.yell script_api["cut"] = scriptrunner.make_blocking(self.__cut) script_api["get_cuts_left"] = self.__get_cuts_left script_api["dig"] = self.dig scriptrunner.start(script_api, script_to_run, self, engine, parse_error, callback) return
def run_script(self, script_to_run = -1, parse_error = True, callback = lambda: None): """ Runs the current script in the player_scripts folder in a seperate thread. Exposes the PyGuide API to the script to allow it to control this player. Everything in the API is bocking, however this doesn't impact regular gameplay as it's run in a seperate thread. Parameters ---------- script_to_run : int, optional A flag that indicates which script to run. -1 indicates the current script parse_error : bool, optional #TODOFILL THIS callback : func, optional Places the callback onto the engine event-queue """ engine = self.get_engine() if not(self.is_running_script()): #only run script if one currently isn't running. if (script_to_run == -1): script_to_run = engine.get_run_script() self.set_running_script_status(True) #script_api is a python dictionary of python objects (variables, methods, class instances etc.) #available to the player. :) #eg. if there is an entry named "fart" whos entry is blob, then in the level script, any reference to fart #will be refering to what blob is known as here. #Here the list of game_objects is being looped through, and their names are being mapped to each instance :) script_api = {} # Provide all the movement functions to the player, but make them blocking. script_api["move_north"] = scriptrunner.make_blocking(self.move_north) script_api["move_east"] = scriptrunner.make_blocking(self.move_east) script_api["move_south"] = scriptrunner.make_blocking(self.move_south) script_api["move_west"] = scriptrunner.make_blocking(self.move_west) script_api["face_north"] = scriptrunner.make_blocking(self.face_north) script_api["face_east"] = scriptrunner.make_blocking(self.face_east) script_api["face_south"] = scriptrunner.make_blocking(self.face_south) script_api["face_west"] = scriptrunner.make_blocking(self.face_west) script_api["turn_left"] = scriptrunner.make_blocking(self.__turn_left) script_api["turn_right"] = scriptrunner.make_blocking(self.__turn_right) script_api["can_move"] = self.__can_move script_api["move"] = scriptrunner.make_blocking(self.__move) script_api["scan"] = self.__scan script_api["wait"] = scriptrunner.make_blocking(lambda callback: self.wait(0.3, callback)) #the method to get the position of the player script_api["get_position"] = self.get_position script_api["yell"] = self.yell script_api["cut"] = scriptrunner.make_blocking(self.__cut) script_api["get_cuts_left"] = self.__get_cuts_left script_api["dig"] = self.dig scriptrunner.start(script_api, script_to_run, self, engine, parse_error, callback) return