Is it possible to have the number of different objects/pages counted for you?

Greetings, fellow Quest users.

A gamebook-dolt needs your help. To be exactly, i just need the number of different pages i have in total. (Minus a few that are entirely script, but i can count those by hand and subtract later.)

The problem is that i have, even when all directories under Pages are fold together already nigh-200 entries. I don't have to tell you that counting the entire tree by hand is tedious and prone to errors. So i would like to be able to have them counted, but couldn't find a way to do so.

I though that looking at Pages (Disable Simple Mode) could give me a number... It doesn't.

Anyone got a suggestions? I'd highly appreciate it, and thanks in advance.


Off the top of my head:

This gamebook has {eval ListCount (AllObjects())-1} pages!

I believe (havent tested it) that for a gamebook, AllObjects() will return all pages plus the player.

If you want only text pages, you can write a script to loop over AllObjects and count the ones with a specific type. I'd give an dxample, but don't remember the name of the type.

Edit: your script would look something like:

textpages = 0
scripttextpages = 0
scriptpages = 0
foreach (page, AllObjects()) {
  if (DoesInherit (page, "defaultplayer")) {
    // do nothing here, because we're counting pages
    // and as far as I'm aware, AllObjects() returns all pages plus the player object
  }
  else if (DoesInherit (page, "script")) {
    scriptpages = scriptpages + 1
  }
  else if (DoesInherit (page, "scripttext")) {
    scripttextpages = scripttextpages + 1
  }
  else {
    textpages = textpages + 1
  }
}
msg ("Page count by type:<ul><li>Text: "+textpages+"</li><li>Text and Script: "+scripttextpages+"</li><li>Script: "+scriptpages+"</li></ul>")

Of course, you'd need to do this in the game. I'd recommend either making a "game stats" page (and only adding a link to it temporarily if you don't want players to see it), or (if you only want to count them once) adding the code, getting your answer, and removing it again.


So, i'm now going to do one of my favourit activities: nitpicking over work that others have done for me. :P

Your little code is prining out the message after every counting step, resulting in 228 outputs for me. Wrong placement of the curly braces? Also, you've forgoten that gameis also an object. (Forgivable, since this is just a gamebook shenenigan.)

Anyway, big thanks for this handy-dandy little script, it will be very usefull in the future. I still can't believe you have to do this with a counting script, but the only other option i've seen would have been opening Pages with Notepad++ and look at the line count.


(filler for getting my edited post, updated/posted)


you need to put this code into the 'start' Script Attribute of the required and special 'game' Object, so it's only done once, at the very start of your game, but if you create new pages during game play, you'd need to run this code again, if you want to get the new count of pages you got now

or, you can have your first page, be set to the Page Type: [script] or [text + script], and put this code into it (it's scripting) instead (if the 'start' Script Attribute of the special and required 'game' Object doesn't exist in the Game Book)

to handle the special and required 'game' Object (mrangel and myself didn't know that both the default 'player' Player Object and the special and required 'game' Object were included as Pages/Objects that the 'AllObjects()' Script/Function counts)

(and a little tweaking of mrangel's code, and a small correction: mrangel forgot to change 'scripttextpages' to 'textpages' in the 'else' condition, likely due to copy-pasting - the one pitfall of using copy-pasting, lol-sighs-argh, I always to this mistake too)

textpages = 0
scripttextpages = 0
scriptpages = 0

foreach (page, AllObjects()) {

  if (not page = game and not DoesInherit (page, "defaultplayer")) {

    // if the above line doesn't work, try this line instead: if (not page.name = game.name and not DoesInherit (page, "defaultplayer")) {

    // also, if the Game Book has the 'pov' feature (and you got it set up), you can do this code line instead as well: if (not page = game and not page = game.pov) {

    // if that doesn't work, try this code line instead: if (not page = game and not page.name = game.pov.name) {

    // or lastly, if that doesn't work, try this code line instead: if (not page.name = game.name and not page.name = game.pov.name) {

    if (DoesInherit (page, "script")) {
      scriptpages = scriptpages + 1
    } else if (DoesInherit (page, "scripttext")) {
      scripttextpages = scripttextpages + 1
    } else {
      textpages = textpages + 1
    }

  }

  msg ("Page count by type:<ul><li>Text: "+textpages+"</li><li>Text and Script: "+scripttextpages+"</li><li>Script: "+scriptpages+"</li></ul>")
}

if you want to store those count Values for reuse later/elsewhere:

(or replace 'game' in all of my 'game.XXX', aka: game.scriptpages, game.scripttextpages, game.textpages, with either: 'player' or 'whatever_you_renamed_the_default_player_object_as' or 'whatever_you_named_your_first_page_as' or 'the_name_of_whatever_page_that_you_want_to_use_to_hold_these_integer_attributes')

game.textpages = 0
game.scripttextpages = 0
game.scriptpages = 0

foreach (page, AllObjects()) {

  if (not page = game and not DoesInherit (page, "defaultplayer")) {

    // if the above line doesn't work, try this line instead: if (not page.name = game.name and not DoesInherit (page, "defaultplayer")) {

    // also, if the Game Book has the 'pov' feature (and you got it set up), you can do this code line instead as well: if (not page = game and not page = game.pov) {

    // if that doesn't work, try this code line instead: if (not page = game and not page.name = game.pov.name) {

    // or lastly, if that doesn't work, try this code line instead: if (not page.name = game.name and not page.name = game.pov.name) {

    if (DoesInherit (page, "script")) {
      game.scriptpages = game.scriptpages + 1
    } else if (DoesInherit (page, "scripttext")) {
      game.scripttextpages = game.scripttextpages + 1
    } else {
      game.textpages = game.textpages + 1
    }

  }

  msg ("Page count by type:<ul><li>Text: "+game.textpages+"</li><li>Text and Script: "+game.scripttextpages+"</li><li>Script: "+game.scriptpages+"</li></ul>")
}

Your little code is prining out the message after every counting step, resulting in 228 outputs for me. Wrong placement of the curly braces?

Yeah; one misplaced brace. The hazards of typing on my phone, with the onscreen keyboard, where I don't have access to Quest to test it.

I've now edited the code in the post above to fix it.

Also, you've forgoten that game is also an object. (Forgivable, since this is just a gamebook shenenigan.)

No I didn't. game might or might not be an object (Quest uses the word "object" to mean three different things, depending if you're looking at the documentation, Quest code, or the source code of the editor. One of those definitions includes game, the others don't)

But whether it's an object or not is irrelevant. game is not in the list returned by AllObjects().

I took a while to respond to this, because I wanted to double check that this is still the same in gamebooks.


But whether it's an object or not is irrelevant. game is not in the list returned by AllObjects().

Oh, i wasn't aware of this. It's... odd.

Anyway, mrnagel and hegemonkhan, thanks for your input, this really saved me from loads of frustration.


Log in to post a reply.

Support

Forums