Passing a parameter to HTML5 engine

All about the StoneScript

Passing a parameter to HTML5 engine

Postby VLens » 2017-11-23 16:43

Hello everyone,

I'm looking for a way to pass a parameter to the HTML5 engine.

For example, the game is running from www.example.com/myShivagame.php

Another application generates a user ID, and opens the site with a GET parameter like: www.example.com/myShivagame.php?user=111

Is there a way to get this user ID from the engine?

Thanks,
V
VLens
Expert Boarder
Expert Boarder
 
Posts: 86
Joined: 2010-03-03 16:32
Location: Hungary

Re: Passing a parameter to HTML5 engine

Postby VLens » 2017-11-23 18:56

Okay, i found this thread, it seems doable in javascript:

http://www.shiva-engine.com/shiva-html5-javascript-interaction/
VLens
Expert Boarder
Expert Boarder
 
Posts: 86
Joined: 2010-03-03 16:32
Location: Hungary

Re: Passing a parameter to HTML5 engine

Postby broozar » 2017-11-24 12:35

exactly. let me know if you have any questions on the tutorial, or suggestions.
User avatar
broozar
Administrator
Administrator
 
Posts: 4101
Joined: 2007-09-16 10:22
Location: Berlin - Germany

Re: Passing a parameter to HTML5 engine

Postby VLens » 2017-11-24 18:36

Thanks broozar, but it's actually quite easy after following that tutorial.

If someone needs it, here is my quick&dirty javascript implementation:

Code: Select all
// This function reads the GET variables from the URL
   function getURIVars () {
      var $_GET = {},
         args = location.search.substr(1).split(/&/);
      for (var i=0; i<args.length; ++i) {
         var tmp = args[i].split(/=/);
         if (tmp[0] != "") {
            $_GET[decodeURIComponent(tmp[0])] = decodeURIComponent(tmp.slice(1).join("").replace("+", " "));
         }
      }
      return $_GET;
   }

// The initBridge is called from Shiva when the engine starts.
   function initBridge() {
      shiva_user_event_args_clear = Module.cwrap ( 'shiva_user_event_args_clear', 'number' ) ;
      shiva_user_event_args_push_number = Module.cwrap ( 'shiva_user_event_args_push_number', 'number', ['number'] ) ;
      shiva_user_event_args_push_string = Module.cwrap ( 'shiva_user_event_args_push_string', 'number', ['string'] ) ;
      shiva_user_event_args_push_boolean = Module.cwrap ( 'shiva_user_event_args_push_boolean', 'number', ['number'] ) ;
      shiva_user_event_send = Module.cwrap ( 'shiva_user_event_send', 'number', ['string', 'string'] ) ;
      document.getElementById ( 'shivafocus' ).focus();
      var aVars = getURIVars ();
      sendToShiva ( aVars );
   }

// Pass the GET values back to Shiva
    function sendToShiva (aVars) {
      // - clear arguments list
        shiva_user_event_args_clear ( ) ;
      // - push argument(s)
      var i;
      for (i in aVars) {
         var sVar = aVars[i];
         shiva_user_event_args_push_string ( sVar );
      }
      // - send event to the specified AI and handler
        shiva_user_event_send ( 'AIMain_Caching', 'onJSInterface' ) ;
        returnFocusToShiva();
    }
VLens
Expert Boarder
Expert Boarder
 
Posts: 86
Joined: 2010-03-03 16:32
Location: Hungary


Return to Game programming

Who is online

Users browsing this forum: No registered users and 15 guests

cron