Gamebook Questions.

Hello, I'm currently trying to make a CYOA style game using the Gamebook. However I'm unsure on how to create variables in the game (since I use the online editor I have a slight idea for text adventures but Gamebook lacks a key thing I need for it to work). I'm also unsure the main function of the the counter as well, I can't seem to find it in the tutorial, or if it is something I can use.

Sorry for sounding like a novice, I can handle text adventures but the gamebook looks weird. Yet I think its perhaps the best to go about the CYOA rather than creating a whole world that may only be seen once in some cases.

Edit: Didn't realize there was also Squiffy, and it has a tutorial on gamebooks, I'll poke through that and see if I still have the same issues.


However I'm unsure on how to create variables in the game

I suspect you mean attributes; which are variables that continue to exist after the end of the script that created them.

I'm not sure how to do it in the GUI (it's awkward, and you have to find the option you want instead of just typing it in). However, if you can't find the function you need, you can still enter code view for a moment, type it in, and then return to the GUI if that's your preferred way of working.

To set an attribute, you want a line that looks like:

objectname.attributename = value

For example:

game.score = 25

or

player.catchphrase = "By George!"

In gamebook mode, the "objects" you can use for your attributes are either the special objects (player and game), or pages. Note that you have to spell the name of the object exactly, including any spaces and capital letters.

If you want to increase or decrease an attribute, you can do sums using the old value (or using other attributes). For example:

player.health = player.health - 6

will set the player's health attribute to what it previously was, minus 6. This will cause an error if you haven't already set that attribute to something.

To display the attributes, you can include {objectname.attributename} in any piece of text that gets displayed. To change other things based on the value of an attribute, in your script you can do something like:

if (player.health < 20) {
  msg ("You are bleeding, so your friend panics and takes you to hospital.")
  MovePlayer (page95)
}

Hopefully that's enough of the basics of variables. If you can be more precise about what part you're missing, I can try to give a better answer.

I'm also unsure the main function of the the counter as well, I can't seem to find it in the tutorial, or if it is something I can use.

A counter is just an attribute of the object game. Gamebook mode gives you some functions to manipulate them. The same as Flags, which are just attributes of game which must be boolean (true or false).


Thank you for the tips, I'll update if everything works so far.


Okay I had some luck on the attribute part, I selected the set variable and did game.score on the left and game.score ="140" on the right while placing a {game.score} in the text. It returned to be a false in the place of the {game.score}, yet I'm unsure why.

Another weird thing is trying to set up page links, I thought the "add page link" would simply add a page link yet it doesn't do that unless I have text added with the script (the Script+Text option for the page).

I will say this is a very odd way of how this Quest code is behaving, why are gamebooks so different?


Okay I had some luck on the attribute part, I selected the set variable and did game.score on the left and game.score ="140" on the right while placing a {game.score} in the text. It returned to be a false in the place of the {game.score}, yet I'm unsure why.

I think that adds the line:

game.score = game.score = "140"

That is, it compares the existing value of game.score to the string "140" and generates a value of true or false depending if they're equal, and sets the new game.score to that value.

The expression you want is probably just "140" (or 140 without the quotes if you want to add to it later).


Okay removing the game.score from the prompt is actually giving me the number! However... I can't seem to add or subtract from it properly. If I try to add something it gets placed next to it, say if I try to add a six it wouldn't go to 146 but will look like 1406. Subtracting doesn't work as it says the "Operation 'Subtract' is not defined for types 'String' and 'Int32".


It seems you're missing the difference between "140" and 140 in your code.

The first one, with quotation marks around it, is a String. It is a series of characters, and anything else added to it will be joined on to the end.

The second one, without quotation marks, is an Int32. It is stored as a number, and you can do addition and subtraction with it.


Ah so that's why it's acting weird, thank you it's working now!

So now the next odd issue is trying to create page links from script-only pages. I assume using the add link code is the way to do it as the remove page link works on the pages with text on them. Here is how it looks:

AddPageLink (Autumn 1 In the Dorms, Page3, ""I'm here!"")

Not sure what I am doing wrong in this instance.


Yes, it looks like description and options are both part of the "text" page mode. If you want to use options, you would need to change the page type to "Script + Text".

Alternatively, you could have your script display the links itself, rather than modifying the page. Doing something like:

msg ("{page:Page3:Some text here}")

I'll try that once I get the time, thank you again.


Okay that works, although it is a bit weird how it presents itself. Not to mention it doesn't remove the links of the page once I click on them, but it is moving me to other pages. Is there a way to remove these?


I haven't played much with gamebook mode, but skimming over the code it looks like this is fairly simple.
When visiting a new page, GamebookCore checks if there is an attribute called game.optionsoutputsection containing the name of a section, and if so removes that section.

So, the lines you want will be:

game.optionsoutputsection = StartNewOutputSection()

and

EndOutputSection (game.optionsoutputsection)

Everything between those two will be removed when the player clicks a link to a new page.


I'm not sure how to implement this, trying a few things yet so far none are working. Both codes are appearing in the text and haven't vanished after moving to a new page, so I assume there may be something I'm not doing correctly.

Edit: Also I'm sorry if I'm asking so many questions, it doesn't help that Quest does have an apparent guide on Gamebooks (Squiffy does, yet their GUI looks scary).


I'm not sure how to implement this, trying a few things yet so far none are working. Both codes are appearing in the text and haven't vanished after moving to a new page, so I assume there may be something I'm not doing correctly.

Those are lines of script. Here's what it looks like in the GUI:

(I just put a random message in between them for demonstration purposes)

If someone gives you lines of script, it's usually easiest to go into code view and paste them in. Even if you switch right back to the GUI for editing, code view allows you to copy and paste code to share on the forum :)


OH, I see. Alright let me see if I can get this to work on my end, hopefully it works.


YES IT WORKS! Thank you very much mrangel! I doubt I have any other questions for now, but thank you again!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums