Login
Remember
IF Answers
Ask a Question

# Is there an "object_is_room" function?

0 votes
119 views
asked Aug 2 in Authoring by anonymous

Both "room" and "object" have "type" and "elementtype" which are all "object" so that doesn't help. I don't see any attribute which is unique to one or the other that I could check.

- quest

## 1 Answer

0 votes
answered Aug 3 by hegemonkhan (161 points)
edited Aug 3 by hegemonkhan

unfortunately, no (at least not at the user level, no idea how the engine internally is coded).

the built-in Object Types (or shortened as: Types) 'editor room', 'editor object', and 'editor player', as their labels suggest, is just for the GUI~Editor itself, giving you the Tabs and their options~settings within using the GUI~Editor. When you play your game, these Object Types mean nothing (as they get removed~deleted upon playing the game), so don't mistake that you can use them for making your game, you can't use them for your game's scriptings.

fortunately, it is very easy to add~create your own such (direct) Attributes for your Objects, or (indirect Attributes, via) an Object Type (which can hold additional Attributes) which you give to your Object via its 'Inherit' Attribute, which you then check for in your scripting.

for example:

Using Direct Attributes:

'whatever' Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

    Attribute Name: type_of_object // you can label~name it as whatever you want

    Attribute Type: string // you don't have to use a String Attribute, but it's the most intuitive+practical+easy, so it's being used in this example.

    Attribute Value: (depends upon what the Object is that you're adding this Attribute to, for examples: room, npc, pc~player, items, equipment, weapon, armor, sword, shield, clothing, spell, furniture, table, chair, bed, tree, outdoor, environment, etc etc etc)

for example:

    (Object Name: dungeon_1)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: room // or whatever you want: 'area', 'place', 'location', 'sector', etc etc

    (Object Name: player)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: pc

    (Object Name: HK)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: pc

    (Object Name: barmaid_1)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: npc

    (Object Name: orc_1)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: monster

    (Object Name: hp_potion_1)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: item

    (Object Name: claymore)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: weapon

    (Object Name: fireball)
    Attribute Name: type_of_object
    Attribute Type: string
    Attribute Value: spell

and your scripting:

example (in code, sorry but it's quick and easy for me) using an Object's 'examine~look~description' Verb:

    if (HasString (this, "type_of_object") and this.type_of_object = "sector") {
      msg (this.alias + " is a location~place for you to explore, travel to, and~or travel from.")
    } else if (HasString (this, "type_of_object") and this.type_of_object = "pc") {
      msg (this.alias + " is a party member, so you can equip~unequip gear, cast spells, and~or use items with this character.")
    } else if (HasString (this, "type_of_object") and this.type_of_object = "npc") {
      msg (this.alias + " is a npc, and thus non-hostile, so you can talk with this character.")
    } else if (HasString (this, "type_of_object") and this.type_of_object = "monster") {
      msg (this.alias + " is a monster, and thus hostile, so you can only fight with this character, either gaining rewards if you win or losing the game if you get killed.")
    } else if (HasString (this, "type_of_object") and this.type_of_object = "table") {
      msg (this.alias + " is table, which you can use, place~put, or pick up~take items from it.")
    }
    // etc etc etc
    else {
      msg ("You can't do that with " + this.alias + ".")
    }

or, if you want to use Object Types (sorry, I'm getting a bit tired, so this will be fast):

(if you don't understand Object Types, then this won't help you much, as I'm assuming you do for this stuff, as I'm too tired to explain Object Types at the moment ~ ask if you need help in understanding Object Types, and I'll at a later date, help you with understanding and using them)

it's the same as above for the most part...

.1. create~add your Object Types (and optionally: any additional Attributes that the Object Type holds and~or other Object Types that it holds)

.2. add the Object Types to the proper Objects in your game (based on your design)

'whatever' Object -> 'Attributes' Tab -> Inherited Attributes -> Add -> (type in the name of your Object Type)

.3. the scripting:

basically it's simliar to the structure I gave above for direct Attribute usage, the only difference is that you use this:

'DoesInherit' ( http://docs.textadventures.co.uk/quest/functions/doesinherit.html )

instead of:

'HasAttribute', 'HasString', 'HasInteger', 'HasDouble', HasBoolean', etc etc etc

so, using my above direct Attribute usage example for using Object Types instead:

let's say I created Object Types named:

'room~sector~place~location~area'
'monster'
'pc'
'npc'
'item'
'weapon'
'armor'
'spell'
etc etc etc

    if (DoesInherit (this, "sector")) {
      // blah script(s)
    } else if (DoesInherit (this, "monster")) {
      // blah script(s)
    } else if (DoesInherit (this, "npc")) {
      // blah script(s)
    }
    // etc etc etc

commented Aug 3 by TM123 (1 point)
Thanks. Seems like a lot of work for one thing, but the object types would save time because I would need several attributes.
I came up with this which is pretty close to identifying a room, there would be a few exceptions:
boolean function HasExits(object)
return (ListCount(ScopeExitsForRoom(object)) > 0)
commented Aug 4 by hegemonkhan (161 points)
edited Aug 4 by hegemonkhan
in various situations, each of these 3 methods can be better than the other two, there's no 'always best' method, it depends.
generally about the 3 methods:
1. individually placing your Attributes on each of your Objects is the most work (highest character~symbol count, length~size of your game file), but it's the easiest~simpliest to do.
2. using Object Types reduces that work to a degree, less work, less length~size of game file, less character~symbol count, but Object Types are a bit more confusing initially, and they're much more limited in use, than with using scripting.
3. the least amount of work (in terms of character~symbol count, length~size of game file), is using the scripting to do most of the work for you, (in the most extreme usage, expert~professional level of coding ability) you'll have the quest engine set everything up for you at the beginning of the game, via scripting: Objects will be created and placed, Attributes will be created on those Objects, and etc etc etc. But, as I already mentioned, this is the most complex~challenging, you got to be really good at coding, to get it to all work correcty.
---------------------
about Object Types limited use:
Object Types are great for Objects that share the same Attributes and their Values, but for Objects having Attributes with different Values, Object Types aren't of much use, see below for an example:
---------------------
this is much better:
<object name="orc_1">
<inherit name="orc_object_type" />
</object>
<object name="orc_2">
<inherit name="orc_object_type" />
</object>
<object name="orc_3">
<inherit name="orc_object_type" />
</object>
<type name="orc_object_type">
<attr name="alias" type="string">orc</attr>
<attr name="type_of_object" type="string">monster</attr>
<attr name="dead" type="boolean">false</attr>
<attr name="strength" type="int">25</attr>
<attr name="endurance" type="int">25</attr>
<attr name="dexterity" type="int">25</attr>
<attr name="agility" type="int">25</attr>
<attr name="speed" type="int">25</attr>
<attr name="luck" type="int">25</attr>
</type>
--------
than this:
<object name="orc_1">
<attr name="alias" type="string">orc</attr>
<attr name="type_of_object" type="string">monster</attr>
<attr name="dead" type="boolean">false</attr>
<attr name="strength" type="int">25</attr>
<attr name="endurance" type="int">25</attr>
<attr name="dexterity" type="int">25</attr>
<attr name="agility" type="int">25</attr>
<attr name="speed" type="int">25</attr>
<attr name="luck" type="int">25</attr>
</object>
<object name="orc_2">
<attr name="alias" type="string">orc</attr>
<attr name="type_of_object" type="string">monster</attr>
<attr name="dead" type="boolean">false</attr>
<attr name="strength" type="int">25</attr>
<attr name="endurance" type="int">25</attr>
<attr name="dexterity" type="int">25</attr>
<attr name="agility" type="int">25</attr>
<attr name="speed" type="int">25</attr>
<attr name="luck" type="int">25</attr>
</object>
<object name="orc_3">
<attr name="alias" type="string">orc</attr>
<attr name="type_of_object" type="string">monster</attr>
<attr name="dead" type="boolean">false</attr>
<attr name="strength" type="int">25</attr>
<attr name="endurance" type="int">25</attr>
<attr name="dexterity" type="int">25</attr>
<attr name="agility" type="int">25</attr>
<attr name="speed" type="int">25</attr>
<attr name="luck" type="int">25</attr>
</object>
--------------------
HOWEVER, Object Types don't help much when those Attributes' Values are different:
(Attributes added to the Object, OVER-RIDE the Inherited Attributes'~Object Types' Values)
<object name="orc_grunt_1">
<inherit name="orc_object_type" />
<attr name="alias" type="string">orc grunt</attr>
</object>
<object name="orc_chief_1">
<inherit name="orc_object_type" />
<attr name="alias" type="string">orc chief</attr>
<attr name="strength" type="int">50</attr>
<attr name="endurance" type="int">50</attr>
<attr name="dexterity" type="int">50</attr>
<attr name="agility" type="int">50</attr>
<attr name="speed" type="int">50</attr>
<attr name="luck" type="int">50</attr>
</object>
<object name="orc_king_1">
<inherit name="orc_object_type" />
<attr name="alias" type="string">orc king</attr>
<attr name="strength" type="int">75</attr>
<attr name="endurance" type="int">75</attr>
<attr name="dexterity" type="int">75</attr>
<attr name="agility" type="int">75</attr>
<attr name="speed" type="int">75</attr>
<attr name="luck" type="int">75</attr>
</object>
<type name="orc_object_type">
<attr name="alias" type="string">orc</attr>
<attr name="type_of_object" type="string">monster</attr>
<attr name="dead" type="boolean">false</attr>
<attr name="strength" type="int">25</attr>
<attr name="endurance" type="int">25</attr>
<attr name="dexterity" type="int">25</attr>
<attr name="agility" type="int">25</attr>
<attr name="speed" type="int">25</attr>
<attr name="luck" type="int">25</attr>
</type>
----------------
so... Object Types are good for universal~general~same Attributes+their Values, which are more of the 'categorical grouping' type of Attributes, that are shared by Objects:
dead = false~true
status effect~condition = "normal~poisoned~petrified~paralyzed~stunned~etc"
locomotion = "bipedal~quadripedal~walking~standing~jumping~falling~running~etc"
activity = "reading~talking~sleeping~resting~fighting~stealing~bartering~etc"
type_of_object = "monster~item~spell~room~pc~npc~etc"
race = "elf~human~dwarf~etc"
class = "warrior~cleric~thief~mage~etc"
etc ec etc
than 'stat' type of Attributes (aka: mostly Integer Attributes), which often vary Object to Object:
strength = 0~100
hp = 0~999
etc etc etc
---------------------
Object Types help with attributes that are for~shared by a type of group of objects, but not with individual~independent attributes.
for example of groups of objects:
'humans', 'dwarves', 'elves', 'dragons', 'animals', 'plants', 'nekos', 'monsters', 'equipment', 'spells~magic', 'items', 'rooms', 'players~pcs', 'npcs', 'outdoor scenery: trees, plants', 'indoor scenery: furniture', etc etc etc
characteristic~trait~appearance~etc type of attributes, which are shared by the group, is what Object Types are for, but for attributes and their values not shared by a group, than Object Types aren't of much help.

## Related questions

- Is there an expression or script that addresses an attribute that is shared by all objects in a room (or the game)?
- Is there any way to paste code into the web version of Quest?
- Quest - Is there to "ScopeInventory" or "ScopeReachableInventory" that includes not visible items?
- Is there syntax to allow multiple expressions in the same script?
- Is there a known bug with commands not functioning?

...