How to Add a Stat Bar to Your Game


#1

Here’s how to add a stat bar to your game:

  1. Open your game’s index.html file in a text editor. (It’s the index.html file inside the web/mygame folder.)

  2. Find this:[code]

[/code]
  1. Insert a new line above this line that says this:[code]
 
[/code]
  1. Open web/mygame/mygame.js in your text editor.

  2. Add the following code to the bottom:

function updateStatBar() {
    document.getElementById("quickstats").innerHTML = "Health: "+stats["cur_health"]+"/"+stats["max_health"]+"   •   Self-Esteem: "+stats["esteem"]+"/100   •   Rations Left: "+stats["food"];
}
  1. Modify the code in step 5 to reflect your stats.

  2. In your game, whenever you want to update the stat bar (for example, initially, at the beginning of the game and any time a stat is changed), put: *script updateStatBar();

That’s it!


#2

This is interesting, but this wouldn’t be supported.


#3

@Gantron’s WIP somehow had it. What do you mean by not supported, it wouldn’t translate to app form once handed in to COG?


#4

I just mean that anything that uses *script they can’t officially support, since you can put just about anything in there and it may or may not cause problems with the game.


#5

To my understanding, Dan has to actually do some back end work on every game that gets posted to the appstores and everywhere else (I’m not sure what all goes into it, I just know it’s more than copy/paste). So adding JavaScript (which is what *script does) means, at the very best, your game is perpetually stuck at the bottom of the list of games to host, while at the worst, if it’s too difficult to do on the other platforms, HG won’t host it.

If you’re just making a WIP cause you want to and have no plan to ever get it hosted by CoG, it’s one thing, but if you do what to eventually make some money back on your game, it’s best to skip *script.


#6

Thank you for clarifying.