Adventure Creator original thread

Tips, techniques and tutorials about creation tools.

Re: Adventure Creator main thread

Postby tlaero » Fri, 13Dec27 19:05

Thanks Wolf. I agree with everything you said. I'd use a switch statement for the days, but the ifs work too. The best way to do it, though, is to have an array of day names and index it with the day variable. It's important to know that the first entry in the array is index 0, not 1.

Code: Select all
var dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var day;  //must range from 0 to 6
var dayName;

day = 3; // Wednesday;
dayName = dayOfWeek[day];


Subtracting 7 in a while loop is good, but the modulus operator (%) is better. Modulus is the remainder of a division. So
14 % 7 = 0
15 % 7 = 1
5 % 7 = 5
9 % 7 = 2
Etc.

Adding the mod above makes it look like this:

Code: Select all
var dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var day;  // Sunday is 0, Saturday is 6
var dayName;

day = 10; // Wednesday;
dayName = dayOfWeek[day % 7];


Tlaero
User avatar
tlaero
Lady Tlaero, games and coding expert
 
Posts: 1829
Joined: Thu, 09Jun04 23:00
sex: Female

Re: Adventure Creator main thread

Postby Dakutis » Sat, 13Dec28 07:41

tlaero wrote:
Code: Select all
var dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var day;  // Sunday is 0, Saturday is 6
var dayName;

day = 10; // Wednesday;
dayName = dayOfWeek[day % 7];


Tlaero


This is working thanks.
And other question is about stats page, maybe you can explain me more about that. I need to put there some of stats and save load function.
I write this:
Code: Select all
    var inStats = readVar(gInStats);

    var numSetAchieves = CountSetAchieves();
    var numMaxAchieves = CountMaxAchieves();

    var gotoStats = "<br/><a onclick=\"GotoStatsPage('_stats.htm');\" href='#'>Go to Stats Page</a> ";
    var stats = "You've earned " + score10 + " out of " + var score11 + " Achievements.";

    if (inStats == 0)
    {
        outputScoreString(str + gotoStats);
    }
    else
    {
        outputScoreString(stats);
    }

in my _game.js function gameShowTopScore() and now game don't start.
http://dakutisgames.weebly.com/
User avatar
Dakutis
lagoon predator
 
Posts: 116
Joined: Wed, 12Nov07 14:17
Location: Lithuania, Kaunas
sex: Masculine

Re: Adventure Creator main thread

Postby tlaero » Sat, 13Dec28 21:04

check this line:

var stats = "You've earned " + score10 + " out of " + var score11 + " Achievements.";

You've got an extra "var" before score11.

If you remove that, does it work?

Tlaero
User avatar
tlaero
Lady Tlaero, games and coding expert
 
Posts: 1829
Joined: Thu, 09Jun04 23:00
sex: Female

Re: Adventure Creator main thread

Postby Dakutis » Sun, 13Dec29 07:16

tlaero wrote:check this line:

var stats = "You've earned " + score10 + " out of " + var score11 + " Achievements.";

You've got an extra "var" before score11.

If you remove that, does it work?

Tlaero


No, it does not.
http://dakutisgames.weebly.com/
User avatar
Dakutis
lagoon predator
 
Posts: 116
Joined: Wed, 12Nov07 14:17
Location: Lithuania, Kaunas
sex: Masculine

Re: Adventure Creator main thread

Postby tlaero » Sun, 13Dec29 08:39

What have you tried so far?

Wait, you don't have a str.
outputScoreString(str + gotoStats);

You never defined str.

Tlaero
User avatar
tlaero
Lady Tlaero, games and coding expert
 
Posts: 1829
Joined: Thu, 09Jun04 23:00
sex: Female

Re: Adventure Creator main thread

Postby Dakutis » Sun, 13Dec29 09:32

tlaero wrote:What have you tried so far?

Wait, you don't have a str.
outputScoreString(str + gotoStats);

You never defined str.

Tlaero


all function gameShowTopScore()

Code: Select all
function gameShowTopScore() {

var DayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var Day;  //must range from 0 to 6
var DayName;
Day = readVar("Day");
DayName = DayOfWeek[Day % 7]; 

    var inStats = readVar(gInStats);

    var numSetAchieves = CountSetAchieves();         
    var numMaxAchieves = CountMaxAchieves();
   
    var score = calcScore();
    var score2 = calcScore2();
    var score3 = calcScore3();
    var score4 = calcScore4();
    var score5 = calcScore5();
    var score6 = calcScore6();
    var score7 = calcScore7();
    var score8 = calcScore8();
    var score9 = calcScore9();
    var score10 = calcScore10();
    var str =      "Day " + score + " " + DayName +".| Time " + score2 +".00 | stat1 " + score4 + " | stat2 " + score5 + " | stat3 " + score6 +
                 " | stat4 " + score7 + " | stat5 " + score9 + " | stat6 " + score8 +" | stat7 " + score10 +" | $ " + score3 + " | ";
    var gotoStats = "<br/><a onclick=\"GotoStatsPage('_stats.html');\" href='#'>Go to Stats Page</a> ";
    var stats = "You've earned " + numSetAchieves + " out of " + numMaxAchieves + " Achievements.";

    if (inStats == 0)
    {
        outputScoreString(str + gotoStats);
    }
    else
    {
        outputScoreString(stats);
    }
http://dakutisgames.weebly.com/
User avatar
Dakutis
lagoon predator
 
Posts: 116
Joined: Wed, 12Nov07 14:17
Location: Lithuania, Kaunas
sex: Masculine

Re: Adventure Creator main thread

Postby kexter » Sun, 13Dec29 13:38

Dakutis, what do you mean by "not working"?

I tried your code by replacing gameShowTopScore() in the AC example, added some dummy calcScoreN() functions and it seems to be working. Or at least it does what it is told to do.
My quick check code looks like this:
Code: Select all
function calcScore2() { return 20 }
function calcScore3() { return 30 }
function calcScore4() { return 40 }
function calcScore5() { return 50 }
function calcScore6() { return 60 }
function calcScore7() { return 70 }
function calcScore8() { return 80 }
function calcScore9() { return 90 }
function calcScore10() { return 100 }

function gameShowTopScore() {
    var DayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    var Day;  //must range from 0 to 6
    var DayName;
    Day = readVar("Day");
    DayName = DayOfWeek[Day % 7];

    var inStats = readVar(gInStats);

    var numSetAchieves = CountSetAchieves();         
    var numMaxAchieves = CountMaxAchieves();
   
    var score = calcScore();
    var score2 = calcScore2();
    var score3 = calcScore3();
    var score4 = calcScore4();
    var score5 = calcScore5();
    var score6 = calcScore6();
    var score7 = calcScore7();
    var score8 = calcScore8();
    var score9 = calcScore9();
    var score10 = calcScore10();
    var str = "Day " + score + " " + DayName +".| Time " + score2 +".00 | stat1 " + score4 + " | stat2 " + score5 + " | stat3 " + score6 +
              " | stat4 " + score7 + " | stat5 " + score9 + " | stat6 " + score8 +" | stat7 " + score10 +" | $ " + score3 + " | ";
    var gotoStats = "<br/><a onclick=\"GotoStatsPage('_stats.htm');\" href='#'>Go to Stats Page</a> ";
    var stats = "You've earned " + numSetAchieves + " out of " + numMaxAchieves + " Achievements.";

    if (inStats == 0)
    {
        outputScoreString(str + gotoStats);
    }
    else
    {
        outputScoreString(stats);
    }

    // Set the sizes of the bars to the left and right of the image.
    var green = document.getElementById("green");
    var red = document.getElementById("red");
    if (green && red)
    {
        green.style.height = CalcBarHeight("happy") + "px";
        red.style.height = CalcBarHeight("angry") + "px";
    }   
}

And it generates the following lines:
Day 0 Sun.| Time 20.00 | stat1 40 | stat2 50 | stat3 60 | stat4 70 | stat5 90 | stat6 80 | stat7 100 | $ 30 |
Go to Stats Page

Without seeing what each of your calcScore(), calcScore2(), etc functions do, I can't say for sure that the stat-line will be as you intended. And I'm assuming here that all of these calcScoreN() functions are correct.
For example I don't know if calcScore() calculates the day-number or some other score, because you use score to denote the number of the current day. This could simply be:
Code: Select all
var score = Day + 1;

Also check that there are no duplicate calcScore() functions in _game.js
And in case your stat-page is not showing up then check if you have a '_stats.html' or a '_stats.htm' file - check the extension. In your code you reference a '_stats.html'.
Other than these, I can't think of anything.
User avatar
kexter
Moderator
 
Posts: 214
Joined: Sun, 13Dec29 11:01
sex: Masculine

Re: Adventure Creator main thread

Postby Dakutis » Sun, 13Dec29 15:52

kesler - "not working" is that game don't run - blank screen.
Before I tryed to use Tlaero function with stats page my function was this and its working well.

Code: Select all
function gameShowTopScore() {

var DayOfWeek = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var Day;  //must range from 0 to 6
var DayName;
Day = readVar("Day");
DayName = DayOfWeek[Day % 7]; 
 
    var score = calcScore();
    var score2 = calcScore2();
    var score3 = calcScore3();
    var score4 = calcScore4();
    var score5 = calcScore5();
    var score6 = calcScore6();
    var score7 = calcScore7();
    var score8 = calcScore8();
    var score9 = calcScore9();
    var score10 = calcScore10();
    var str =      "Day " + score + " " + DayName +".| Time " + score2 +".00 | stat1 " + score4 + " | stat2 " + score5 + " | stat3 " + score6 +
                 " | stat4 " + score7 + " | stat5 " + score9 + " | stat6 " + score8 +" | stat7 " + score10 +" | $ " + score3 + " | ";
    var save = " <a onclick=\"SaveState();\" href='#'>Save</a>  ";
    var restore = " <a onclick=\"RestoreState();\" href='#'>Load</a> ";

    outputTopScoreString(str + save + restore);
}
http://dakutisgames.weebly.com/
User avatar
Dakutis
lagoon predator
 
Posts: 116
Joined: Wed, 12Nov07 14:17
Location: Lithuania, Kaunas
sex: Masculine

Re: Adventure Creator Tips and Tricks

Postby kexter » Sun, 13Dec29 17:14

Okay, this may be a wee bit advanced, but you can make Adventure Creator games compatible with Chrome.
Replace the cookie functions in _functions.js with the following code:
Code: Select all
//--------------------------------------------------------//
// Cookie functions
//
// These functions are used for storing and changing
// cookies in the site.  The variable functions use
// these.  Games probably shouldn't call them directly.

var gEnableLocalStorage = true;
var gGameId = "tlaero.example.";  // Use "creator.gamename." or any unique id.

function useStorage() {
  return (typeof(Storage) !== "undefined") && gEnableLocalStorage;
}

// This function deletes a cookie
function deleteCookieVar(name) {
  if (useStorage()) {
    localStorage.removeItem(gGameId + name);
  } else {
    document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
  }
}

// This function creates a cookie (if necessary) and sets its value
function setCookieVar(name, value, expires) {
  if (useStorage()) {
    localStorage.setItem(gGameId + name, Number(value));
  } else {
    if (expires == null) {
      var days = 30; // Number of days to keep the cookies
      expires = new Date();
      expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
    }
    document.cookie = name + "=" + escape(value) + "; path=/" +
      ((expires == null) ? "" : "; expires=" + expires.toGMTString());
  }
}

// This function reads the cookie and returns its value as a number. 
// If the cookie doesn't exist or isn't a number, this returns 0.
function readCookieVar(name) {
  var val = 0;
  if (useStorage()) {
    val = Number(localStorage.getItem(gGameId + name));
    if (isNaN(val)) {
      val = 0;
    }
  } else {
    var fullName = name + "=";   
    var strings = document.cookie.split(';');
    for (var i = 0; i < strings.length; i++) {
      var str = strings[i];
      while (str.charAt(0) == ' ')
        str = str.substring(1, str.length);
      if (str.indexOf(fullName) == 0)
        val = parseInt(str.substring(fullName.length, str.length));
      if (isNaN(val))
        val = 0;
    }
  }
  return val;
}

// This function creates a cookie (if necessary) and sets its (string) value
function setCookieString(name, value, expires) {
  if (useStorage()) {
    localStorage.setItem(gGameId + name, String(value));
  } else {
    if (expires == null) {
        var days = 30; // Number of days to keep the cookies

        expires = new Date();
        expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
    }
    document.cookie = name + "=" + value + "; path=/" +
      ((expires == null) ? "" : "; expires=" + expires.toGMTString());
  }
}

// This function reads the cookie and returns its value as a string. 
function readCookieString(name) {
  var val = "";
  if (useStorage()) {
    val = String(localStorage.getItem(gGameId + name));
  } else {
    var fullName = name + "=";
    var strings = document.cookie.split(';');
    for (var i = 0; i < strings.length; i++) {
      var str = strings[i];
      while (str.charAt(0) == ' ')
        str = str.substring(1, str.length);
      if (str.indexOf(fullName) == 0)
        val = str.substring(fullName.length, str.length);
    }
  }
  return val;
}


Important: Set the gGameId variable (at the beginning of the code) to something unique. Something like "creator.title." for example.

Or if all your ".html" or ".htm" files are in the same directory (barring "start.html") then you can simply change the "var gGameId = ..." line to:
Code: Select all
var gGameId = location.href.replace(/[^\/]*$/, '');


This code uses localStorage (if available) instead of cookies so games will work under Chrome too. No need to start with the "--enable-file-cookies" flag. It will fall back gracefully to using cookies if localStorage is not supported (should be a very rare case) and you can manually disable it by setting the gEnableLocalStorage variable to false.
Apart from these, no further change should be required to your game files. I've tested these modification with the latest Adventure Creator example, Meeting Keeley, and Coffee for Keisha.

Edit: The code contained a glitch, that prevented it from falling back to using cookies if localStorage was not supported (or gEnableLocalStorage was false).
Last edited by kexter on Sun, 13Dec29 22:52, edited 2 times in total.
User avatar
kexter
Moderator
 
Posts: 214
Joined: Sun, 13Dec29 11:01
sex: Masculine

Re: Adventure Creator main thread

Postby kexter » Sun, 13Dec29 17:36

Dakutis wrote:"not working" is that game don't run - blank screen.

Okay, it could be as little as a typo in the code, what does the javascript console (CRTL + SHIFT + K in Firefox) say when you start the game?
If you've just pasted the code in to an older codebase then is gInStats defined in your _functions.js? Do you have a GotoStatsPage() function? Because if these are missing then the script can't be compiled and it will result in a blank screen.
User avatar
kexter
Moderator
 
Posts: 214
Joined: Sun, 13Dec29 11:01
sex: Masculine

Re: Adventure Creator main thread

Postby Dakutis » Sun, 13Dec29 17:49

kexter wrote:
Dakutis wrote:"not working" is that game don't run - blank screen.

Okay, it could be as little as a typo in the code, what does the javascript console (CRTL + SHIFT + K in Firefox) say when you start the game?
If you've just pasted the code in to an older codebase then is gInStats defined in your _functions.js? Do you have a GotoStatsPage() function? Because if these are missing then the script can't be compiled and it will result in a blank screen.


yes you are write, with crtl + shift +K I find that missing "}". Thanks .
http://dakutisgames.weebly.com/
User avatar
Dakutis
lagoon predator
 
Posts: 116
Joined: Wed, 12Nov07 14:17
Location: Lithuania, Kaunas
sex: Masculine

Re: Adventure Creator Tips and Tricks

Postby tlaero » Sun, 13Dec29 18:59

Hi Kexter,

It's a pretty bad idea for people to change _functions.js. That file needs to stay in sync with AC updates. If someone changed it, they'd either need to merge in future changes to it, or they wouldn't be able to update to later versions of AC.

I investigated local storage a while back, and there were browsers that, like cookies in chrome, supported the Storage class, but didn't support it on file://. It looks like your code would break those browsers. Which ones did you test it on?

Tlaero
User avatar
tlaero
Lady Tlaero, games and coding expert
 
Posts: 1829
Joined: Thu, 09Jun04 23:00
sex: Female

Re: Adventure Creator Tips and Tricks

Postby kexter » Sun, 13Dec29 22:14

Firefox 26, Chrome 32, Opera 12 - all work.
I know IE 11 slips. Personally I'd trade IE support for Chrome support in a heartbeat, but I don't know your user-base so I don't know your priorities.
@kextercius
User avatar
kexter
Moderator
 
Posts: 214
Joined: Sun, 13Dec29 11:01
sex: Masculine

Re: Adventure Creator Tips and Tricks

Postby Wolfschadowe » Sun, 13Dec29 22:18

My solution to the Chrome issue is to put a notification on the start page for BEW for Chrome users to launch the game with the "--enable-file-cookies" switch in the shortcut. This allows full compatibility.

Wolfschadowe
User avatar
Wolfschadowe
legend of the South Seas
 
Posts: 559
Joined: Thu, 13Mar21 07:37
Location: West Coast, USA
sex: Masculine

Re: Adventure Creator Tips and Tricks

Postby tlaero » Mon, 13Dec30 04:38

Chrome rules mobile, but if we're talking about solving the --enable-file-cookies problem, it's desktop browsers. In desktop browsers, IE is 58%.

That said, I'd rather localstorage. It makes me sad that IE doesn't support it in the filesystem. This is the first time IE made my life harder. Usually that's firefox's job.

What if we did
if (typeof (localStorage) != "undefined")

instead of

if (typeof (Storage) != "undefined")

I think localStorage is undefined in file:// on IE but defined elsewhere.

Tlaero
User avatar
tlaero
Lady Tlaero, games and coding expert
 
Posts: 1829
Joined: Thu, 09Jun04 23:00
sex: Female

PreviousNext

Return to The workshop of creators

Who is online

Users browsing this forum: No registered users and 2 guests

eXTReMe Tracker