How to use url paramater arguments for builds

E.g. I know we can do some stuff with the url by putting ?gizmos at the end of the url. Can we do anything like ?clampresolution to pass that as a value to a script in the build to clamp the resolution to 1920x1080 for a build?

Also would this even work on a local server running build from Local Server in VS Code for example?

Mainly asking as my first project with Needle is going live soon and the client has a 4k screen they want to run it on but they might want to clamp the build resolution in browser to 1920x1080 or switch back. I know I can do two different builds for this otherwise but doing it in 1 would be nice.

Original Post on Discord

by user 103054507105067008

Yes you can add that easily!

You already have the settings for setting the resolution scale etc right?

You can use the getParam("parameterName") utility method.

Here is a code snipped:

import { getParam } from "@needle-tools/engine/engine/engine_utils";

const testParamValue = getParam("test");
console.log("TestParam is:", testParamValue)

getParam returns a boolean when the param is just present or not and otherwise the string value.

E.g. &test=hellorob will print “hellorob” while &test will print true

That’s perfect!

by user 103054507105067008

The same utils file also contains nice helpers like setParamWithoutReload if you ever need that

which is great for doing stuff like configuration UIs where you want to be able to send the configured state to someone else as part of the URL

Taking a look at that for sure, gives me peace of mind as I can provide a client some more control or for presentations where I might want to make quick tweaks

by user 103054507105067008

We use it for the room name for example :slightly_smiling_face:

Real quick on this, trying to send through a boolean in the param via ?is4k=true

        const testParamValue = getParam("is4k");
        console.log("Is 4k:", testParamValue)
        if(testParamValue != null)
        this.capRes = testParamValue as Boolean;
        console.log("capres: " + this.capRes);

The boolean value doesn’t seem to be set properly, am I doing something wrong?

by user 103054507105067008

Capres is: private capRes?: Boolean;

by user 103054507105067008

** query params are always a string if assigned** - you have to parse it yourself if you expect a boolean. You usually see params containing 0 and 1 for that reason since they by default evaluate to “true or false”

So you need to check if the “testParamValue” variable === “true” if you want to go that route

Or you do “is4k=1”

Thanks, 1 or 0 was easy

by user 103054507105067008