Proper way to use if DoesInherit

lightwriter
if (DoesInherit (player.character, "True")) {
msg ("It's nice to meet you" + player.playername + " who is a " + player.gender + "and controls"+ player.class ".")
}

I used this as a guide http://docs.textadventures.co.uk/quest/guides/using_types.html
wondering if it was how it used to be in an old version.
I also looked at this but don't understand the format:
http://docs.textadventures.co.uk/quest/functions/doesinherit.html
Basically, I want something if player.character = true then it does 1 thing
and if false then do something else.

jaynabonne
If that's all you want, then it's how you informally said it:

if (player.character) {
msg ("It's nice to meet you" + player.playername + " who is a " + player.gender + "and controls"+ player.class ".")
}


I'm assuming you don't mean "True" as in the string "True" but just the boolean values true/false. If you do mean it as a string, then you'd have to do

if (player.character = "True")


If you don't know if "character" will be set initially, you can also do this, which is handy:

if (GetBoolean(player, "character") {
msg ("It's nice to meet you" + player.playername + " who is a " + player.gender + "and controls"+ player.class ".")
}

GetBoolean returns false if the attribute is not set at all, otherwise the true/false value it contains.

To your original question, DoesInherit is used when you have objects that have base types. You can then see if an object inherits from a base type. If you're not using types, then that probably doesn't mean much!

TinFoilMkIV
Is player.character it's own object or an attribute of the player object?

It looks to me like you're using the wrong input for the DoesInherit function

Assuming you're trying to check if the player is inheriting the 'character' type, then it should look something like this
if (DoesInherit (player, "character")) {
// this returns 'true' to the 'if' statement when the player has inherited type 'character'
msg ("It's nice to meet you" + player.playername + " who is a " + player.gender + "and controls"+ player.class ".")
}

lightwriter
oh, ok, so how do I check if a boolean is true or false?
See when I first did the = it says it couldn't work for a string or boolean but I must've forgotten the quotation marks around 'True'
Now how would I go about re-running the script if the player selects false and wants to re-enter info such as name and gender?

jaynabonne
I showed you examples above of checking boolean, so I'm not sure what you're asking... (I would just give you the same answer, though I could change the names a bit).

To check if an attribute is true:

if (someobject.someattribute) {
}

To check if an attribute is false:

if (not someobject.someattribute) {
}


You might have gotten the error before if you didn't pre-define the attribute, setting it to some value like false. That's where GetBoolean comes in handy, as the attribute doesn't have to be defined ahead of time.

if (GetBoolean(someobject, "someattribute")) {
}

TinFoilMkIV
'GetBoolean' is probably your best bet here. It will check for a 'true' value in a boolean attribute, however it will still return false if the attribute is anything other than 'true' whether or not the actual value is 'false'.

That being said, considering a boolean case can only ever be true or false, there should only be two case, an if(true) and then an else. The 'GetBoolean' function should be sufficient here. If you absolutely must be sure that the value is either true or false and not something completely unrelated, you can use a 'HasBoolean' to check that the attribute you're looking for is indeed a boolean value.

HegemonKhan
you got your Attributes:

Object_name.Attribute_name = Value_or_Expression

String Attribute: Object_name.Attribute_name = "Value" // or: = Expression // (the textual~string parts require double quotes)
example 1: player.sex = "male"
example 2: game.greeting = "Hi, " + player.alias + ". You're going to lose, muwahaha! This game is very difficult!"

Object Attribute: Object_1_name.Attribute_name = Object_2_name // except 'true' and 'false', as these are reserved for Boolean Attribute's Values
example 1: player.right_hand = sword
example 2: player.parent = room

Boolean Attribute: Object_name.Attribute_name = false // or: true
example 1A: orc.dead = false
example: 1B: orc.dead = true
example 2A: player.flying = false
example 2B: player.flying = true

Integer Attribute: Object_name.Attribute_name = 5 // or whatever integer (non-decimal) number // or: = Expression
example 1: player.strength = 100
example 2: player.damage = player.claymore.damage + player.claymore.damage * player.strength / 100

Double (Float ~ Floating Point) Attribute: Object_name.Attribute_name = 5.00 // or whatever decimal number // or: = Expression
example 1: player.damage = 67.23
example 2: player.damage = player.claymore.damage + player.claymore.damage * player.strength / 100

Stringlist Attribute: Object_name.Attribute_name = split ("item~choice~option1;item~choice~option2;item~choice~option3;etc", ";")
example 1: global_data_object.sex_stringlist_attribute = split ("male;female", ";")
example 2: HK.favorite_colors_stringlist_attribute = split ("black;red", ";")
example 3: game.season_stringlist_attribute = split ("winter;spring;summer;autumn", ";")
example 4: player.condition_stringlist_attribute = split ("poisoned;confused", ";")

Objectlist Attribute: Object_name.Attribute_name = split ("item~choice~option1;item~choice~option2;item~choice~option3;etc", ";")

example:

weapon_shop.sword_objectlist_attribute = split ("short_sword;long_sword;broad_sword;claymore;katana;rapier;scimitar;cutlass;saber;machete;flamberge", ";")
<object name="short_sword">
</object>
<object name="long_sword">
</object>
<object name="broad_sword">
</object>
<object name="claymore">
</object>
<object name="katana">
</object>
<object name="rapier">
</object>
<object name="scimitar">
</object>
<object name="cutlass">
</object>
<object name="saber">
</object>
<object name="machete">
</object>
<object name="flamberge">
</object>


---------

to refer+check+act to~on them:

OPERATORS: '=', '>', '<', '<=', '>=', and ( '<>' or 'not xxx = xxx' )
(there is no '==', the '=' does both functionalities in quest: the engine handles the parsing for you)

if (Object_name.Attribute_name OPERATOR Value_or_Expression) {
Object_name.Attribute_name = Value_or_Expression
} else if (Object_name.Attribute_name OPERATOR Value_or_Expression) {
Object_name.Attribute_name = Value_or_Expression
} else {
Object_name.Attribute_name = Value_or_Expression
}


----------

Object Types:

http://docs.textadventures.co.uk/quest/ ... /type.html

The 'Object Type' Element holds Attributes and~or other Object Types. Think of it as a basket that holds eggs, so instead of giving each Object indivually each 'egg' (Attribute), you can instead give each Object the basket (Object Type):

<object name="player">
<attr name="locomotion_stringlist_attribute" type="simplestringlist">bipedal;standing</attr>
<attr name="condition_stringlist_attribute type="simplestringlist">alive;normal</attr>
<attr name="head_quantity_integer_attribute" type="int">1</attr>
<attr name="head_quantity_string_attribute" type="string">one</attr>
<attr name="arm_quantity_string_attribute" type="string">two</attr>
<attr name="arm_quantity_integer_attribute" type="int">2</attr>
<attr name="eye_quantity_integer_attribute" type="int">1</attr>
<attr name="eye_quantity_string_attribute" type="string">one</attr>
<attr name="skin_type_string_attribute" type="string">skin</attr>
</object>

<object name="orc">
<attr name="locomotion_stringlist_attribute" type="simplestringlist">bipedal;standing</attr>
<attr name="condition_stringlist_attribute type="simplestringlist">alive;normal</attr>
<attr name="head_quantity_integer_attribute" type="int">1</attr>
<attr name="head_quantity_string_attribute" type="string">one</attr>
<attr name="arm_quantity_string_attribute" type="string">two</attr>
<attr name="arm_quantity_integer_attribute" type="int">2</attr>
<attr name="eye_quantity_integer_attribute" type="int">1</attr>
<attr name="eye_quantity_string_attribute" type="string">one</attr>
<attr name="skin_type_string_attribute" type="string">skin</attr>
</object>


VS

<object name="player">
<inherit name="humanoid_object_type" />
</object>

<object name="orc">
<inherit name="humanoid_object_type" />
</object>

<type name="humanoid_object_type">
<attr name="locomotion_stringlist_attribute" type="simplestringlist">bipedal;standing</attr>
<attr name="condition_stringlist_attribute type="simplestringlist">alive;normal</attr>
<attr name="head_quantity_integer_attribute" type="int">1</attr>
<attr name="head_quantity_string_attribute" type="string">one</attr>
<attr name="arm_quantity_string_attribute" type="string">two</attr>
<attr name="arm_quantity_integer_attribute" type="int">2</attr>
<attr name="eye_quantity_integer_attribute" type="int">1</attr>
<attr name="eye_quantity_string_attribute" type="string">one</attr>
<attr name="skin_type_string_attribute" type="string">skin</attr>
</type>


-----------------------

to refer+check+act to~on them:

http://docs.textadventures.co.uk/quest/ ... herit.html

example (using the above example, and pretend I made 'animal' Object Type too):

if (DoesInherit (player, "humanoid_object_type")) {
msg ("You are a humanoid.")
} else if (DoesInherit (player, "animal_object_type")) {
msg ("You are an animal.")
} else {
msg ("You are an alien.")
}


and you can do as many layers deep as you want, and checking on both Object Type and its Attributes:

if (DoesInherit (monster_99, "humanoid_object_type")) {
if (monster_99.head_quantity_integer-attribute = 0) {
msg (monster_99.alias + " got decapitated by you.")
}
} else if (DoesInherit (monster_99, "animal_object_type")) {
if (monster_99.animal_type_string_attribute = "dog") {
if (monster_99.head_quantity_integer-attribute = 3) {
msg (monster_99.alias + " is the Kerberus of Greek Mythology.")
} else if (monster_99.head_quantity_integer-attribute = 1) {
msg (monster_99.alias + " is just an ordinary, but rabid, dog.")
}
} else if (monster_99.animal_type_string_attribute = "cat") {
msg (monster_99.alias + " is just an ordinary cat.")
}
} else {
msg (monster_99.alias + " is an alien.")
}

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

Support

Forums