Gamebook: Handling page links based on variables

Hi,
next question. I'm working on a gamebook with a status page. If you flip to that page, all essential character stati get displayed. Of course, the player should be able to flip back to where they left. So, I tried to do this:
AddPageLink(Status, game.current_page, "Back to game")
This is, at least in my imagination, very intuitive; AddPageLink() gets from which page to which page a link should be added with a link text as defined in the 3rd parameter. Funny thing is that the link doesn't get displayed; Neiter if I add this code on the Status page itself, nor on another page. game.current_page would contain a valid page object, for example Start if I had a page named Start.
Alternatively, I tried printing the expression:
Msg("{page:" + game.current_page + ":Back to game}")
This leads to a funny result: Link gets displayed as Start:Back to game (if variable contained Start).
If I click on the link, an error occurs stating that there's no page named Object. Apparently, my expression doesn't get interpreted correctly.
Can someone tell me how to fix either of those issues?
Thanks in advance.
PS. I can't find the AddPageLink()-function in the docs. Looked in functions, and javascript... Neiter contained that function.


On the latter one, you are trying to add strings together with the + operator, but one of them isn't a string.

game.current_page is apparently an object (page), so when it gets added to a string, it is converted to the string "Object: Start".
So the message that gets passed to the text processor is: "{page:Object: Start:Back to game}"

If you want the text to contain the name of the page, look at its name attribute.
So:

msg("{page:" + game.current_page.name + ":Back to game}")

UGH! Type convertion. Of course! (Should've used msg("" + game.current_page) to see the result first...)
Thanks. Feel like a moro now, but at least I can move on xD


ya, it's a bit confusing at first, especially for new people who don't know coding, in trying to learn/understand/deal-with Data Types (usually its using a Value without the double quotes, making it an Object reference/pointer Value instead of a String Value that they're trying to script with using and not understanding the differences/nuances between them in terms of with their scripting syntax --- see below example)

for example of your mistake with Types (Type Conversions):

create ("katana") // creates a 'katana' Object

player.weapon = katana // creates/sets an 'Object' (reference/pointer) Attribute

// CORRECT usages (Data Type Match):

if (player.weapon = katana) { /*scripting */ } // Object (reference/pointer) ~ ~ Object / Object (reference/pointer) --- gets more confusing with the internal structure / underlying code, lol (I think technically all of quest's internal structure / underlying code, are pointers/references, but I'm still a programming noobie with understanding this level of stuff --- don't really know/understand it that well yet --- it's still beyond me a bit)

// or:

if (player.weapon.name = "katana") { /*scripting */ } // String ~ String

// IN-correct usages (Data Type MIS-match):

if (player.weapon = "katana") { /*scripting */ } // Object (reference/pointer) ~ String

// or:

if (player.weapon.name = katana) { /*scripting */ } // String ~ Object / Object (reference/pointer) --- gets more confusing with the internal structure / underlying code, lol (I think technically all of quest's internal structure / underlying code, are pointers/references, but I'm still a programming noobie with understanding this level of stuff --- don't really know/understand it that well yet --- it's still beyond me a bit)


Converting Functions/Scripts between Objects and Strings:

STRING_VARIABLE = ToString (NAME_OF_OBJECT)
// and:
OBJECT_(POINTER/REFERENCE)_VARIABLE = GetObject ("NAME_OF_OBJECT") // the 'GetObject' Script/Function returns 'null' if no Object (of the inputted String Value) exists


other various Data Type Conversions:

http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)

// and also (NOT related to Type Conversions, but they're more built-in Scripts/Functions that are available for use): http://docs.textadventures.co.uk/quest/scripts/

(I might miss some things in my below list, so scan through especially the 'alphabetical order' link above, to see full list)

GetObject
ToString
ToInt
ToDouble

checking Data Types:

IsNumeric
IsInt
IsDouble
IsScript // err... maybe this was removed or it never existed
IsString // err... maybe this was removed or it never existed --- (quest might handle this automatically/internally for you)

DoesInherit // (Object Types /Types, and their use via/as Inherited Attributes --- these are like a user level's 'classes/groups')

TypeOf // returns the Type of the Value's/VARIABLE'S Data Type (string, int --- Integer, double, object, boolean, script, stringlist, objectlist, stringdictionary, objectdictionary, scriptdictionary, etc?)

// checking existence of an Attribute of a Specific Data Type

HasAttribute // this is the generic/dynamic (NOT specific), I think this will work with/for lists and dictionaries
HasObject
HasString
HasScript
HasBoolean
HasInt
HasDouble

// and lastly, there's also (it doesn't deal with Data Types, but it's useful for programmers who know how to use/work with it, as its one of quest's internal functionalities that can be very useful for programmers --- I still need to learn exactly how to use this, along with all of the regex stuff... HK is lazy, lots of things to learn with quest and programming in general, sighs):

eval // http://docs.textadventures.co.uk/quest/functions/eval.html


other useful/related links:

http://docs.textadventures.co.uk/quest/elements/ ('Elements' = Quest's OBJECTS:programming level, not to be confused with the sub/user-level's 'Object' Element, and the various other sub-types of Elements)

http://docs.textadventures.co.uk/quest/types/ (Data Types, at least the user's level, anyways --- see comment about the Elements above)

http://docs.textadventures.co.uk/quest/elements/object.html // the built-in Attributes for the 'Object' Element (gotten to from the 'object' hyperlink in the elements link above)

http://docs.textadventures.co.uk/quest/null.html (how quest handles/functionality of 'null')

http://docs.textadventures.co.uk/quest/asl_requirements.html (the quest software/engine has some requirements)

http://docs.textadventures.co.uk/quest/expressions.html (useful link)

http://docs.textadventures.co.uk/quest/scripts/setting_variables.html (useful link)

http://docs.textadventures.co.uk/quest/scopes.html (conveniently separated out --- found also within the 'Function' Links: alphabetical order and categorical order)

there's also these for generating/finding/populating/returning various Object Lists:

( http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html )

AllObjects ()
AllExits ()
AllCommands ()


and a lot of etc useful stuff (especially look through the 'Script', http://docs.textadventures.co.uk/quest/scripts/ , 'Function', http://docs.textadventures.co.uk/quest/functions/ or http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html , and the 'Object' Element's built-in Attributes, http://docs.textadventures.co.uk/quest/elements/object.html , links)


Thank you, will come in handy.


the 'HasXXX' just checks if the Attribute exists (if the Object has the Attribute or not --- it doesn't care at all about what the Value of the Attribute is)

whereas,

the 'GetXXX' not only checks if the Attribute exists, but ALSO, it checks the Value of the Attribute, as well


player.strength = 50

if (HasInt (player, "strength")) {
  msg ("Yes, the 'player' Object has a 'strength' Integer Attribute")
} else {
  msg ("Fail 1")
}

if (GetInt (player, "strength") = 100) {
  msg ("Yes, the 'player' Object has a 'strength' Integer Attribute with the Value of '100'")
} else {
  msg ("Fail 2")
}

// results:

Yes, the 'player' Object has a 'strength' Integer Attribute
Fail 2

// -------------------------------------

player.strength = 100
player.strength = null // (hehe)

if (HasInt (player, "strength")) {
  msg ("Yes, the 'player' Object has a 'strength' Integer Attribute")
} else {
  msg ("Fail 1")
}

if (GetInt (player, "strength") = 100) {
  msg ("Yes, the 'player' Object has a 'strength' Integer Attribute with the Value of '100'")
} else {
  msg ("Fail 2")
}

// results:

Fail 1
Fail 2

// -------------------------------------

player.strength = 100

if (HasInt (player, "strength")) {
  msg ("Yes, the 'player' Object has a 'strength' Integer Attribute")
} else {
  msg ("Fail 1")
}

if (GetInt (player, "strength") = 100) {
  msg ("Yes, the 'player' Object has a 'strength' Integer Attribute with the Value of '100'")
} else {
  msg ("Fail 2")
}

// results:

Yes, the 'player' Object has a 'strength' Integer Attribute
Yes, the 'player' Object has a 'strength' Integer Attribute with the Value of '100'

// ------------------

player.strength = 100

variable = HasInt (player, "strength")
msg (variable)

// result/display/output:

true

// ------------------

player.strength = 100
player.strength = null

variable = HasInt (player, "strength")
msg (variable)

// result/display/output:

false

// ------------------

player.strength = 100

variable = GetInt (player, "strength")
msg (variable)

// result/display/output:

100

// ------------------

player.strength = 50

variable = GetInt (player, "strength")
msg (variable)

// result/display/output:

null
// or:
// (it's blank: nothing is returned/outputted/displayed, aka null)

// ---------------

player.strength = 100
player.strength = null

variable = GetInt (player, "strength")
msg (variable)

// result/display/output:

null
// or:
// (it's blank: nothing is returned/outputted/displayed, aka null)

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

Support

Forums