Confusion on using variables


Sorry, just trying to puzzle this program out. So, I have a character creation framework set (bare bones, but I'm really just trying to learn how things work, not actually make anything)...

<object name="Character Creation">
<inherit name="scripttext" />
<script type="script">
  msg ("Okay, let's test this out. First of all, what's your name?")
  GetInput() {
    PlayerName = result
    msg ("")
    msg ("Hi, " + PlayerName + ".")
    msg ("")
    ShowMenu ("What's your character class?", Split ("Cleric;Mage;Rogue;Warrior"), false) {
      PlayerClass = result
      msg ("")
      msg ("So you're a " + PlayerClass + ".")
      MovePlayer (Entrance)

And that all works fine. However, once the player is in Entrance, I want it to do this:

msg ("You have arrived at the gates!  A determined " + PlayerClass + ", you aim to rid the land of the wicked sorcerer once and for all!")

And it tells me "Unknown object or variable 'PlayerClass'". What do I need to do to get it to recognize the variable value from the other page? Also, what do I need to do to make it display in lowercase?

Thank you!

Variables only exist until the end of the script that created them.

If you want them to persist, you need to make them attributes.

An attribute's name looks like game.somevariable or player.class. You can use them in the same way as local variables, just by putting a dot in the name.
The part before the dot is the name of an object. The attribute will continue to exist as long as the object does; but the code will give an error if the object doesn't exist.

In a gamebook, valid objects are game, player, or any page.

The gamebook concept of "flags" and "counters" are actually just attributes of the game object. In some circumstances, like the text processor's {if statement, any variable name without a dot in it will have game. stuck on the beginning before processing.

Ah, simple enough! Thank you so much for the help, it's greatly appreciated. Sorry though, but how do I do that? I've tried tweaking the variable names with a period, and making them lowercase, and now it's just telling me "Cannot change name of element when not in Edit mode".

Re you trying to name an attribute name? This is an attribute which already exists for all objects. name specifically is an attribute which cannot be changed during the game.

That's all it was, indeed! An easy fix. I like it. Thank you again!

All of the editable fields in the editor are actually stored into attributes; so you can change them in the same way as other variables. As long as you're just doing simple things, you probably want to avoid using those attribute names; but when you get on to more advanced scripting, it can be useful to know what they are in case you want to change them during the game.

  • For the game object there are dozens, including settings for colours/fonts/etc. Plus:
    • - not a valid attribute
    • game.noclear - set to true if you don't want to clear the screen between pages
  • For the player object:
    • - must be "player"
    • player.parent - the current page
  • For a page:
    • pagename.visited - this will be true or false depending if the player has been to a particular page.
    • pagename.description - the page's text
    • pagename.script - the page's script
    • - the address of a youtube video
    • pagename.sound - the name of a sound file
    • pagename.picture - the name of an image file
    • pagename.options - the options leading away from the page (this is the one you're most likely to change; for example if you want a player's choice to add or remove links from some other page)

Very good to know, thank you! I greatly appreciate the effort and the assistance, it has been extremely helpful.

Log in to post a reply.