Attributes and 'IF' Script Guide by HK

HegemonKhan
I dug this up~out of mine from some post buried in the forum, hopefully, it'll be of some use to people

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

HK's Attribute Comprehensive Guide:

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

within your question, due to not understanding Attributes (not your fault), you're describing a bit of a conflict between whether to use an Object, an Attribute, or an Object+Attribute.

So, let's just use an Attribute, as that is what you want to learn about using. Thus there's no 'dropping' as there's no 'item' (an Object) involved.

-----------

I like to describe quest's (and many other) code structure(s) in this way:

real world's tri-structure:

1. matter: the physical stuff, examples: 'HK' and 'Exekieljd'
2. energy~forces~waves: actions, example: talking
3. traits~characteristics~properties~data~info: male (HK is a male) or wet (water is wet) or bright (the sun is bright)

human's English language's tri-structure:

1. nouns
2. verbs
3. adjectives and~or adverbs

quest's code tri-structure:

Object-Oriented Programming (OOP)

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

1. OOP's OBJECTS: Elements (Objects, Exits, Functions, Verbs, Commands, Turnscripts, Timers, Object Types, etc): http://docs.textadventures.co.uk/quest/elements/

ya, the terminology is a bit confusing at this more technical level (hence my use of all caps OBJECT vs quest's Object), all you need to know is that the Elements (Objects, Exits, Verbs, Functions, etc) are your 'physical things', an Object is just one of those 'physical things'.

Objects: holds~contains Attributes and~or other Objects

Exits: connectors of Room Objects, holds~contains Attributes

Functions: holds~contains scripting and Attributes

Verbs: local ~ individual Object's Script Attributes: holds~contains scripting. Technically, this is actually a specialized (individual Objects) sub-Command

Commands: global, able to use input by the person playing the game, holds~contains scripting and Attributes

Turnscripts: basically (depending on the settings) an always activating~executing~running Function, on the quest engine's 'turn' underlying code

Timers: same as Turnscripts, except uses real time (seconds) for when (at intervals) it activates~executes~runs

Object Types: holds~contains Attributes and~or other Object Types (as Inherited Attributes)

etc Elements: too lazy to get into them

four types of Objects:

(1) Game Object: the 'game' Game Object: a special Object, which contains~holds the global settings (Attributes) for your game
(2) Player Objects: the controllable Objects (RPG term: pcs: playable characters) by the person playing the game: the default is the 'player' Player Object
(3) Room Objects: self-explanatory functionality (Exits connect Room Objects)
(4) (Other: non-player, non-room) Objects: these are everything else: npcs (RPG term: non-playable characters), furniture, trees, RPG items, equipment, etc

(5) 'Other'+Room Objects: have both functionalities

example of Objects and their Attributes:

<object name="room">
<inherit name="editor_room" />
<alias>home</alias>
<description>This is HK's home.</description>
<attr name="tidyness_state_string_attribute" type="string">messy</attr>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<alias>HK</alias>
<attr name="sex_string_attribute" type="string">male</attr>
<object name="sword_1">
<inherit name="editor_object" />
<alias>claymore</alias>
<attr name="damage_integer_attribute" type="int">50</attr>
</object>
</object>
</object>


the special 'game' Game Object in code below, corresponds to the GUI~Editor's:

'game' Game Object ( left side's 'tree of stuff', click on it to highlight~choose it ) -> (right side) -> various Tabs -> various options~settings (Attributes)

<game name="xxx">
<gameid>xxx</gameid>
<firstpublished>2015</firstpublished>
<version>1.0</version>
<author>xxx</author>
<category>xxx</category>
<description>xxx</description>
<subtitle>xxx</subtitle>
// etc Attributes
</game>


2. Scriptings (code lines of action~events):

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

the main containers of scriptings:

(GUI~Editor: run as script -> add a~new script -> etc)

(Objects) -> Script Attributes: http://docs.textadventures.co.uk/quest/ ... cript.html
Functions
Verbs (GUI~Editor): these are actually just an Object's Script Attributes (see two lines above)
Commands
Turnscripts
Timers

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


the two SUPER SCRIPTS, which especially when used together, lets you do 90% of everything that you want to do in~for your game:


(1) the GUI~Editor's 'set a variable or attribute' Script:

this let's you set~create, re-set, add~remove, and~or change~alter~adjust any Attribute (during the game)

run as script -> add a~new script -> variables -> 'set a variable or attribute' Script -> (set it up)

and, JUST FOR INITIAL CREATION~SET'ting ONLY (before the game begins):

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

(Object Name: whatever)
Attribute Name: whatever
Attribute Type: (String, Boolean, Integer, Double, Script, Lists, Dictionaries, etc)
Attribute Value: (whatever, but depends upon the Attribute Type, of course)

in code:

Object_name.Attribute_name = Value_or_Expression

examples:

game.game_event_flag_state_integer_attribute = 0
game.game_event_flag_state_integer_attribute = game.game_event_flag_state_integer_attribute + 1
player.strength_integer_attribute = 3
player.offense = player.strength + player.endurance
player.damage_double_attribute = 37.21 // or it's: "37.21" // I haven't worked with Doubles at all, so I don't know if they need the double quotes or not
player.parent = room
player.parent = room2
orc.dead_boolean_attribute = false
orc.dead_boolean_attribute = true
HK.favorite_color_string_attribute = "black"
HK.favorite_colors_stringlist_attribute = split ("black;red", ";")

player.damage = player.weapon.damage + player.weapon.damage * player.strength / 100 - orc.armor.resistance - orc.armor_resistance * orc.endurance / 100

etc etc etc examples

(2) the GUI~Editor's 'if' Script:

this lets you act upon conditions~scenarios, the examples below will make more sense of this for you

run as script -> add a~new script -> scripts -> 'if' Script -> (set it up)

in code (example in optional full form):

OPERATORS:

Addiition: +
Subtraction: -
Multiplication: *
Division: /
Equals: =
Not Equals A: <>
Not Equals B: not Object_name.Attribute_name = Value_or_Expression
Greater Than: >
Lesser Than: <
Greater Than or Equals to: >=
Lesser Than or Equals to: <=
String Comparison: =
*Concatinating (literally putting things together): +
bitwise and: and
bitwise xor~or: or
bitwise not: not

*Concatinating:
Math: 5+4 ===> 9
Math: 5+5+5+5 ===> 20
Math: 5+"5" ===> ERROR!
Math: 5+"Mama" ===> ERROR!
Math: "Mama"+"Mia" ===> ERROR!
~VS~
Concatinating: "5"+"4" ===> "54"
Concatinating: "5"+"5"+"5"+"5" ===> "5555"
Concatinating: "5"+"Mia" ===> "5Mia"
Concatinating: "Mama"+"Mia" ===> "MamaMia"
Concatinating: "Mama"+""+"Mia" ====> "Mama Mia"


examples:

if (Object_name.Attribute_name OPERATOR Value_or_Expression) {
// whatever scripting
}
else if (Object_name.Attribute_name OPERATOR Value_or_Expression) {
// whatever scripting
}
// etc 'else ifs' if you want~need more
else {
// whatever scripting
}

if (orc.dead = true) {
msg ("The orc is already dead, silly.")
} else if (orc.dead = false) {
msg ("You attack and kill the orc.")
orc.dead = true
}

if (player.condition = "poisoned") {
player.life = player.life - 50
msg ("The poison damages you for 50 hp.")
} else if (player.condition = "paralyzed") {
msg ("You are paralyzed, unable to move, nor able to do anything.")
} else if (player.condition = "dead") {
msg ("You were killed or died.")
msg ("GAME OVER")
finish
}

if (player.strength_integer > 100) {
player.strength_integer = 100
} else if (player.strength_integer < 0) {
player.strength_integer = 0
}
if (player.strength_integer >= 67) {
player.strength_string = "strong"
} else if (player.strength_integer < 67 and player.strength_integer > 33) {
player.strength_string = "average"
} else if (player.strength_integer <= 33) {
player.strength_string = "weak"
}

if (not npc_1.parent = player.parent) {
msg ("Npc_1 follows along with you.")
npc_1.parent = player.parent
}


3. Attributes (data~properties~traits~characteristics): http://docs.textadventures.co.uk/quest/types/

Attributes are hard to describe, as they behave as a combination of both being 'physical things' and 'scriptings'

in the GUI~Editor (before the game begins):

'whatever' Element -> 'whatever' or the 'Attributes' Tab -> the options~settings (Attributes) || or Attributes -> Add -> (set them up)

in code (during the game: set~create, re-set, add~remove, and change~alter~adjust) examples:

Object_name.Attribute_name = Value_or_Expression

Attribute Types:

String Attributes: a collection of symbols (alphabet, numbers, and some of the other symbols too):

a
aaa
1
1234
a1a1
ifdsifhsdlkfhsdklf
dead
dead_boolean_attribute


(the Value must be encased in~by double quotes, or the textual parts within an Expression must be too)

player.condition = "poisoned"
player.alias = "HK"
player.strength_integer_as_a_string = "100"

game.greeting = "Hi, " + player.alias + " welcome to this game, have fun, but try not to die, as if you die in the game, then you die in real life, muwahaha! Good Luck! You'll need it..."

Object Attributes:

the Value must *NOT* have double quotes, it can't be the special~reserved (a Boolean Attribute's Values) 'true' nor 'false', and it must be an actual-existing Object in the game!

player.parent = room
player.left_hand = shield
player.right_hand = sword

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

<object name="room">
</object>

<object name="shield">
</object>

<object name="sword">
</object>


Boolean Attributes: literally as 'true' or 'false'

NO double quotes!

// the orc starts out alive (duh, lol):
orc.dead = false

// you kill the orc:
orc.dead = true

example of a built-in Boolean Attribute:
tv.switchedon=false // or (too lazy to look it up): tv.SwitchedOn=false
tv.switchedon=true // or (too lazy to look it up): tv.SwitchedOn=true

Integer Attributes: any non-decimal number

player.strength_integer = 100
game.event_flag_state = 0
player.strength_integer = player.strength_integer + 3

Double (Float~Floating Point) Attribute: any decimal number

player.damage_double = 45.2 // or: "45.2", as I've never used Doubles, so I don't know if it needs the double quotes or not.

List (Stringlists and Objectlists) Attributes: these are a bit more advanced, so not getting into them

Dictionary (Stringdictionaries, Objectdictionaries, and Scriptdictionaries) Attributes: these are even more advanced, so not getting into them

etc Attribute Types: too tired to get into them

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

anyways, finally about your question, conceptually about Attribute usage:

you're used to using and thinking in terms of Object (physical thing) usage, but these are very unweildy, such as:

imagine having actual individual 'silver and gold coins' Objects for your currency~transactions, the sheer quantity of them + having to move them around .. YUCK !!!!

INSTEAD, you want to use Attributes!

Your Objects have Attributes, which you can simply adjust, no moving of actual physical things around, nor in having those physical things. Attributes are awesome! see below, using the currency~transactions example (in code):

we're only moving the 'sword' Object around, no 'gold coins' and 'silver coins' extra Objects being moved around

shop_owner.cash = 500
player.cash = 100
sword.price = 50

Buying:

sword.parent = shop_owner

player.cash = player.cash - sword.price
shop_owner.cash = shop_owner.cash + sword.price
sword.parent = player

Selling:

sword.parent = player

player.cash = player.cash + (sword.price / 2)
shop_owner.cash = shop_owner.cash - (sword.price / 2)
sword.parent = shop_owner

*note: this should require 'if' scripting to check if you have enough 'cash' to buy the sword and the shop owner to buy the sword, of course, which I've left out, obviously.

----------

finally for your question specifically:

I would have your 'security' be an Integer Attribute on your 'player' Player Object, by creating~setting it to zero in the GUI~Editor:

'player' Player Object -> 'Attributes' Tab -> Attributes -> Add -> (see below)

(Object Name: player)
Attribute Name: security
Attribute Type: int (integer)
Attribute Value: 0

in code as scripting: player.security = 0

in code as creation tag:

<object name="player">
// blah code lines
<attr name="security" type="int">0</attr>
// blah code lines
</object>


anyways, conceptually what we're doing is 'flag stating', which probably makes more sense in the examples below:

player.security = 0 ~~~~~ you don't have any security clearance, no pretend security card
player.security = 1+ ~~~~~ you have higher levels of security clearance

let's say you 'push' Verb on a 'machine button' Object, which in its scripting, gives you: player.security = 1

than on a 'computer' Object, there's a 'hack' Verb, which if successful (using 'if' scripting), each time but increasing harder, increases your security by 1:
player.security = player.security + 1

and lastly, you got 'teleporter door' that are 'Locked' Objects~Exits that require levels of security clearance, example in pseudo-code:

if (player.security=0) {
-> msg ("You don't ahve clearance.")
} else if (player.security=1) {
-> msg ("You get into, are moved to, noobie areas~rooms of the game.")
} else if (player.security=2) {
-> msg ("You get into, are moved to, intermediate areas~rooms of the game.")
} else if (player.security=3) {
-> msg ("You get into, are moved to, hard areas~rooms of the game.")
} else if (player.security=4) {
-> msg ("You get into, are moved to, the last area~room of the game.")

HegemonKhan
and here's a link to using STATUS ATTRIBUTES:

viewtopic.php?f=10&t=5387&p=37393&hilit=statusattributes#p37375

(link includes a full sample game for you to use~study)

HegemonKhan
the secret trick of writing msg expressions (text+VARIABLES):

break it up into chunks

there's two types of chunks:

1. "text"
2. +VARIABLES+

for example:

HK is a 18 year old adult male human warrior.

player.alias = "HK"
player.age_integer = 18 // I wish I was 18, lol
player.age_string = "adult"
player.sex = "male"
player.race = "human"
player.class = "warrior"

msg (player.alias + " is a " + player.age_integer + " year old " + player.age_string + " " + player.sex + " " + player.race + " " + player.class + ".")

the chunks: 12

01) player.alias +
02) " is a "
03) + player.age_integer +
04) " year old "
05) + player.age_string +
06) " "
07) + player.sex +
08) " "
09) + player.race +
10) " "
11) + player.class +
12) "."

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

see if you can understand this, and then apply it to the string in your post

the backslash ( \ ) is called an 'escape' character, it allows you to display characters that you normally wouldn't be able to display (and it does other things too, like a newline, tab, etc --- not sure what quest has programmed into it though). So, \", causes the double quote to be displayed. The backslash~escape character is always on the left side and the character that goes with it is on its right side.

but, if you can't figure it out:

the chunks:

"You say \"" // Outputs: You say "
+ text + // Outputs (example): hello // You say "hello
",\" but nobody replies." // Outputs: ," but nobody replies. // You say "hello," but nobody replies.

"You say \"" + text + ",\" but nobody replies."
// outputs: You say "hello," but nobody replies.

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

Support

Forums