Published HTML5 acting different than localhost test

0 favourites
  • 7 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hi

    I'm working on another plugin, but struggling to find out why the code is acting different when it's published to a website, over running on localhost test.

    I got this JS/jQuery code, that perfectly works when i'm testing, but not when i've exported the project.

    jQuery.each(self.response.results[0].address_components, function () {
    	var component = jQuery(this)[0];
    	jQuery.each(component.types, function () {
    	    console.log(jQuery(this));
    	    switch (jQuery(this).selector) {
    	        case 'street_number':
    	            self.data.street_number = component.long_name;
    	            break;
    
    	        case 'route':
    	            self.data.street = component.long_name;
    	            break;
    
    	        case 'locality':
    	            self.data.city = component.long_name;
    	            break;
    
    	        case 'administrative_area_level_1':
    	            self.data.state = component.long_name;
    	            break;
    
    	        case 'administrative_area_level_2':
    	            self.data.county = component.long_name;
    	            break;
    
    	        case 'country':
    	            self.data.country = component.long_name;
    	            break;
    
    	        case 'postal_code':
    	            self.data.postal_code = component.long_name;
    	    }
    	});
    });[/code:35hglc6l]
    
    The console.log will output the following on test (correct):
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    Object[]
    
    Where the Object selectors will have some value.
    But the exported project will output this:
    Object["s", "t", "r", "e", "e", "t", "_", "n", "u", "m", "b", "e", "r"]
    Object["r", "o", "u", "t", "e"]
    Object["l", "o", "c", "a", "l", "i", "t", "y"]
    Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
    Object["a", "d", "m", "i", "n", "i", "s", "t", "r", "a", "t", "i", "v", "e", "_", "a", "r", "e", "a", "_", "l", "e", "v", "e", "l", "_", "2"]
    Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
    Object["c", "o", "u", "n", "t", "r", "y"]
    Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
    Object["p", "o", "s", "t", "a", "l", "_", "c", "o", "d", "e"]
    Object["s", "t", "r", "e", "e", "t", "_", "n", "u", "m", "b", "e", "r"]
    Object["r", "o", "u", "t", "e"]
    Object["l", "o", "c", "a", "l", "i", "t", "y"]
    Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
    Object["a", "d", "m", "i", "n", "i", "s", "t", "r", "a", "t", "i", "v", "e", "_", "a", "r", "e", "a", "_", "l", "e", "v", "e", "l", "_", "2"]
    Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
    Object["c", "o", "u", "n", "t", "r", "y"]
    Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
    Object["p", "o", "s", "t", "a", "l", "_", "c", "o", "d", "e"]
    
    Why is this so ? Please help me. 
    
    -Acey
  • It's probably broken by the minifier - see the section on Closure Compiler in the SDK docs: https://www.scirra.com/manual/22/runtime-overview

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's probably broken by the minifier - see the section on Closure Compiler in the SDK docs: https://www.scirra.com/manual/22/runtime-overview

    That seems pretty true for now, i've reworked the code to work without minifying, but how to i then oprimize it to work with minifying too, i think it's an cap for my plugins to say that people can't export with minifying if they use it.

    EDIT:

    TypeError: f.response.N is undefined is the error i get, when running here:

    http://demo.acey.io/C2/LocationInfo/

    I guess this comes from a try, catch i have, where the FOR loops are in.

    for(var componentIndex in self.response.results[0].address_components)
    {
    	var component = self.response.results[0].address_components[componentIndex]
    	console.log(component);
    	for (var typeIndex in component.types) {
    	    switch (component.types[typeIndex]) {
    	        case 'street_number':
    	            self.data.street_number = component.long_name;
    	            break;
    
    	        case 'route':
    	            self.data.street = component.long_name;
    	            break;
    
    	        case 'locality':
    	            self.data.city = component.long_name;
    	            break;
    
    	        case 'administrative_area_level_1':
    	            self.data.state = component.long_name;
    	            break;
    
    	        case 'administrative_area_level_2':
    	            self.data.county = component.long_name;
    	            break;
    
    	        case 'country':
    	            self.data.country = component.long_name;
    	            break;
    
    	        case 'postal_code':
    	            self.data.postal_code = component.long_name;
    	    }
    	}
    }[/code:3iu4v7uy]
  • There are 2 ways to name the property (variable or function name) in an object-

    1. obj.name

    2. obj["name"]

    After exporting with minify, property name in Method 1 might be changed to obj.a, name in Method 2 will become obj.name. So uses Method 2 to keep the property name unchanged after minify.

  • So your suggestion would be to always use method 2 ? If i understand correctly ?

  • No, most of my property names uses method 1, only the names which I don't want to be changed uses method2.

    For example, you put an external library into your plugin, call the functions provided by this library, then uses method2 to keep the name of function call unchanged.

  • rexrainbow Thanks for the explanation, after playing a little with it, i found out what you meant, and now i know the difference, thank you

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)