Results 1 to 1 of 1

Thread: [Bug] Scripts not loaded when loading in an included javascript file

  1. #1
    Basic Member AgentP's Avatar
    Join Date
    Jul 2015
    Posts
    15

    [Bug] Scripts not loaded when loading layout in an included javascript file

    I was trying to set up a nice way modularise my UI and found an interesting way of making modules very similar to OOP in the following way:
    XML:
    Code:
    <root>
    	<script>
    		(function(){ 
                            $.Msg('Setting up module.');
    			var module = $('#PlayerAvatar').GetParent();
    			module.someMethod = function() {
    				$.Msg('Hello world!');
    			}
    		})();
    	</script>
    
    	<Panel class="TeamSelectPlayer">
    		<DOTAAvatarImage id="PlayerAvatar" />
    		<Label id="PlayerIsHostPanel" />
    	</Panel>
    </root>
    This allowed me to call this from another file like this:
    Code:
    <script>
    		(function() {
    			var newPanel = $.CreatePanel( "Panel", $('#unassignedTeam'), "player_root" );
    			newPanel.BLoadLayout( "file://{resources}/layout/custom_game/Modules/PlayerAvatar.xml", false, false );
    			
    			newPanel.someMethod();
    		})();	
    </script>
    Now this little prototype works fine. The problem occurred once I started refactoring this. I moved the function that spawns the panel to a different javascript file that I include at the top of the file and call it like so:
    Code:
    <root>
    	<scripts>
    		<include src="file://{resources}/scripts/custom_game/Modules.js" />
    	</scripts>
    
    	<script>
    		(function() {
    			var newPanel = spawn( $('#unassignedTeam') );
    			
    			newPanel.someMethod();
    		})();
    ...
    In Modules.js I have the following code, which should be identical to what I had before just in a different place:
    Code:
    function spawn( parent ) {
    	var newPanel = $.CreatePanel( "Panel", parent, "player_root" );
    	newPanel.BLoadLayout( "file://{resources}/layout/custom_game/Modules/PlayerAvatar.xml", false, false );
    	return newPanel;
    }
    When moving the call to .BLoadLayout suddenly any scripts in PlayerAvatar.xml are not loaded anymore at all, not in the <scripts> block or anything in a regular <script> block. This does not seem like intended behaviour to me as the code is identical, just moved to a different file.
    Last edited by AgentP; 07-09-2015 at 12:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •