WoofJS icon indicating copy to clipboard operation
WoofJS copied to clipboard

refresh page for resetting game

Open stevekrouse opened this issue 8 years ago • 11 comments
trafficstars

A common use-case is wanting to provide an option for resetting the game. The reccomended way to do this is by creating a flag gameOver or gamePlaying and check it where relevant, and reset it where relevant.

However, this is complicated. We could give students a reload() primitive that reloads the page and resets the game. We can explain next to this primitive that if you want true resetting, you need to do the flag thing.

stevekrouse avatar May 01 '17 16:05 stevekrouse

So this option basically clears all the stuff in the code block and we are directed to a fresh create.html ? I'll work on this fix as soon as i know exactly what it to be done. Share me the details @stevekrouse :smile:

anshumanv avatar May 15 '17 05:05 anshumanv

My thought was that the reload() primitive (maybe we call it reset()) would simply reload the game page iframe (not the entire create.html page) by calling this: https://www.w3schools.com/jsref/met_loc_reload.asp

So this would be a helper method added to the end of src/woofjs.es6.js and added to the bottom of the Control menu in the documentation.

stevekrouse avatar May 16 '17 16:05 stevekrouse

As far as i get, what it does is somewhat clear the 'CODE' iframe and reset it to the initial new project code which is something like (.setBackDropURL). Do let me know your views on this @stevekrouse

anshumanv avatar May 17 '17 06:05 anshumanv

If the above deduction is correct we can simply replace all the stuff in CODE iframe and set it to the initial new project code, that would be just a minor JS function to replace some piece of text, won't it ?

anshumanv avatar May 17 '17 06:05 anshumanv

Hey @Anshuman-Verma I think we're talking past each other here. This reload() function will be a WoofJS function you can use to reload the page. If you're on create.html this will reload the Preview tab. If you're looking at a game in full screen, it will reload the entire page. This will not affect the Code tab.

stevekrouse avatar May 18 '17 17:05 stevekrouse

But since we already have a 'Reset' button on the preview iframe so what good will this new function do since we don't want any changes elsewhere, can u clear the application/usage for this reload() function please @stevekrouse .

anshumanv avatar May 18 '17 17:05 anshumanv

Ah, I see why you're confused. Maybe re-read my description of this function at the top of this issue.

This function is so that the programmer can have the game reset via code. This makes more sense for when the game is in full screen. Imagine a kid sharing a game they made with a friend in full screen where they don't have the reset button. Sure, they could just reload the page to get the game to reset, but this is making that workflow slightly easier.

For example, the programmer could add a "Reset" button in their game and the user can press it and it would reload the page.

stevekrouse avatar May 18 '17 17:05 stevekrouse

Just figured @stevekrouse . Thanks for that awesome explanation and patience :smile: Appreciate it, I'll send a PR soon.

anshumanv avatar May 18 '17 17:05 anshumanv

As a heads up, you're going to need to add this to the woofjs core library so here's how to do that...

https://github.com/stevekrouse/WoofJS#woofjs-core-library

stevekrouse avatar May 18 '17 17:05 stevekrouse

Appreciate it steve, I'll surely look into it !

anshumanv avatar May 18 '17 17:05 anshumanv

history.go(0);

The History interface allows manipulation of the browser session history , that is the pages visited in the tab or frame that the current page is loaded in.

There are multiple ways to Refresh/Reload a page with jQuery/JavaScript, some are:

  • location.href = location.href
  • location.replace(location.pathname)
  • window.location = window.location
  • window.self.window.self.window.window.location = window.location

linehammer avatar Sep 07 '20 04:09 linehammer