Object Categories

Kaejer
26 May 2016, 00:31
Hi there,

I'm trying to figure out how to set something up so in a Turn Script, and potentially other things in the future, to auto populate a list based off of attributes I am using to categorize some objects I have.

Currently the situation is this:
I have provided a numerical listing of all of the people (objects set it be as an actual NPC) in an attribute. Originally, it was just going to be a boolean flag, but I wanted to differentiate them with a number instead so I went with an integer - variable "person". This also allows me to be able to able to make certain functions work on specific numerical ranges (certain NPCs).

I want to be able to create a new list in a Turn Script that automatically scans all objects and returns any object that has the attribute "person" so that I don't have to manually create a list for each function and update (unless there's a way to make a global list somehow with this, which would work too). This way it would filter down to only objects with the attribute "person" and then I can use an if statement with a literal expression to know which "person"s this Turn Script would effect.

Summary:
How to create a list of all objects with attribute "person"

Let me know if you need any other information,
Thank in advance!

HegemonKhan
26 May 2016, 02:41
links:

http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... reach.html

http://docs.textadventures.co.uk/quest/ ... jects.html
^^^^
http://docs.textadventures.co.uk/quest/ ... tions.html

-------

<function name="populate_npc_objectlist_function">
if (not HasAttribute (game, "npc_objectlist_attribute")) {
game.npc_objectlist_attribute = NewObjectList()
}
foreach (object_variable, AllObjects()) {
if (HasAttribute (object_variable, "person") {
list add (game.npc_objectlist_attribute, object_variable)
}
}
</function>


conceptually what the code above is doing:

if there is no npc list, create one. Then, you iterate (cycle) through all of the objects in the game, and check if they have the indicator/flag (Attribute and/or its Value), and if they do, then add them to the npc list. You can then use (such as iterating through) that npc list for doing whatever you want.

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

you may want to create a String Attribute like this instead (as this way below only requires/uses a single Attribute, instead of making many Attributes):

Object_name.type_of_object
// obviously replace 'Object_name' or 'object_1...X' with the actual names of your Objects, and/or use the special keyword, 'this', if/when you can.
// you can change 'type_of_object' to whatever you want, this is just the naming/labeling that I like to use for it

as then you can use it for this:

object_1.type_of_object = "person"
object_2.type_of_object = "npc"
object_3.type_of_object = "monster"
object_4.type_of_object = "environment"
object_5.type_of_object = "tree"
object_6.type_of_object = "building"
object_7.type_of_object = "room"
object_8.type_of_object = "dungeon"
object_9.type_of_object = "room_object"
object_10.type_of_object = "pc"
object_11.type_of_object = "player"
object_12.type_of_object = "player_object"
object_13.type_of_object = "item"
object_14.type_of_object = "cash"
object_15.type_of_object = "object"
object_16.type_of_object = "object_object"
object_17.type_of_object = "town"

if (this.type_of_object = "npc") {
-> // whatever Script(s)
} else if (this.type_of_object = "monster") {
-> // whatever Script(s)
} else if (this.type_of_object = "item") {
-> // whatever Script(s)
} else if (this.type_of_object = "room") {
-> // whatever Script(s)
}
// etc etc etc

---------

and if you're able to work with List/Dictionary Attributes well, you can use them instead of a String Attribute, allowing you to check for multiple indicators/flags:

object_1.type_of_object_list = split ("spell;fire", ";")
object_1.type_of_object_list = split ("spell;water", ";")
object_2.type_of_object_list = split ("weapon; equipment", ";")
object_3.type_of_object_list = split ("weapon; equipment; melee", ";")
object_4.type_of_object_list = split ("weapon; equipment; ranged", ";")
object_5.type_of_object_list = split ("weapon; equipment; two_handed", ";")
object_6.type_of_object_list = split ("weapon; equipment; one_handed", ";")
object_7.type_of_object_list = split ("weapon; equipment; one_handed; melee", ";")
object_8.type_of_object_list = split ("weapon; equipment; one_handed; ranged", ";")
object_9.type_of_object_list = split ("weapon; equipment; two_handed; melee", ";")
object_10.type_of_object_list = split ("weapon; equipment; two_handed; ranged", ";")
object_11.type_of_object_list = split ("armor; equipment", ";")
object_12.type_of_object_list = split ("spell; fire; item", ";")
object_13.type_of_object_list = split ("item; normal", ";")
object_14.type_of_object_list = split ("item; battle", ";")
object_15.type_of_object_list = split ("item; quest", ";")
object_16.type_of_object_list = split ("item; map", ";")
// etc etc etc

if (ListContains (this.type_of_object_list, "spell")) {
-> whatever Script(s)
} else if (ListContains (this.type_of_object_list, "spell") and ListContains (this.type_of_object, "item")) {
-> whatever Script(s)
}
// etc etc etc

The Pixie
26 May 2016, 07:04
Like this:
lst = NewObjectList()
foreach (o, AllObjects()) {
if (HasInt(o, "person")) {
if (o.person = value) {
list add(lst, o)
}
}
}

The first line creates a new list, called lst, to which all the NPCs will be added. Then we start a loop that will go through every object in the game. For each object, does it have a "person" attribute? Is the value of the attribute value (obviously set that to the number required beforehand)? If so, add to the list.

If you are not familiar with code, this page explains how to paste it into your game.
http://docs.textadventures.co.uk/quest/ ... _code.html

Personally I would put that in a function, and have it return an object list, with "value" as a parameter.

Kaejer
29 May 2016, 18:19
Thank you all for your help, this is assisted me in more ways than one :D.

HegemonKhan
29 May 2016, 21:03
here's a good demonstration of uing the different Types of Attributes:

RPG conditions:

poisoned, stunned, asleep, paralyzed, petrified, muted/silenced, dead, unconscious, crippled/disabled, normal, intoxicated/drugged, sick/diseased, etc etc etc

UGLY design (uses many Attributes), but it (Boolean Attributes: true/false) is very simple to understand and use:

player.poisoned = (false/true)
player.stunned = (false/true)
player.asleep = (false/true)
player.(muted/silenced) = (true/false)
player.dead = (true/false)
etc etc etc

you're not poisoned:

player.poisoned = false

you're not poisoned and not paralyzed:

player.poisoned = false
player.paralyzed = false

you're not poisoned but you are paralyzed:

player.poisoned = false
player.paralyzed = true

you're poisoned but not paralyzed:

player.poisoned = true
player.paralyzed = false

you're poisond and paralyzed:

player.poisoned = true
player.paralyzed = true

you're poisoned, paralyzed, petrified, crippled, and silenced, but not stunned:

player.poisoned = true
player.paralyzed = true
player.petrified = true
player.crippled = true
player.slenced = true
player.stunned = false

etc etc etc combinations...

much better design (only uses a single Atribute) but limited to only having a single condition and it's concept usually isn't understood by new peeple:

String Attribute: string comparison, for example: if (player.condition = "poisoned") { player.life = player.life - 50 } // if (player.condition: "poisoned" = "poisoned") -> TRUE, VS, if (player.condition: "asleep" = "poisoned") -> FALSE, as this string comparison stuff is a coding/programming concept.

player.condition = "(poisoned/stunned/etc etc etc)"

player.condition = "normal"
OR
player.condition = "poisoned"
OR
etc etc etc, you can only have a single condition at a time

much better design (but lists are much more advanced/difficult to understand/use for new poeple), and able to have multiple conditions:

you get/are normal:

player.condition_list = split ("normal", ";")

you get/are poisoned and petrified:

player.condition_list = split ("poisoned; petrified", ";")

or, you get/are dead, crippled, and paralyzed:

player.condition_list = split ("dead; crippled; paralyzed", ";")

etc etc etc