Question About a Function :D [SOLVED]

Anonynn
06 Jun 2018, 23:33Hello all :)
I was wondering...I have objects (monsters) and a monster type and I want to randomly generate a few basic things about their anatomy to interweave within their descriptions with each play-through. So what is the best way to go about doing this.
What I was going to do was create a few Attributes on the monsters that return an "unknown" string until the function is called at the monster's being cloned or put into a room.
I also have a Function called MonsterParts
should I have it return a String? And then do something like...
firsttime {
if (monsternamehere.height="unknown") {
if (RandomChance(50)) {
monsternamehere.height="3.2"
}
else if (RandomChance(33)) {
monsternamehere.height="3.4"
}
else if (RandomChance(25)) {
monsternamehere.height="3.6"
}
else {
monsternamehere.height="3.8"
}
}
}
and...
firsttime {
if (monsternamehere.weight="unknown") {
if (RandomChance(50)) {
monsternamehere.height="skinny"
}
else if (RandomChance(33)) {
monsternamehere.height="fat"
}
else if (RandomChance(25)) {
monsternamehere.height="chubby"
}
else {
monsternamehere.height="paper thin"
}
}
}
Like that?
And then when the function is called, it'll pick one from each of these and apply it to the monster's description.
Anonynn. :D

K.V.
07 Jun 2018, 00:15Look at Pixie's Zombie Apocalypse guide on his GitHub wiki.
Specifically, the SpawnZombie function.
(My Windows are all jammed shut, so... no link for you. Sorry!)
hegemonkhan
07 Jun 2018, 00:33an example (using an Object+Script_Attribute+Delegate, instead of a Function)
(if you need help with adjusting it for your needs, let me know and I'll help you with it)
// scripting examples:
rundelegate (monster_object, "monster_script_attribute", "orc", "orc_type", "example_room")
rundelegate (monster_object, "monster_script_attribute", "monster", "monster_type", "example_room")
// -----------
<delegate name="monster_delegate" parameters="monster_name_string_parameter, monster_type_string_parameter, monster_destination_string_parameter" />
<game name="example_game">
</game>
<object name="example_room">
</object>
<object name="monster_object">
<attr name="monster_script_attribute" type="monster_delegate">
create (monster_name_string_parameter, monster_type_string_parameter)
object_variable = GetObject (monster_name_string_parameter)
object_variable.parent = this
clone_object_variable = CloneObject (object_variable)
clone_object_variable.parent = GetObject (monster_destination_string_parameter)
// clone_object_variable.type_string_attribute = monster_name_string_parameter // this isn't needed as Pixie already built-in this functionality into the recent version of quest, using his 'prototype' Object Attribute and etc built-in coding of his own
// object_variable.look ="Height: " + object_variable.height_double_attribute + ", Weight: " + object_variable.weight_string_attribute
// clone_object_variable.look = "Height: " + clone_object_variable.height_double_attribute + ", Weight: " + clone_object_variable.weight_string_attribute
// msg (object_variable.look)
// msg (clone_object_variable.look)
if (RandomChance (50)) {
clone_object_variable.height_double_attribute = 3.2
clone_object_variable.weight_string_attribute = "skinny"
} else if (RandomChance (33)) {
clone_object_variable.height_double_attribute = 3.4
clone_object_variable.weight_string_attribute = "fat"
} else if (RandomChance (25)) {
clone_object_variable.height_double_attribute = 3.6
clone_object_variable.weight_string_attribute = "chubby"
} else {
clone_object_variable.height_double_attribute = 3.8
clone_object_variable.weight_string_attribute = "paper thin"
}
// scripting for applying the above new/randomly set Attribute changes into your 'description/look' String Attribute:
// examples:
// object_variable.look ="Height: " + object_variable.height_double_attribute + ", Weight: " + object_variable.weight_string_attribute
// clone_object_variable.look = "Height: " + clone_object_variable.height_double_attribute + ", Weight: " + clone_object_variable.weight_string_attribute
// msg (object_variable.look)
// msg (clone_object_variable.look)
</attr>
</object>
<type name="orc_type">
<inherit name="monster_type" />
<attr name="height_double_attribute" type="double">10.0</attr>
<attr name="weight_string_attribute" type="string">chubby</attr>
</type>
<type name="monster_type">
<attr name="height_double_attribute" type="double">0.0</attr>
<attr name="weight_string_attribute" type="string">unknown</attr>
</type>
jmnevil54
07 Jun 2018, 00:41Your idea sounds fine to me! ...Even if I mostly don't have any idea of what you said...
Zombie game link here.
https://github.com/ThePix/quest/wiki/The-Zombie-Apocalypse-(on-the-web-version)

K.V.
07 Jun 2018, 01:45I still have no clue how to do anything with delegates...
...or why I would bother... (I'm bound to be missing something!)
Do the delegates, Anonynn! Then show us your code!

Dcoder
07 Jun 2018, 01:55To generate exacting probabilities, I prefer to use something like
n = GetRandomInt (1, 10)
switch (n) {
case (1, 2, 3) {
monster.weight = "lightweight"
}
case (4, 5, 6, 7) {
monster.weight = "cruiserweight"
}
case (8, 9, 10) {
monster.weight = "massive"
}
}
The GetRandomInt (1, 10)
or DiceRoll ("d10")
functions give you precise control over probabilities, as opposed to using a series of RandomChance (whatever %)
functions which are harder to plan out and more cumbersome to use.

Anonynn
07 Jun 2018, 02:21Well, according to Pixie's library...it says to use ProcessText to keep descriptions from changing. But that link is for the web version so let's hope they are the same.
obj.look = ProcessText("A " + obj.alias + ", {random:covered in maggots:missing an arm:one eye hanging out}.")
obj.hitpoints = 10
obj.damage = 3
obj.attack = 0
obj.defence = 0
obj.armour = 0
this seems to be the important bit.
So should it be something like...
monsternamehere.height
monsternamehere.gender
monsternamehere.weight
etc
Then on the description of the monster.
monsternamehere.look = ProcessText("You can see a + obj.alias + " {monsternamehere.height}, {monsternamehere.gender} zombie that looks incredibly {monsternamehere.weight}.
Like that?
Anonynn.

Anonynn
07 Jun 2018, 02:22I just feel like we need a stringlist on the monster type for the gender and weight and other attributes for the ProcessText to pull from.
hegemonkhan
07 Jun 2018, 04:01There's no difference between Delegates and Functions for the most part, aside from organization/encapsulation:
have to find the Functions, whereas using Objects+Script_Attributes+Delegates has everything right there within the Object (aside from the Delegate, aka its definition/prototype/body info, itself)

K.V.
07 Jun 2018, 09:33have to find the Functions
Ah! I see!

Anonynn
07 Jun 2018, 21:17So am I correct :D ? I just want to make sure before I start adding stuff.
Anonynn.

K.V.
07 Jun 2018, 21:25It looks like you've got it right to me, ma'am!

Anonynn
07 Jun 2018, 22:14So wait. I make each attribute a string on the monster type (which covers all monsters) and then I make it unknown. Then...where do I put the stringlist for them? Or do I make each attribute a stringlist from the beginning and have the ProcessText in the look description of the creatures choose one.
Do I have to create a look attribute as well and mark it as Process Text?
/confused.
Anonynn.
hegemonkhan
08 Jun 2018, 00:12(filler for getting my edited post, updated/posted)
I'd create a single base monster Object, for holding various Attributes for reference/usage (such as List/Dictionary Attributes if their contents are used as such), as you only need a single Object holding them, as you don't want every Object to have them (which would occur when putting them into the Object_Type/Type/Inherited_Attribute)
(see my example in my previous post)
but, all the Attributes that every various 'monster' Object needs, those Attributes should be put into the Object_Type/Type/Inherited_Attribute, as you do want these to be distributed/given to all of your various monster Objects
or, see this example:
<game name="example_game">
<attr name="start" type="script">
do (orc_object, "orc_script_attribute")
</attr>
</attr>
// my base 'orc_object' Object:
<object name="orc_object">
<orc_skin_color_stringlist_attribute type="stringlist">
<value>light green</value>
<value>dark green</value>
<value>light grey</value>
<value>dark grey</value>
<value>light blue</value>
<value>dark blue</value>
</orc_skin_color_stringlist_attribute>
<orc_objectlist_attribute type="objectlist">
<value>orc_1_object</value>
<value>orc_2_object</value>
<value>orc_3_object</value>
</orc_objectlist_attribute>
<attr name="orc_script_attribute" type="script">
foreach (object_variable, orc_object.orc_objectlist_attribute) {
string_variable = StringListItem (orc_object.orc_skin_color_stringlist_attribute, GetRandomInt (0, ListCount (orc_object.orc_skin_color_stringlist_attribute) - 1))
set (object_variable.name, "orc_skin_color_string_attribute", string_variable)
}
</attr>
</object>
// my 'orc' Objects:
<object name="orc_1_object">
<inherit name="orc_type" />
</object>
<object name="orc_2_object">
<inherit name="orc_type" />
</object>
<object name="orc_3_object">
<inherit name="orc_type" />
</object>
// my 'orc_type' Object_Type/Type/Inherited_Attribute:
<type name="orc_type">
<attr name="orc_dead_boolean_attribute" type="boolean">false</attr>
<attr name="orc_skin_color_string_attribute" type="string">unknown</attr>
</type>

Anonynn
08 Jun 2018, 00:46Okay. So I'm on the right track then. I already have a Monster Type, a specific Monster Type like Zombie and a Zombie Female and Zombie Male type. I put the stringlists on the Female and Male Zombie types since things are a little different between them.
So the only thing I'm confused about now is the ProcessText.
monsternamehere.look = ProcessText("You can see a + obj.alias + " {monsternamehere.height}, {monsternamehere.gender} zombie that looks incredibly {monsternamehere.weight}.
I know I need this above to be in the message. But is it supposed to be this...
msg ("monsternamehere.look = ProcessText("You can see a + obj.alias + " {monsternamehere.height}, {monsternamehere.gender} zombie that looks incredibly {monsternamehere.weight}.") ?
Thanks for your help so far everyone :D!
Anonynn.

K.V.
08 Jun 2018, 01:05I think you just want it like this:
monsternamehere.look = "You can see a " + obj.alias + " {monsternamehere.height}, {monsternamehere.gender} zombie that looks incredibly {monsternamehere.weight}."

Anonynn
09 Jun 2018, 05:42Thanks all! I'll write more if I have any issues. :)
Anonynn.

Anonynn
11 Jun 2018, 01:05So I plugged in all the stuff and this happened...
Error running script: Error compiling expression '"Before you is a (stringlist) " + obj.alias + " with (stringlist) skin. You can tell she used to be a (stringlist) before she lost her mind to the zombie infection, now she's only a shell of her former self, only basic instincts remain. She stands (stringlist) tall, has thinned out (stringlist) and curly (stringlist) hair and her eyes are a brilliant (stringlist) color despite her being mostly putrefied. She also has (stringlist) lips which are blocking her broken teeth. On her torso rests (stringlist) breasts. The rest of her torso has multiple contusions and other impairments that make you wonder just how these creatures are staying upright. "': Unknown object or variable 'obj'
So I'm assuming stringlists can't be used. Should this just be a string? Here is the original code.
Before you is a {this.weight} " + obj.alias + " with {this.skin} skin. You can tell she used to be a {this.race} before she lost her mind to the zombie infection, now she's only a shell of her former self, only basic instincts remain. She stands {this.height} tall, has {random:thinned out:full:thick} {this.hairlength}{random: and curly: and straightened: and messy:} {this.haircolor} hair and her eyes are {random:a beautiful:a wonderful:a brilliant:an attractive:a gorgeous:a lovely:an exquisite} {this.eyecolor} color despite her being mostly {random:dead:rotten:decayed:withered:addled:decomposed:putrefied}. She also has {this.lips} lips which are blocking her {random:rotten teeth:discolored teeth:crooked teeth:blood-stained teeth:broken teeth:decaying teeth}. On her torso rests {this.breastsize} breasts. The rest of her torso {random:has multiple contusions:has multiple bruises and minor cuts:has multiple bruises and major gashes:has multiple cuts and leaking lesions:has multiple lacerations both minor and severe:has multiple protruding bones and afflictions} and other {random:deformations:damages:sores:blemishes:impairments:trauma:wounds:abrasions} that make you wonder just how these creatures are staying upright.
and here is the code from the script.
monsternamehere.look = "Before you is a {this.weight} " + obj.alias + " with {this.skin} skin. You can tell she used to be a {this.race} before she lost her mind to the zombie infection, now she's only a shell of her former self, only basic instincts remain. She stands {this.height} tall, has {random:thinned out:full:thick} {this.hairlength}{random: and curly: and straightened: and messy:} {this.haircolor} hair and her eyes are {random:a beautiful:a wonderful:a brilliant:an attractive:a gorgeous:a lovely:an exquisite} {this.eyecolor} color despite her being mostly {random:dead:rotten:decayed:withered:addled:decomposed:putrefied}. She also has {this.lips} lips which are blocking her {random:rotten teeth:discolored teeth:crooked teeth:blood-stained teeth:broken teeth:decaying teeth}. On her torso rests {this.breastsize} breasts. The rest of her torso {random:has multiple contusions:has multiple bruises and minor cuts:has multiple bruises and major gashes:has multiple cuts and leaking lesions:has multiple lacerations both minor and severe:has multiple protruding bones and afflictions} and other {random:deformations:damages:sores:blemishes:impairments:trauma:wounds:abrasions} that make you wonder just how these creatures are staying upright. "

K.V.
11 Jun 2018, 01:19What is this
in your script? I think you need to replace every instance of this
with monsternamehere
or obj
, but it's hard to tell out of context.
You can use msg("this: " + this)
to find out what this
is. Same goes for obj
. For that, use msg("obj: " + obj)
.

K.V.
11 Jun 2018, 02:07I was without Windows, reading these posts on my phone, at the beginning of this. Where are you creating string lists and what are you using them for?
The only purpose I can think of is during the initial monster setup, like when play begins. A script would choose a weight, height, skin type, etc. from string lists then set the actual monster's attributes to one value each.
hegemonkhan
11 Jun 2018, 03:22(filler for getting my edited post, updated/posted)
String Lists are not strings, so they can't be displayed as text.
the built-in way of displaying a list/dictionary is via:
DisplayList (LIST, true/false)
DisplayDictionary (DICTIONARY, true/false)
true: will number the list items
// example:
stringlist_variable = Split ("red;blue;yellow", ";")
DisplayList (stringlist_variable, true)
// output/display:
- red
- blue
- yellow
false: will NOT number the list items
// example:
stringlist_variable = Split ("red;blue;yellow", ";")
DisplayList (stringlist_variable, false)
// output/display:
red
blue
yellow
You can manually (and set its format/look) display a String List, as the built-in method has its format already set (limited), via using 'foreach' and possibly needing string concatenation
You can also use the 'join' (the opposite/reverse of 'Split') to turn a String List into a String (though you'll want to do more formatting of it as well, most likely):
http://docs.textadventures.co.uk/quest/functions/string/join.html
stringlist_variable = Split ("red;blue;yellow", ";")
string_variable = Join (stringlist_variable, ";")
msg (string_variable)
// output/display:
red;blue;yellow
or
redblueyellow
or
red blue yellow
(I'm not sure how join returns/displays/formats the string... too lazy to get on quest to see it)
hegemonkhan
11 Jun 2018, 03:37oh....
if you just want to display a String List's Item, an example using your scripting:
<object name="example_object">
<example_stringlist_variable type="stringlist">
<value>red</value>
<value>blue</value>
<value>yellow</value>
</example_stringlist_variable>
</object>
<object name="npc">
<attr name="alias" type="string">sarah</attr>
<attr name="look" type="script">
example_object.example_string_variable = "Before you is a " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " " + npc.alias + " with " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " skin. You can tell she used to be a " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " before she lost her mind to the zombie infection, now she's only a shell of her former self, only basic instincts remain. She stands " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " tall, has thinned out " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " and curly " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " hair and her eyes are a brilliant " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " color despite her being mostly putrefied. She also has " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " lips which are blocking her broken teeth. On her torso rests " + StringListItem (example_object.example_string_variable, GetRandomInt (0, ListCount (example_object.example_string_variable) - 1)) + " breasts. The rest of her torso has multiple contusions and other impairments that make you wonder just how these creatures are staying upright."
msg (example_object.example_string_variable)
</attr>
</object>

Anonynn
11 Jun 2018, 05:52Heya! So I had to do a massive work around with KV to figure out what all the problems were! ((There were a lot)). Luckily, it all works 100% now, although it took quite a while to figure out what was happening!
Thanks everyone!
Anonynn.