Set test values in URL - go to a scene, set variables

Hi all. I have found this little trick to pass data to my game via the URL. I use it in tests to skip to a scene or to set a variable. Note it uses *script.

*create jump_to_scene ""
*script var jump_to_scene=new URLSearchParams(window.location.search).get("scene"); if (jump_to_scene) {this.stats.jump_to_scene = jump_to_scene}

*if jump_to_scene = "<YOUR SCENE>"
  *set <VARIABLES YOU MAY NEED>
  *gosub_scene <YOUR SCENE>

I have tested this locally and on dashingdon. This link, for instance, sets the game size, skipping the initial choice.

https://dashingdon.com/play/sciscidiego/walking-lights/mygame/?scene=6

In order to use it, start with the URL of your game, for example (NOT A REAL LINK):

http://localhost:60564/web/mygame/index.html

then you can add “?scene=somescene” to get (NOT A REAL LINK)

http://localhost:60564/web/mygame/index.html?scene=somescene

With a little more effort, you can pass multiple variables: Javascript does half the job for you already. Let me know if you find it useful.

2 Likes

Links not working for me :slight_smile:

Hi @Charles_Parkes, those were not real links, but only examples on how to use the concept. I updated the post to clarify this, and added a real example.

1 Like

I think I follow now! Might there be there other applications other than the testing scenarios you use it for?

The ability to pass data into the app could be used in a million ways:

  • Low-tech state saving: encode the state in a URL and bookmark it. The app may show something like: to get to this point, use this URL:

URL-to-the-game?state=XXXX

  • You could pass a sequence of choices to get to a particular configuration as a stress test (similar to randomtest, but more specific). → You can write a regression test suite for your app.

  • You could pass an encoded password/signature to unlock additional levels or features (you’d need to obfuscate the code too).

  • Some configuration (language, theme, sound) could be in the URL.

  • You could simplify/skip some part of the game.

In general, you could control anything that can be controlled by an *if statement. :slight_smile:

1 Like

Mind if I ask about one application I’ve been mulling over?

If you had a game with a main character and a ‘buddy’ or friend npc. And you set the main character up normally using a set number of characteristics, that could generate a number string - (9126738349835975340002 that kind of thing)

If you export the string onto the COG forum in a post or direct message, could that string be used to generate the ‘buddy’ in another persons game (assuming all the character characteristics were interpreted in game using a series of *if statements)?

Weirdly specific, I know, but I think it helps me understand the ramifications of what you’ve explored here, if I can apply it to problems I’ve thought about in the past.

Don’t feel you need to respond, the above is interesting enough!

EDIT: Actually - nevermind, I think that’s achievable just with *input_number and coding an interpreter.

Yeah, reasonably sure you can check the value of a specific character in a string. Seen it done and it’s not too complex, but I’d have to check my notes for how to write it out properly.

You could 100% import characters from another person’s game.

1 Like

@Charles_Parkes @will you just made CS games social!! Imagine one person finds the rare Sword of Destiny in a game, they can then share it with their friends. Or they become the rulers of Andalasia, their friends can join there.

mygame.com/?share=SIGNED_SWORD_TOKEN
mygame.com/?realm=SIGNED_ANDALASIA_TOKEN

It would require a lot of code to share and reconstruct the state, but it’s doable (or at least conceivable). @will please share your tips. This reminds me of @stainedofmind password system from a while ago.

1 Like