clarix
October 6, 2018, 10:20pm
1
Hey,
I am wondering if it would be possible to run my game with startparams? My plan is to have a link or GET/POST param when opening a page which includes the html build of my game to prefill variables like a username/nickname. I am open for other ways. My maingoal would be to run the game with a prefilled nickname field.
Does anyone have an idea how to manage this?
best regards,
clarix
Pkeod
October 6, 2018, 11:28pm
2
This is easily possible for GET
If you want to be able to get GET params for whatever reason (such as allowing others to embed your games while changing select config values easily)
myawesomegame.com/embed/?lang=en&show_splash=1
Then you can use something like this
if html5 then
local lang = html5.run("try{(document.URL.match(/lang=([a-z,A-Z])\\w+/)[0]).split('=')[1];}catch(err){}")
local show_splash = html5.run("try{(document.URL.match(/show_splash=([0-9])\\w+/)[0]).split('=')[1];}catch(err){}")
...
end
Maybe a web expert…
For POST params you need your server to digest the POST and embed values into your extra_params
It’s in extra_params with key engine_arguments. Like this:
<script type='text/javascript'>
var extra_params = {
archive_location_filter: function( path ) {
return ("archive" + path + "");
},
splash_image: "splash_image.png",
custom_heap_size: 268435456,
engine_arguments : [
"--config=project.title=Foobar",
"--config=display.width=1000"
]
}
Module.runApp("canvas", extra_params);
/* Fullscreen button */
document.getElementById("fullscreen").onclick = function (e) …
You can also just embed the values you want to get into JS values and get them easily with html5.run(“variable”)
Cookies would be possible too.
1 Like
clarix
October 7, 2018, 12:15am
3
This is just lovely.
Gonna try both solutions tomorrow.
clarix
October 7, 2018, 12:39am
4
I just tried out your first example. As soon as I add the parameter to the url I am getting the following Error in Defold:
java.nio.file.InvalidPathException: Illegal char <?> at index 10: index.html?lang=de
Pkeod
October 7, 2018, 12:44am
5
This is a known issue in the Defold fileserver. If you test with any other fileserver like HFS it will work.
clarix
October 7, 2018, 12:51am
6
I just thought about that. Is there any way I can send console output to the debug console in browsers to quickly test those stuff?
Pkeod
October 7, 2018, 12:57am
7
I think HTML5 console output is current bugged if you do Build->Html5 because it might still be doing a release mode only.
You can try https://www.defold.com/community/projects/76578/
Easiest thing you could do for testing is to manually edit your game.project file and include whatever flags you want for language or game mode that you are currently testing then get with sys.get_config(). This is what I do when testing these kinds of things on Windows builds for example. In my project, I support the game.project method, the extra_params method, and the GET method.
GET supersedes extra_params which supersedes game.project values in my projects.
1 Like
clarix
October 7, 2018, 1:05am
8
Just tested it with my dev webserver. Works like a charm. Thanks alot!
If you use print()
and pprint()
, the output shows up in the debug console.
clarix
October 7, 2018, 8:56pm
10
Did not work for me yesterday on Windows 10/Chrome 69.0.3497.100 and print().
Gonna test ist with pprint() later
What editor version are you using?
Pkeod
October 7, 2018, 9:34pm
12
Debug versions for HTML5 are working for me again in latest. Make sure your editor version is up to date.
clarix
October 7, 2018, 10:15pm
13
I am using the editor 2 - Version 1.2.137
Then it should have worked for you.
I wonder, do you use an .appmanifest?