WoofJS
WoofJS copied to clipboard
refresh page for resetting game
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.
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:
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.
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
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 ?
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.
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 .
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.
Just figured @stevekrouse . Thanks for that awesome explanation and patience :smile: Appreciate it, I'll send a PR soon.
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
Appreciate it steve, I'll surely look into it !
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