Classes and types and base objects... (oh my!)

K.V.
29 Aug 2017, 03:35

Okay....

  1. Type
  • I make a type with attributes.
  • I make and object of that type, than enable the attributes which are darkened out?
  1. classes
  • no idea
  1. base objects
  • Mmmm...
  • Yeah... No clue.

@HK

I figured I'd start a new thread, instead of totally taking over Anthony the Tiger's thread.


Okay.

Somebody hit me with something.

Links. Examples. Theories...

I'm ready.


hegemonkhan
29 Aug 2017, 04:07

well, in quest at the user level, it's much more simple:

Object Types / Types / Inherited Attributes

think of an Object Type basically as a basket of eggs (Attributes), so instead of manually giving/handing an Object, an egg by an egg (Attribute by Attribute), you can just give the Object a basket (an Object Type, via as an Inherited Attribute).


for example, not using an Object Type (YUCK!):

<object name="player_1">
  <inherit name="editor_object" />
  <inherit name="editor_player" />
  <attr name="parent" type="object">player_data_room_object</attr>
  <attr name="alias" type="string">unknown</attr>
  <attr name="strength" type="int">0</attr>
  <attr name="endurance" type="int">0</attr>
  <attr name="dexterity" type="int">0</attr>
  <attr name="agility" type="int">0</attr>
  <attr name="speed" type="int">0</attr>
  <attr name="luck" type="int">0</attr>
  <attr name="look" type="script">
    // blah scripting
  </attr>
  <attr name="pov_look" type="script">
    // blah scripting
  </attr>
  <attr name="current_level" type="int">0</attr>
  <attr name="maximum_level" type="int">0</attr>
  <attr name="minimum_currency" type="int">0</attr>
  <attr name="maximum_currency" type="int">0</attr>
  <attr name="current_experience" type="int">0</attr>
  <attr name="maximum_experience" type="int">0</attr>
  <attr name="life" type="string">unknown</attr>
  <attr name="current_life" type="int">0</attr>
  <attr name="maximum_life" type="int">0</attr>
  // etc etc etc common/universal/shared Attributes amongst your Player Objects
</object>

<object name="player_2">
  <inherit name="editor_object" />
  <inherit name="editor_player" />
  <attr name="parent" type="object">player_data_room_object</attr>
  <attr name="alias" type="string">unknown</attr>
  <attr name="strength" type="int">0</attr>
  <attr name="endurance" type="int">0</attr>
  <attr name="dexterity" type="int">0</attr>
  <attr name="agility" type="int">0</attr>
  <attr name="speed" type="int">0</attr>
  <attr name="luck" type="int">0</attr>
  <attr name="look" type="script">
    // blah scripting
  </attr>
  <attr name="pov_look" type="script">
    // blah scripting
  </attr>
  <attr name="current_level" type="int">0</attr>
  <attr name="maximum_level" type="int">0</attr>
  <attr name="minimum_currency" type="int">0</attr>
  <attr name="maximum_currency" type="int">0</attr>
  <attr name="current_experience" type="int">0</attr>
  <attr name="maximum_experience" type="int">0</attr>
  <attr name="life" type="string">unknown</attr>
  <attr name="current_life" type="int">0</attr>
  <attr name="maximum_life" type="int">0</attr>
  // etc etc etc common/universal/shared Attributes amongst your Player Objects
</object>

<object name="player_3">
  <inherit name="editor_object" />
  <inherit name="editor_player" />
  <attr name="parent" type="object">player_data_room_object</attr>
  <attr name="alias" type="string">unknown</attr>
  <attr name="strength" type="int">0</attr>
  <attr name="endurance" type="int">0</attr>
  <attr name="dexterity" type="int">0</attr>
  <attr name="agility" type="int">0</attr>
  <attr name="speed" type="int">0</attr>
  <attr name="luck" type="int">0</attr>
  <attr name="look" type="script">
    // blah scripting
  </attr>
  <attr name="pov_look" type="script">
    // blah scripting
  </attr>
  <attr name="current_level" type="int">0</attr>
  <attr name="maximum_level" type="int">0</attr>
  <attr name="minimum_currency" type="int">0</attr>
  <attr name="maximum_currency" type="int">0</attr>
  <attr name="current_experience" type="int">0</attr>
  <attr name="maximum_experience" type="int">0</attr>
  <attr name="life" type="string">unknown</attr>
  <attr name="current_life" type="int">0</attr>
  <attr name="maximum_life" type="int">0</attr>
  // etc etc etc common/universal/shared Attributes amongst your Player Objects
</object>

vs using an Object Type (much better!):

<type name="player_type">
  <inherit name="editor_object" />
  <inherit name="editor_player" />
  <attr name="parent" type="object">player_data_room_object</attr>
  <attr name="alias" type="string">unknown</attr>
  <attr name="strength" type="int">0</attr>
  <attr name="endurance" type="int">0</attr>
  <attr name="dexterity" type="int">0</attr>
  <attr name="agility" type="int">0</attr>
  <attr name="speed" type="int">0</attr>
  <attr name="luck" type="int">0</attr>
  <attr name="look" type="script">
    // blah scripting
  </attr>
  <attr name="pov_look" type="script">
    // blah scripting
  </attr>
  <attr name="current_level" type="int">0</attr>
  <attr name="maximum_level" type="int">0</attr>
  <attr name="minimum_currency" type="int">0</attr>
  <attr name="maximum_currency" type="int">0</attr>
  <attr name="current_experience" type="int">0</attr>
  <attr name="maximum_experience" type="int">0</attr>
  <attr name="life" type="string">unknown</attr>
  <attr name="current_life" type="int">0</attr>
  <attr name="maximum_life" type="int">0</attr>
  // etc etc etc common/universal/shared Attributes amongst your Player Objects
</type>

<object name="player_1">
  <inherit name="player_type" />
</object>

<object name="player_2">
  <inherit name="player_type" />
</object>

<object name="player_3">
  <inherit name="player_type" />
</object>

you can also over-ride/over-write inherited Attributes too (or if you want to be able to manipulate those Inherited Attributes, you MUST over-ride / over-write them first, before you can then manipulate/change/adjust/alter them):

<type name="player_type">
  <inherit name="editor_object" />
  <inherit name="editor_player" />
  <attr name="parent" type="object">player_data_room_object</attr>
  <attr name="alias" type="string">unknown</attr>
  <attr name="strength" type="int">0</attr>
  <attr name="endurance" type="int">0</attr>
  <attr name="dexterity" type="int">0</attr>
  <attr name="agility" type="int">0</attr>
  <attr name="speed" type="int">0</attr>
  <attr name="luck" type="int">0</attr>
  <attr name="look" type="script">
    // blah scripting
  </attr>
  <attr name="pov_look" type="script">
    // blah scripting
  </attr>
  <attr name="current_level" type="int">0</attr>
  <attr name="maximum_level" type="int">0</attr>
  <attr name="minimum_currency" type="int">0</attr>
  <attr name="maximum_currency" type="int">0</attr>
  <attr name="current_experience" type="int">0</attr>
  <attr name="maximum_experience" type="int">0</attr>
  <attr name="life" type="string">unknown</attr>
  <attr name="current_life" type="int">0</attr>
  <attr name="maximum_life" type="int">0</attr>
  // etc etc etc common/universal/shared Attributes amongst your Player Objects
</type>

<object name="player_1">
  <inherit name="player_type" />
  <attr name="strength" type="int">100</attr>
</object>

<object name="player_2">
  <inherit name="player_type" />
</object>

<object name="player_3">
  <inherit name="player_type" />
</object>

// results:

Player 1 Strength: 100 // the '100' Value replaces the Inherited '0' Value, as you over-rode/over-written the Inherited Attribute
Player 2 Strength: 0
Player 3 Strength: 0

// also:

player_1.strength = player_1.strength + 1 // NO error, as since we over-ridden/over-wrote the Inherited Attribute, we can now do this manipulation of it.

player_2.strength = player_2.strength + 1 // ERROR!!! Inherited Attributes are blocked-off from being manipulated/changed!!!

Object Types / Types / Inherited Attributes:

really useful for Script Attributes, as usually these are universally the same for their related Objects, and you can use the 'this' key-word/key-command as well too (works wonderfully with Object Types)

Some non-Script Attributes are universal/shared in their Values across related Objects (for example, for monster types of Objects, usually for simple designs, you use a 'dead' Boolean Attribute, and thus all of them start of as 'alive', aka: 'false' for their initial Value), but most non-Script Attributes are individual for each related Object, so generally not too great for using with Object Types (unless you want to ensure they have an Attribute, instead of using scripting to check if they have an Attribute, and create it if they don't).

Also, if you don't use the 'cloning' feature, then Object Types are good with Attributes (if you want your Objects to be the exact same):

<type name="orc_type">
  <attr name="strength" type="int">10</attr>
  <attr name="endurance" type="int">10</attr>
  <attr name="dexterity" type="int">10</attr>
  <attr name="agility" type="int">10</attr>
  <attr name="speed" type="int">10</attr>
  <attr name="luck" type="int">10</attr>
</type>

<object name="orc_1">
  <inherit name="orc_type" />
</object>

<object name="orc_2">
  <inherit name="orc_type" />
</object>

<object name="orc_3">
  <inherit name="orc_type" />
</object>

<type name="orc_king_type">
  <attr name="strength" type="int">20</attr>
  <attr name="endurance" type="int">20</attr>
  <attr name="dexterity" type="int">20</attr>
  <attr name="agility" type="int">20</attr>
  <attr name="speed" type="int">20</attr>
  <attr name="luck" type="int">20</attr>
</type>

<object name="orc_king_1">
  <inherit name="orc_king_type" />
</object>

<object name="orc_king_2">
  <inherit name="orc_king_type" />
</object>

<object name="orc_king_3">
  <inherit name="orc_king_type" />
</object>

<type name="ogre_type">
  <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>
</type>

<object name="ogre_1">
  <inherit name="ogre_type" />
</object>

<object name="ogre_2">
  <inherit name="ogre_type" />
</object>

<object name="ogre_3">
  <inherit name="ogre_type" />
</object>

<type name="ogre_magi_type">
  <attr name="strength" type="int">100</attr>
  <attr name="endurance" type="int">100</attr>
  <attr name="dexterity" type="int">100</attr>
  <attr name="agility" type="int">100</attr>
  <attr name="speed" type="int">100</attr>
  <attr name="luck" type="int">100</attr>
</type>

<object name="ogre_magi_1">
  <inherit name="ogre_magi_type" />
</object>

<object name="ogre_magi_2">
  <inherit name="ogre_magi_type" />
</object>

<object name="ogre_magi_3">
  <inherit name="ogre_magi_type" />
</object>

hegemonkhan
29 Aug 2017, 04:43

if you're talking about actual programming learning:

DATA STRUCTURES, OBJECT-Oriented Programming (OOP) / OBJECT-Oriented Design (OOD), CLASSES, OBJECTS/INSTANCES, INSTANTIATION, declaration, initializing, ENCAPSULATION, INHERITANCE, POLYMORPHISM, and ETC

this is actually how the quest software is created and how it allows you to create your own library files (including your own engine library files), its actual underlying code (not the built-in user-level stuff): https://github.com/textadventures/quest --- notice how the code looks a lot like the stuff you read about in your research/learning of the 3 main full-bore programming languages:

http://www.cplusplus.com/doc/tutorial/classes/
https://www.tutorialspoint.com/cplusplus/cpp_classes_objects.htm

https://docs.oracle.com/javase/tutorial/java/javaOO/
https://www.tutorialspoint.com/java/java_object_classes.htm

https://docs.python.org/3/tutorial/classes.html
https://www.learnpython.org/en/Classes_and_Objects

(there's A LOT MORE to using/learning these full-bore programming languages, and actually, you should NOT be starting with this stuff... as it's a lot more advanced than scripting... most first intro programming classes have you learn a language's scripting first, then they get into learning the stuff in the links above, over 1 to 2 classes, for each language. 1 to 2 classes to learn C++, 1 to 2 classes to learn Java, 1 to 2 classes to learn Python. And this is just learning the "basics" of these 3 programming languages: their scripting: "hello world" output/displayment, formatting output/displayment, VARIABLES, 'if', 'switch', looping, iteration, 'for', 'foreach', Functions, 'while', 'do while', terminators, recursion, input/output, displayment, and their Object-Oriented Programming/Design: Encapsulation, Inheritance, Polymorphism, CLASSES, OBJECTS, INSTANTIATING, pointers, constructors, destructors, structures / structs, arrays, lists, matrix'es, dictionaries, error and exception handling / 'throw/catch', etc etc etc)

(then, you learn Data Structures Design / Data Management Design as a class: linked lists, abstract data structures, trees, maps, dictionaries, stacks, queues, etc)

(then, you learn Assembly Language and "basic" Computer-Architecture/Digital-Design/Circuitry/logic-gates/computer-parts-components/half-adders/full-adders/multiplexors-mutex/registers/combinational-circuits/sequential-circuits/etc, etc etc etc)

(then you're done with lower division classes... lol...now you got upper division classes to do, which I don't know, as I'm still stuck on Data Structures and Assembly Language and Computer Architecture, sighs. I do know that there's more classes on computer architecture and probably/definitely mathematical/theory programming classes too... I hate math!!!...)

this is the Computer Science (CS) field/major: the 'programming' (and beyond: everyone can program and be a programmer, but not everyone can program well --- this is what you learn from CS, becoming: a software engineer, an expert programmer, not an amateur programmer, which everyone can be/learn/do on their own) field/major, you can then if you want branch out into whatever specializations (A.I., neurological: man-machine, theorists, etc etc etc. I don't really know the field/s that well, lol)


The Pixie
29 Aug 2017, 07:13

Types are how Quest implements classes; they are not the same, but equivalent. Types have attributes just as objects do, and any object that inherits from a type will get all those attributes. ~If it inherits multiple types, and those types have the same attributes, the type listed later will take priority. Any attribute that is inherited will be in grey, any attribute specific t the object will be black.

Not sure about base objects. Where have you seen hem mentioned?


hegemonkhan
29 Aug 2017, 07:27

@ Pixie:

one poster was talking of 'base objects' in some other thread, I thought the poster was talking about quest's underlying OBJECTS (its Attribute Types and Elements).

but in a later post by the poster, I think they were just talking about the Object Types, if I understood their later post.

HK edit: found it: http://textadventures.co.uk/forum/quest/topic/zhzl_m8hd0qoookndtqrqq/inheriting-commands-from-the-direct-parent-object-is-it-possible


hegemonkhan
29 Aug 2017, 07:48

P.S.

@ KV:

here's an earlier post from the other thread that is similar to the one that I posted/wrote here:

http://textadventures.co.uk/forum/quest/topic/sy2qb0ng9umzw-eyefe6ag/why-does-showmenu-lose-variable-contents#5c26e6ad-c972-42f9-a9b7-91043a772bb5

might have some bits different, so might be of some informational value


K.V.
31 Aug 2017, 09:34

Okay, so types just have the attributes sort of 'on retainer', and you just have to enable them instead of setting each one up on each similar object?


K.V.
31 Aug 2017, 10:15

Not sure about base objects. Where have you seen them mentioned?

Yeah, it was that link HK posted. I was trying to make a command in a room, then put rooms in that room that would inherit the command.

I just ended up making a command and dropping it inside of an object, then using your script from that thread to move it to the main room's parent object when I wanted it to be there. (Why didn't I just use IF...THEN... to limit the command? That's no fun at all, is it?)


So are commands, exits, and verbs classes?


The Pixie
31 Aug 2017, 10:45

So are commands, exits, and verbs classes?

It is very simple. There are two types of type. Every object has a single type, but can have several inherited types, some of which may be inherited from other inherited types.

Each command is an object (look at the "elementtype" attribute for a command), of the "command" type. Commands all have the "defaultcommand" inherited type.

Same for exits, but they have several inherited types.

Verbs are actually commands, so are objects of the command type, and have "defaultcommand" and defaultverb" inherited types.

In case you are wondering, rooms are objects of the object type, with the "defaultobject" inherited type.


hegemonkhan
31 Aug 2017, 11:34

in/for quest, at the user-level, as Pixie stated, Object Types / Types, are somewhat like classes.

in quest's underlying code, yes, it uses CLASSES, and its OBJECTS are called 'Elements' (Objects, Exits, Verbs, Commands, Functions, Turnscript, Timer, Object Types, etc):

https://github.com/textadventures/quest/blob/master/WorldModel/WorldModel/Element.cs (look for anything with the 'class', specifically, find the: 'class Element')