cómo alternar entre dos funciones automáticamente sin botón
Sep 23 2020
Quiero alternar entre anuncios intersticiales y anuncios de video recompensados en mi juego html, utilícelo en la construcción 2 cada vez que cargue el diseño, como si el primer tiempo de ejecución muestre intersticial y si se carga nuevamente, muestre anuncios de video recompensados y repita esto cada vez.
SysActs.prototype.GoToLayout = function(to) {
showInterstitialAd();
showRewardedVideoAd();
if (this.runtime.isloading)
return; // cannot change layout while loading on loader layout
if (this.runtime.changelayout)
return; // already changing to a different layout
;
this.runtime.changelayout = to;
};
mi código de prueba después de alternar entre dos funciones automáticamente
SysActs.prototype.GoToLayout = function (to)
{
if($(this).data('toggleAds') == 1) { toggleAds = 0; if (this.runtime.isloading || showRewardedVideoAd()) return; if (this.runtime.changelayout ) return; ; this.runtime.changelayout = to; } else { toggleAds = 1; if (this.runtime.isloading || showInterstitialAd() ) return; if (this.runtime.changelayout ) return; ; this.runtime.changelayout = to; showInterstitialAd(); } $(this).data('toggleAds', toggleAds);
return false;
};
Intento esto pero no funciona?
Respuestas
1 JeremyThille Sep 23 2020 at 14:02
No funciona porque no persiste nada en la recarga de la página, por lo que obtiene exactamente la misma página y el mismo código, por lo que el comportamiento es exactamente el mismo. No puede alternar de esta manera. Almacene un estado en localStorage y léalo al cargar la página.
const previousState = localStorage.getItem("state"); // null, "interstitial" or "rewarded"
let currentState;
if(previousState){
currentState = previousState === "interstitial" ? "rewarded" : "interstitial";
} else { // First page load ever
currentState = "rewarded"; // or "interstitial", initialize it like you want
}
localStorage.setItem("previousState", currentState); // It's saved for next reload
// Now do something with currentState