How to get application start parameters in HTML5 (SOLVED)

I’m doing app for social network. and my app started in iframe window.
Source page pass parameter to that window like user_id, session and another parameters something like
.../my_game.html?user_id=XXXX&session_id=XXXXX
And I’m intersting how can i read that parameters in the game.

thanks.

1 Like

parse in js and pass in extra_params ?

1 Like

and how to get them in defold ?

You can pass config key-value pairs and read them with sys.get_config(). See:

and

1 Like

sims like i’m doing something wrong.
in index.html template I added following lines

var extra_params = {
			archive_location_filter: function( path ) {
				return ("{{DEFOLD_ARCHIVE_LOCATION_PREFIX}}" + path + "{{DEFOLD_ARCHIVE_LOCATION_SUFFIX}}");
			},
            {{#HAS_DEFOLD_ENGINE_ARGUMENTS}}
			engine_arguments: ["{{DEFOLD_ENGINE_ARGUMENTS}} --config=test_param=111333"],
			{{/HAS_DEFOLD_ENGINE_ARGUMENTS}}
			splash_image: "{{DEFOLD_SPLASH_IMAGE}}",
			custom_heap_size: {{DEFOLD_HEAP_SIZE}}
		}

–config=test_param=111333

and then in the script trying to get this value

print(sys.get_config("test_param"))

but result is nil

thanks i solved the issue.
So here is how to do that
1 In game.project defined new section and variable (not sure if it’s mandatory or not). (upd: Add this only if you need default value)

[test] value = 5555555

2 In index.html template instead of one string parameter you need to make an array with string parameters

that’s it.

thanks again!

upd. this is the whole section which i use

	<script type='text/javascript'>
      var engine_args = []
      {{#HAS_DEFOLD_ENGINE_ARGUMENTS}}
      engine_args.push("{{DEFOLD_ENGINE_ARGUMENTS}}")
      {{/HAS_DEFOLD_ENGINE_ARGUMENTS}}
      var url_params = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
      for(var i = 0; i < url_params.length; i++)
         {
           var new_arg = "--config=url.".concat(url_params[i])
           engine_args.push(new_arg);
         }
      var extra_params = {
        archive_location_filter: function( path ) {
          return ("{{DEFOLD_ARCHIVE_LOCATION_PREFIX}}" + path + "{{DEFOLD_ARCHIVE_LOCATION_SUFFIX}}");
        },
        engine_arguments: engine_args,
        splash_image: "{{DEFOLD_SPLASH_IMAGE}}",
        custom_heap_size: {{DEFOLD_HEAP_SIZE}}
      }

      Module.runApp("canvas", extra_params);

	    /* Fullscreen button */
	    document.getElementById("fullscreen").onclick = function (e) {
	      Module.toggleFullscreen();
	    };
	</script>

and then in lua you can use
sys.get_config("url.your_param_here")

7 Likes

Cool. You don’t need to add anything to the game.project settings btw.

2 Likes