Adventure Creator Q&A thread

Tips, techniques and tutorials about creation tools.

Adventure Creator Q&A thread

Postby tlaero » Sat, 16Jan23 19:48

If you've got questions on how to do things with AC, this is the place to ask. These can be anything from "The program won't start, what do I do?" to "How do I do animations?" to "How do I write code to do this thing I want to do?"

If it's a question about how to do something in a game that you're writing with AC, it's fair ... er ... game here.

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

Re: Adventure Creator Q&A thread

Postby tlaero » Sat, 16Jan23 19:59

I have plans to do a series of quick "How to" tutorials here when I have some more time. I'll morph the old "Need Help" thread into an explanation of advanced animation techniques. I suspect it would be beneficial to do an "AC: How do to simple animations" as well. Are there other tutorials people would like to see?

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

Re: Adventure Creator Q&A thread

Postby bd2021 » Mon, 16Mar21 06:00

Note: I was asked to move this discussion to this Q&A thread in case others come to the forum having similar questions. The following post is a question I asked tlaero via PM and the response.

I'm trying to set up a _game.js for a game and I've run into a bit of an issue. Before I get into it all I want to say sorry if this has been addressed already somewhere, I didn't see it in the tutorials, but I also didn't go through all of the pages of AC discussion on the forum. Also, I have a very limited knowledge of actual coding (especially in terms of JS), so if something I say doesn't make sense that's probably why. I've also basically avoided any difficulty settings for this game since I think it'll be challenging enough for me to make it without having to worry about multiple difficulties right now.

So my issue is that I have 2 characters in my game that I want to keep a separate score for. My idea is that the game will have some branching and depending on user decisions you can end up with one character or the other (or no potentially no one). The issue I've run into is that from what I can tell the calcScore() function keeps a single global score, which would be fine for 1 character but doesn't really work with the game model I had in mind. So my question is: is it possible to modify the calcScore function to have separate scores for different characters (ie calcScore(Character1) and a separate calcScore(Character2))? I've noticed in the _functions.js that there doesn't appear to be any code setting up scoring parameters (just if you want to show the score in the game which I don't), so maybe I'm overthinking this... It seems to me that I could make a function like calcChar1 and then use char1's variable values to calculate a "score", but then I'm not sure if I could set up a code like calcNeeded(area) that is specific for the separate characters to block progression at different points. So for instance could I do something like this:

Code: Select all
var gameVars = ["Char1happy", "Char2happy", "Char1angry", "Char2angry", "cssSize"];

var hug
var kiss

function calcChar1()
{
var Char1happy = readVar("Char1happy") - readvar("Char1angry");
return Char1happy;
}

function calcChar2()
{
var Char2happy = readVar("Char2happy") - readvar("Char2angry");
return Char2happy;
}

function calcNeeded(hug)
{
var needed = 5;
return needed;
}

function calcNeeded(kiss)
{
var needed = 10;
return needed;
}

function checkHug1()
{
var Char1score = calcChar1();
var needed = calcNeeded("hug");

if (Char1score >= needed)
{
window.location = "Char1hug.html";
}
else
{
window.location = "end1.html";
}
return false;
}

function checkHug2()
{
var Char2score = calcChar2();
var needed = calcNeeded("hug");

if (Char2score >= needed)
{
window.location = "Char2hug.html";
}
else
{
window.location = "end2.html";
}
return false;
}


Again sorry if this doesn't make sense or is super complicated. It seemed like you did something similar in Pandora, but I'm not sure if this is the way to do it or if there is something much simpler that could be done.


Everything you've said makes sense and should generally work. The calcNeeded functions aren't right, though. It would be more like this:

Code: Select all
function calcNeeded(type)
{
    if (type == "hug")
    {
         return 5;
    }
    else if (type == "kiss")
    {
         return 10;
    }
    else  // error case
    {
         return 100;
    }
}


Does that make sense?

Tlaero


Yeah, I think that makes sense, thanks! A few more questions. Is there a reason you use the "==" instead of "=" for the type definition? Also I assume the
Code: Select all
else // error case
{
return 100;
}
is a bypass in case of a coding error on my part, is that correct? Lastly, does it matter what I put into the calcNeeded() function? That is does it matter if I use something like calcNeeded(action) or calcNeeded(somethingelse)?

Thanks again!
bd2021
sirens hunter
 
Posts: 13
Joined: Tue, 11Nov22 04:31
sex: Masculine

Re: Adventure Creator Q&A thread

Postby kexter » Mon, 16Mar21 10:54

bd2021 wrote:Is there a reason you use the "==" instead of "=" for the type definition?
Okay, that needs a bit of clearing up, "==" and "=" are two completely different operators. The assignment operator ("=") is used to assign values to variables, while the equivalence operator ("==") is a comparison operator that is used to check if variables and/or values are equivalent.
bd2021 wrote:Lastly, does it matter what I put into the calcNeeded() function? That is does it matter if I use something like calcNeeded(action) or calcNeeded(somethingelse)?
If you don't actually do any calculation in the calcNeeded() function then you can simply drop it and use some variables instead. As I see it, you already tried something like that judging from the dangling "hug" and "kiss" variables at the top. Also do not use `window.location = "page.html";´ to jump between pages, use GotoPage("page.html"); instead. See:
Code: Select all
var gameVars = ["Char1happy", "Char2happy", "Char1angry", "Char2angry", "cssSize"];

var scoreHug = 5;
var scoreKiss = 10;

function calcChar1() {
  return readVar("Char1happy") - readvar("Char1angry");
}

function calcChar2() {
  return readVar("Char2happy") - readvar("Char2angry");
}

function checkHug1() {
  if (calcChar1() >= scoreHug) {
    GotoPage("Char1hug.html");
  } else {
    GotoPage("end1.html");
  }
}

function checkHug2() {
  if (calcChar2() >= scoreHug) {
    GotoPage("Char2hug.html");
  } else {
    GotoPage("end2.html");
  }
}
@kextercius
User avatar
kexter
Moderator
 
Posts: 214
Joined: Sun, 13Dec29 11:01
sex: Masculine

Re: Adventure Creator Q&A thread

Postby Mortze » Mon, 16Mar21 19:10

Really good initiative.
I'll definitly need to rely on your help in this thread. Mostly for code formulas.
User avatar
Mortze
legend of the South Seas
 
Posts: 648
Joined: Wed, 14Oct29 02:34
sex: Masculine

Re: Adventure Creator Q&A thread

Postby tlaero » Tue, 16Mar22 04:18

How you do this will depend on what you're trying to do. The original "calcNeeded" that I use in my games is about what's needed changing as the game progresses. If you're in scene1, you need a 5 to continue, but if you're in scene 2, you need an 8, etc. It also handled the difference between difficulties.

If, on the other hand, you just need fixed values, like "5 for hug, 10 for kiss, 15 for squeeze" etc, there are easier ways to do it. I like what Kexter suggested (aside from the crazy bracket indention :-).

Kexter talked about this, but it's really important, so I'm going to reiterate. In all "c like" languages (c, c++, c#, java, javascript, etc) there's a huge difference between "=" and "==".
"=" is "set the thing on the left to the thing on the right."
"==" is "check if the thing on the left is the same as the thing on the right."

So, say you have
var score = 5;

At that point, score is equal to 5.

Say you then have

score = 6;

Now score is equal to 6.

But say you have

if (score == 7)

This checks if score is equal to 7 (which it's not, it's equal to 6) and returns "true" or "false" (false in this case).

It's really unfortunate, but in most of those "c like" languages, this is legal.

if (score = 7)

But this doesn't do what you think it does. It changes "score" to 7 and then checks to see if that value is "true" or "false." In these languages, anything that isn't 0 is true, so this makes it true, even though that's not what you wanted. One of my first coding professors (more years ago than I'd like to admit) once told me that I was definitely going to make this mistake. I thought he was kind of a jerk and said, "No I'm not!" Unfortunately, he was right...

So, imagine the following code. (Note that things that start with // are comments and aren't used by the code.)

Code: Select all
var score = 0;

// Something happens that gives you a lot of points
score = 4;

if (score = 8)
{
    // allow the player to kiss
}

if (score == 5)
{
   // allow the player to hug
}



Here's what happens.
The player has 4 points and shouldn't be allowed to kiss or hug. But when you test your code, you find that he's allowed to both kiss AND hug. You pull your hair out for a bit, before you notice that you only used one = in "if (score = 8)".

After that line, score is equal to 8, not 4. It allows him to kiss and then, later, when it correctly uses two equals on the hug, score is 8, so he can hug too.

Moral of the story: if your code isn't working right, check your equals.

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

Re: Adventure Creator Q&A thread

Postby bd2021 » Tue, 16Mar22 05:54

Okay, that needs a bit of clearing up, "==" and "=" are two completely different operators. The assignment operator ("=") is used to assign values to variables, while the equivalence operator ("==") is a comparison operator that is used to check if variables and/or values are equivalent.

Kexter talked about this, but it's really important, so I'm going to reiterate. In all "c like" languages (c, c++, c#, java, javascript, etc) there's a huge difference between "=" and "==".
"=" is "set the thing on the left to the thing on the right."
"==" is "check if the thing on the left is the same as the thing on the right."
...

Makes sense, thanks.

How you do this will depend on what you're trying to do. The original "calcNeeded" that I use in my games is about what's needed changing as the game progresses. If you're in scene1, you need a 5 to continue, but if you're in scene 2, you need an 8, etc. It also handled the difference between difficulties.

If, on the other hand, you just need fixed values, like "5 for hug, 10 for kiss, 15 for squeeze" etc, there are easier ways to do it. I like what Kexter suggested (aside from the crazy bracket indention :-).

So the difference in difficulty makes sense here, ie using a single function to progress from scene 1 forward with multiple possible variables depending on the selected difficulty rather than an individual function for each possible permutation. If you get rid of the difficulty settings though would it not be easier to set up separate variables (something like var scene1 = 5;, var scene2 = 8;, etc) and then individual check functions (Function checkScene1() for example)?

Note to tlaero: Your Tutorial 2 has a typo in it.
The last thing you need to do is set the gameScaleFactor. Calculate this by dividing the larger image’s width by the smaller one’s width. In this case, it’s 1280 divided by 500, or 2.56. Change the gameScaleFactor from 1.25 to 2.56, and you’re done.

should read
The last thing you need to do is set the gameScaleFactor. Calculate this by dividing the larger image’s width by the smaller one’s width. In this case, it’s 1280 divided by 889, or 1.44 (or 1.43982 if you want to be more precise). Change the gameScaleFactor from 1.25 to 1.44, and you’re done.
bd2021
sirens hunter
 
Posts: 13
Joined: Tue, 11Nov22 04:31
sex: Masculine

Re: Adventure Creator Q&A thread

Postby Wolfschadowe » Fri, 16Mar25 16:20

Just received the following error when creating the first page in a new directory. I selected "Continue" from the pop-up and the page saved without the image. I reopened the page via game view, re-selected the image and the page saved normally. A second page that I created immediately afterwards also saved normally. I have not been able to reproduce the error since. Exception text in Spoiler.

************** Exception Text **************
System.ArgumentOutOfRangeException: Value of '-345' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'.
Parameter name: Value
at System.Windows.Forms.ScrollBar.set_Value(Int32 value)
at AdventureCreator.GameView.ScrollToStringBottom(String curString, Boolean bOnlyIfOffscreen)
at AdventureCreator.AdventureCreator.UpdateFileView(String strFileName, String strSubDir, String strCurOverDir, String imageSubPath, Int32 numFrames, String strData, String strDump, String links, LocNeeds needsLoc, Boolean doUpdate)
at AdventureCreator.AdventureCreator.AddCurrentFileView(Boolean doUpdate, Boolean isUser)
at AdventureCreator.AdventureCreator.HandleSave(Boolean doUpdate)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItem.ShortcutClick()
at System.Windows.Forms.Form.ProcessCmdKey(Message& msg, Keys keyData)
at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
at System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessCmdKey(Message& msg, Keys keyData)
at System.Windows.Forms.TextBox.ProcessCmdKey(Message& m, Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1055.0 built by: NETFXREL2
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
AdventureCreator
Assembly Version: 2.5.0.0
Win32 Version: 2.5.0.0
CodeBase: file:///C:/Users/<Redacted...>/AdventureCreator6/AdventureCreator.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1055.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1055.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1068.2 built by: NETFXREL3STAGE
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.6.79.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------


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

Re: Adventure Creator Q&A thread

Postby tlaero » Sat, 16Mar26 01:44

Thanks Wolf, I know about that one. It happens when you have GameView open and there's not enough files in it to scroll. I discovered it when I was writing DwE:LtF. I've got it fixed in my current version, but it didn't seem like enough to release an update for. You'll stop getting the exception when you have enough items in the gameView that it gets a scroll bar. In my experience, hitting "Continue" let things progress normally and I didn't have to re-save it.

I'll release an update soon with the fix for that.

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

Re: Adventure Creator Q&A thread

Postby Wolfschadowe » Sat, 16Mar26 06:27

tlaero wrote: It happens when you have GameView open and there's not enough files in it to scroll.
Yep, that doesn't happen to me very often. My GameView is usually packed. :) Good to know it's already on your list. Thanks for looking at it!

Your awesomeness continues unabated. :)
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 Q&A thread

Postby tlaero » Wed, 16May25 07:32

Question for the hardcore JavaScript programmers. I've been using the following code:

Code: Select all
function ConvertBrackets(source)
{
    var openBrackets = "[[";
    var closeBrackets = "]]";
    var openParen = "(";
    var closeParen = ")";

    var index = 0;
    var start = source.indexOf(openBrackets, index);
    var end;
    while (start != -1)
    {
        end = source.indexOf(closeBrackets, index);
        if (end == -1)
        {
            break;
        }

        var fullStr = source.substring(start, end + closeBrackets.length);
        var openParenIndex = fullStr.indexOf(openParen);
        var closeParenIndex = fullStr.indexOf(closeParen);
        var fnstr = fullStr.substring(openBrackets.length, openParenIndex);
        var params = fullStr.substring(openParenIndex + 1, closeParenIndex);
        var fn = window[fnstr];

        if (typeof fn == 'function')
        {
            var str = fn(params);

            source = source.replace(fullStr, str);
        }

        index = end + closeBrackets.length;

        start = source.indexOf(openBrackets, index);
    }

    return source;
}


The idea here is that I run this code on a string that has functions in [[]] and it runs that code. For instance.

Code: Select all
function Name()
{
    return "Tlaero";
}


And the source string that I pass to ConvertBrackets is
Code: Select all
"Hello, my name is [[Name()]]."


This works great when I have no parameters or one parameter. But it doesn't work if I want to have two parameters.

Code: Select all
function Two(param1, param2)
{
  return param1 + param2
}


I can't find any combination of quotes or brackets to make that come in as two parameters.

If I do:
Code: Select all
Hello, this is [[Two('sharks', 'lagoon')]].


Param1 comes in as "'sharks', 'lagoon'" and param2 comes in as undefined.

What's the right way to do this?

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

Re: Adventure Creator Q&A thread

Postby Greyelf » Wed, 16May25 08:53

Is there a reason you are not using a Regular Expression?

I'm travelling atm, so the following is off the top of my head and based on the results from here but something like the following:
Code: Select all
var str = "Hello, this is [[Two('sharks', 'lagoon')]].";
var rx = /\[{2}([\w]+)\(([\s\S]+)\)\]{2}/;
var matches = str.match(rx);

// the first group (second element) is the function name.
var fn = matches[1];

// the second group (third element) is all the parametes, split them using the coma.
var params = matches[2].split(',');

console.log(fn);
params.forEach(element => console.log(element.trim()));
Greyelf
star of the reef
 
Posts: 390
Joined: Thu, 14Jun12 03:20
sex: Masculine

Re: Adventure Creator Q&A thread

Postby kexter » Wed, 16May25 09:59

Here is the relevant code from BEW:
Code: Select all
// Evaluates [[...]] blocks in the specified text.
function evaluateText(text) {
  var s, strBefore, strAfter, func,
    result = typeof text === "undefined" ? "" : text;
  while (result.indexOf("[[") > -1) {
    strBefore = result.slice(0, result.indexOf("[["));
    s = result.slice(result.indexOf("[[") + 2);
    strAfter = s.slice(s.indexOf("]]") + 2);
    s = s.slice(0, s.indexOf("]]"));
    func = new Function("return " + s);
    s = func();
    s = typeof s === "undefined" ? "" : s;
   result = strBefore + s + strAfter;
  }
  return result;
}

This supports the following cases:
Code: Select all
[[customStuff()]]
[[gender("her", "his")]]
[[readVar("test") < 0 && readVar("school") === 1 ? "You have to study." : "You can do anything you want"]]
[[chooseText(readVar("mood"), [
  "happy", "sad", "angry", "bored"
])]]

But if you want to stay with your spec and avoid new Function(), then the following will do pretty much that, albeit with the following caveats: only supports [[func(a, b, ...)]]-type of groups, there can be no line-breaks in the [[...]]-definition, string parameters only (without escaping) - so no 'I\'m' but "I'm" and 'This "is" something' is fine.
Code: Select all
function convertBrackets(text) {
  var groupMatch, paramMatch, funName, params, substitute,
    strBefore, strGroup, strAfter, strParams,
    r = /\[\[(.*)\((.*)\)\]\]/g,
    p = /('.*?'|".*?")/g,
    result = text;
  params = [];
  groupMatch = r.exec(text);
  while (groupMatch !== null) {
    strGroup = groupMatch[0];
    funcName = groupMatch[1];
    strParams = groupMatch[2];
    params = [];
    paramMatch = p.exec(strParams);
    while (paramMatch !== null) {
      params.push(paramMatch[1].slice(1, paramMatch[1].length - 1));
      paramMatch = p.exec(strParams);
    }
    substitute = "";
    if (typeof window[funcName] === "function") {
      substitute = window[funcName].apply(null, params);
    }
    result = result.replace(strGroup, substitute);
    groupMatch = r.exec(text);
  }
  return result;
}
@kextercius
User avatar
kexter
Moderator
 
Posts: 214
Joined: Sun, 13Dec29 11:01
sex: Masculine

Re: Adventure Creator Q&A thread

Postby tlaero » Thu, 16May26 04:54

Awesome, Kexter. Thank you! The magic I needed was this line:

Code: Select all
func = new Function("return " + s);


That drops cleanly into my code (and simplifies it, since I send the whole function and don't need to parse out the params separately).

Allocating functions. That's kind of cool. JavaScript is growing on me, though I'll never get over its not being type safe.

Thank you also, Greyelf. The problem, though, wasn't parsing out the parameters. It was passing them to the function.

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

Re: Adventure Creator Q&A thread

Postby jilliangates77 » Sat, 16Aug13 18:16

Hi Tlaero!

So I followed your directions and wanted to copy / paste where I started from:

From here:
The main AC window has text boxes where you can add or change text. The "game view" window has the names of the pages in bold as well as the text in them. Click a bold name in game view to load that page into the main window.

And, I did this (sort of...)
Look through the pages in the example and see how they worked in AC2.

Successfully changed the "Top Text," of the page for the intro().

Then I see that the white image 'files\images\white.jpg' seems to be associated with the intro() page. Hm, how do I change that image? It says "configure an image editor."
jilliangates77
great white shark
 
Posts: 74
Joined: Mon, 14Nov03 18:26
sex: Female

Next

Return to The workshop of creators

Who is online

Users browsing this forum: No registered users and 11 guests

eXTReMe Tracker