All was looking do something I have no clue on lol


#1

Ok this is an area I have very little understanding. This is what I would like to do.
At a certain piont in the game the pc is handed blueprints, theses are important. Now can I make a new stat button showup at this time. From the stat they can flip through the blueprints. I figure I am reaching to far. The other thought is perhaps add a button that will open small new window that I have linked to my website that I can use simple html and javascript to allow the player to flip through the blueprints.


#2

Yes, you can make a hidden button in the index.html file and unhide it with j/s when required.

At least that’s the theory.
The difficult bit is defining an event for unhiding the button in javascript, since from personal experience “onload=” doesn’t work too well and choicescript never loads a new page, it just changes the content displayed on the same one.

You could have a ‘refresh’ button that will act as a trigger making a new button appear if a condition is true when pressed (which you can set in c/s), but that’s probably not ideal. I’ll let you know if I find a way of checking the variable more often.


#3

So if I make ‘blueprint’ flase then they receive the blueprints turn it true I have it refresh to show the new button?


#4

In index.html have your hidden button:
<button id="blue_prints" onclick="showBluePrintsPage()" style="display:none;"</button>

^See the multi stat page thread for how to make the page/I’m assuming you already have one

Then in mygame.js
function showblueprintbutton() { if (stats.blueprints == true) { document.getElementById("blue_prints").style.display = "inline"; }

All you need on top of that is an EVENT that calls showblueprintbutton()


#5

Thanks will try it out today.


#6

@CJW and @Lordirish, to call the showblueprintbutton() function as in your example, I think you can call it from the CS code when it is most appropriate for the button to appear. I can’t verify the code right now (and I’m leaving soon for a 4-day trip), but I believe the *script command is enabled by default, so you should be able to enter the following at the appropriate place in your CS file:


*script showblueprintbutton()


#7

If that is the case, then my hat off to you sir, I can’t express how much of a pet hate that has become of mine. I’ll check it out when I get home.

Just opened scene.js on my phone and damn, it is so!
Kudos my friend… I’ll have to look into that some more, :smiley:


#8

And if that works, you could also have a function and a corresponding *script command that hides the button when they lose the blueprints!


#9

That helps a lot thank you and for giving me an evil… I mean good idea.


#10

Ok I can follow some of what is going on but can anybody kinda walk me through where to put the code and what it should look like thanks. Lol not feeling so bright since I started this coding stuff.


#11

Ok ^^’

Index.html

  1. Find:

<p><button id="statsButton" onclick="showStats()">Show Stats</button></p>

  1. Replace with:
    <p><button id="statsButton" onclick="showStats()">Show Stats</button> <button style="display:none;" id="blueprintsButton" onclick="showBlueprints()">Show Blue Prints</button></p>

^The display:none; makes sure the button is hidden when the game is first loaded.

ui.js

  1. Find:

`function showStats() {
if (window.showingStatsAlready) return;
window.showingStatsAlready = true;
document.getElementById(“statsButton”).style.display = “none”;
main.innerHTML = “

”;
var currentScene = window.stats.scene;

var scene = new Scene("choicescript_stats", window.stats, this.nav);
scene.save = function(callback) {if (callback) callback.call(scene);}; // Don't save state in stats screen, issue #70
// TODO ban *choice/*page_break/etc. in stats screen
scene.finish = scene.autofinish = function(buttonName) {
  this.finished = true;
  this.paragraph();
  var p = document.createElement("p");
  var restartLink = document.createElement("a");
  restartLink.setAttribute("style", "text-decoration: underline; cursor: pointer; text-align: left");
  restartLink.onclick = function() {
      if (window.confirm("Restart your game?  Did you click that intentionally?")) {
          window.showingStatsAlready = false;
          document.getElementById("statsButton").style.display = "inline";
          clearCookie(function() {
            window.nav.resetStats(window.stats);
            clearScreen(restoreGame);
          }, "");
      }
      return false;
  }
  restartLink.innerHTML = "Start Over from the Beginning";  
  p.appendChild(restartLink);
  var text = document.getElementById('text');
  text.appendChild(p);

  printButton(buttonName || "Fat", main, false, function() {
      window.stats.scene = currentScene;
      window.showingStatsAlready = false;
      document.getElementById("statsButton").style.display = "inline";
      clearScreen(loadAndRestoreGame);
  });
}
scene.execute();

}`

  1. Copy and paste the above below - so you have two copies of the same code in the same file.

  2. Change the following lines in ONE of the blocks of code, it doesn’t matter which one:

function showStats()
With
function showBlueprints()

document.getElementById("statsButton").style.display = "none";
With
document.getElementById("blueprintsButton").style.display = "none";

var scene = new Scene("choicescript_stats", window.stats, this.nav);
With
var scene = new Scene("blue_prints", window.stats, this.nav);

document.getElementById("statsButton").style.display = "inline";
With
document.getElementById("blueprintsButton").style.display = "none";

^The change to none is important, as you don’t want this particular button to appear if someone restarts their game/this is inside the function call for restart.

Same again with the final instance:
document.getElementById("statsButton").style.display = "inline";
With
document.getElementById("blueprintsButton").style.display = "none";

blue_prints.txt

Create a file with this name inside /scenes/

mygame.js

  1. Create a new stat variable:

,blueprints_found: false

  1. Create the hide/unhide function right at the bottom/below everything in the mygame.js file:

`
function checkblueprints() {

if (stats.blueprints_found == true)
{
document.getElementById(“blueprintsButton”).style.display = “inline”;
}
else
{
document.getElementById(“blueprintsButton”).style.display = “none”;
}
}
`

^This function, when called, will show the button if our created variable has been set to true and hide it if it is false.


FINAL STEP

Use:
*set blueprints_found true *script checkblueprints()

To make the button appear

Or:
*set blueprints_found false *script checkblueprints()

To make the button disappear, anywhere in your choicescript scenes.

…I don’t think I missed anything, if you need more elaboration let me know ^^’


#12

@CJW
You my friend ROCK, I will try this out tonight. Thank you very much. :slight_smile:


#13

Hey, no problem ^^
Let me know how it goes!