Stringlists Baby!!

Forgewright
I have been searching for a way to have the GUI randomly select comments from a list to have a NPC comment about when a player "Speaks" to them.

I know it has something to do with a stringlist or dictionary or attributes. I tried a suggestion of using percentages but I can't put everything together. Please give me an example of a character with an attritube and the script to call the values randomly.

I have 0 XP when it comes to string list and dictionary. The quest Tutorials explain them but not to the depth of random calling of such.

I give the character an attribute of any name I want but select stringlist in the drop box then fill it with strings with a :number equals string: or does the GUI count them as 0,1,2,3 automatically?

stringlist = (1=Blah Blah; 2 = Blah this; 3 = Blah that;) Is this right?

then call the stringlist in a script set for "speak" in the characters verb box

outcome = stringlist(Getrandom(1,3)
is it outcome or result or output or wtf
msg = outcome????? the random pick of 1 or 2 or 3 labeled as what to have it print to gamer.

The Pixie
//Use Split to create your string list
stringlist = Split("Blah Blah;Blah this;Blah that", ";")
//Use GetRandomInt to select one, and ListCount to get the range
n = GetRandomInt(0, ListCount(stringlist) - 1)
// Use StringListItem to get the value
msg("The NPC says, '" + StringListItem(stringlist, n) + ".'")

jaynabonne
If your string lists are static (that is, don't change throughout the game), then you might find it easier to just create string list attributes somewhere (perhaps even on the NPC itself to keep things together) rather than doing it in script with hard-coded strings and Split. (My two cents.)

HegemonKhan
HK Edit: my code for the 'for' Function examples has been fixed to being correct~functional code now, sorry, for not fixing it up sooner, but I was really tired after doing this, as it was a lot of work (4+ hrs), and I needed a rest... though I kept posting... lol, but I got my rest now, and the code 'for' Function examples are now fixed up. My 'foreach' examples, should also work now too... but I haven't actually tested them.

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

HK's Extensive Guide for (Using) Lists and Dictionaries:

General Links:

http://docs.textadventures.co.uk/quest/
http://docs.textadventures.co.uk/quest/ ... notes.html (and also click on the individual blog links for more detailed and extra information)
http://docs.textadventures.co.uk/quest/tutorial/
http://docs.textadventures.co.uk/quest/guides/
http://docs.textadventures.co.uk/quest/aslx.html
http://docs.textadventures.co.uk/quest/elements/
http://docs.textadventures.co.uk/quest/types/
http://docs.textadventures.co.uk/quest/functions/ (category order)
http://docs.textadventures.co.uk/quest/ ... tions.html (alphabetical order)
http://docs.textadventures.co.uk/quest/scripts/
viewforum.php?f=18 (more guides: Library and Code Samples)

Lists (Stringlists and Objectlists) Links:

http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... glist.html
http://docs.textadventures.co.uk/quest/ ... tlist.html
http://docs.textadventures.co.uk/quest/ ... glist.html
http://docs.textadventures.co.uk/quest/ ... tlist.html
http://docs.textadventures.co.uk/quest/ ... titem.html
http://docs.textadventures.co.uk/quest/ ... titem.html
http://docs.textadventures.co.uk/quest/ ... t_add.html
http://docs.textadventures.co.uk/quest/ ... emove.html
http://docs.textadventures.co.uk/quest/ ... mbine.html
http://docs.textadventures.co.uk/quest/ ... clude.html
http://docs.textadventures.co.uk/quest/ ... tsort.html
http://docs.textadventures.co.uk/quest/ ... nding.html
http://docs.textadventures.co.uk/quest/ ... ylist.html
http://docs.textadventures.co.uk/quest/ ... tains.html
http://docs.textadventures.co.uk/quest/ ... count.html
http://docs.textadventures.co.uk/quest/ ... titem.html
http://docs.textadventures.co.uk/quest/ ... rents.html

Dictionaries (Stringdictionaries, Objectdictionaries, and Scriptdictionaries) Links:

http://docs.textadventures.co.uk/quest/ ... aries.html
http://docs.textadventures.co.uk/quest/ ... onary.html
http://docs.textadventures.co.uk/quest/ ... onary.html
http://docs.textadventures.co.uk/quest/ ... onary.html
http://docs.textadventures.co.uk/quest/ ... onary.html
http://docs.textadventures.co.uk/quest/ ... onary.html
http://docs.textadventures.co.uk/quest/ ... onary.html
http://docs.textadventures.co.uk/quest/ ... yitem.html
http://docs.textadventures.co.uk/quest/ ... yitem.html
http://docs.textadventures.co.uk/quest/ ... yitem.html
http://docs.textadventures.co.uk/quest/ ... yitem.html
http://docs.textadventures.co.uk/quest/ ... tains.html
http://docs.textadventures.co.uk/quest/ ... count.html
http://docs.textadventures.co.uk/quest/ ... tsort.html
http://docs.textadventures.co.uk/quest/ ... nding.html
http://docs.textadventures.co.uk/quest/ ... y_add.html
http://docs.textadventures.co.uk/quest/ ... emove.html

Other Useful Functions~Scripts for Usage with Lists and Dictionaries:

(There's also the ~ 'Format Objectlists' and etc Functions too, but I didn't include them as they're a bit more specific~advanced~specialized usage)

http://docs.textadventures.co.uk/quest/ ... /join.html
http://docs.textadventures.co.uk/quest/ ... split.html

http://docs.textadventures.co.uk/quest/ ... reach.html
http://docs.textadventures.co.uk/quest/scripts/for.html

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

http://docs.textadventures.co.uk/quest/ ... y/got.html (a shortcut to checking for Object in, with using, the ScopeInventory ~ Player Inventory)

http://docs.textadventures.co.uk/quest/ ... jects.html
http://docs.textadventures.co.uk/quest/ ... mands.html
http://docs.textadventures.co.uk/quest/ ... exits.html
http://docs.textadventures.co.uk/quest/ ... ripts.html

http://docs.textadventures.co.uk/quest/ ... jects.html
http://docs.textadventures.co.uk/quest/ ... ldren.html

http://docs.textadventures.co.uk/quest/ ... verbs.html (special built-in Stringlist)
http://docs.textadventures.co.uk/quest/ ... verbs.html (special built-in Stringlist)
http://docs.textadventures.co.uk/quest/ ... butes.html (special built-in Stringdictionary)

Randomization Links:

http://docs.textadventures.co.uk/quest/ ... eroll.html
http://docs.textadventures.co.uk/quest/ ... omint.html
http://docs.textadventures.co.uk/quest/ ... ouble.html
http://docs.textadventures.co.uk/quest/ ... hance.html

-----------

my general syntax:

Attribute: Object_name.Attribute_name = Value_or_Expression
Variable: Variable_string_name = Value_or_Expression

quest terminology:

VARIABLE:
-> Attribute
-> Variable

Stringlists:

Attribute: Object_name.Stringlist_Attribute_name = split ("string1;string2;string3;etc4", ";")
Variable: Stringlist_Variable_string_name = split ("split ("string1;string2;string3;etc4", ";")

Attribute example: game.food_stringlist = split ("apple;lemon;orange", ";")
Variable example: food_stringlist = split ("apple;lemon;orange", ";")

Objectlists:

Attribute: Object_name.Objectlist_Attribute_name = split ("string1;string2;string3;etc4", ";")
Variable: Objectlist_Variable_string_name = split ("split ("object1;object2;object3;etc4", ";")

Attribute example: game.food_objectlist = split ("apple;lemon;orange", ";")
Variable example: food_objectlist = split ("apple;lemon;orange", ";")

----------

Using Lists and Dictionaries (these are similiar to 'Arrays' in other code languages, I think):

Important Note:

Objects in (put in) Objectlists, have absolutely no effect on an Object's actual location and~or any other bearing at all. Objectlists' items (Objects) are completely independant and is uneffecting of everything else. It took me awhile to understand this concept. An Object's actual existance+location is its Parent (another Object, or the entire game itself as its Parent). For Example:

<object name="object1">
<object name="object2">
</object>
</object>

<object name="object3">
<attr name="objectlistx" type="objectlist">object2</attr>
</object>


'object2' exists+location is inside (a Child of its Parent) 'object1'

the 'object2' item in the 'objectlistx' Objectlist Attribute is just that, an item (as it's NOT the actual 'object2' Object), which is inside~of 'object3', has absolutely no bearing on anything at all. We can use the Objectlist do to do things, that's its purpose, but outside of that doing (actions~scriptings), it has no bearing at all on anything. For example, we can use the objectlist to actually move the 'object2' from 'object1' to 'object3', but until we actually do the 'move' scripting, 'object2' exists and is located inside of 'object1', NOT 'object3'.

About Lists:

Note: my use of 'item' is just my own general term of~for ambigiously referencing 'text~Strings' for Stringlists or 'Objects' for Objectlists

they are just a collection of text~strings (Stringlists) or Objects (Objectlists), separated as individual choices~selections (see section above too):

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

VARIABLE = split ("item1 SEPARATOR_SYMBOL item2 SEPARATOR_SYMBOL item3 SEPARATOR_SYMBOL etc4", "SEPARATOR_SYMBOL")

the generally prefered separator symbol is usually a semicolon:

VARIABLE = split ("item1;item2;item3;etc4", ";")

the point of a List, is that we can then use it, to do a ton of really cool and useful things.

but first, you got to understand more on how Lists work:

VARIABLE = split ("item1;item2;item3;etc4", ";")
game.primary_pigment_colors_stringlist = split ("red;blue;yellow", ";")

0. red (1st item)
1. blue (2nd item)
2. yellow (3rd item)

we have 3 items: red (1st item), blue (2nd item), and yellow (3rd item):

ListCount (game.primary_pigment_colors_stringlist) ====> 3 (quantity of items in the List)

HOWEVER, to actually reference~use~get that item, is via its 'index' number (think of an actual book library), which starts at 0, not 1 (ya, it is very confusing especially when you're using 'ListCount' + 'ListItem~StringListItem~ObjectListItem', grr):

red's index # is 0
blue's index # is 1
yellow's index # is 2

so, for example:

VARIABLE = StringListItem (List, index number)

StringListItem (game.primary_pigment_colors_stringlist, 0) ===> red
StringListItem (game.primary_pigment_colors_stringlist, 1) ===> blue
StringListItem (game.primary_pigment_colors_stringlist, 2) ===> yellow
StringListItem (game.primary_pigment_colors_stringlist, 3) ===> ERROR !!!! there is no 4th item, so can't compute! ERROR !!!

now, you can use variables for your 'index number, too, to do the more fancy things:

get input {
-> // you type in a number
-> // quest automatically sets the variable: result = your_typed_in_input
-> VARIABLE = StringListItem (List, result)
}

and also with using Randomization:

GetRandomInt (min integer number value, max inteer number value)

for a Static+Known quantity of items in your List:

game.primary_pigment_colors_stringlist = split ("red;blue;yellow", ";")
game.primary_pigment_colors_stringlist = StringListItem (game.primary_pigment_colors_stringlist, GetRandomInt (0, 2) )
// 'GetRandomInt' will randomly select '0', '1', or '2'
// game.primary_pigment_colors_stringlist = red (0)
// OR
// game.primary_pigment_colors_stringlist = blue (1)
// OR
// game.primary_pigment_colors_stringlist = yellow (2)

for a Dynamic+UNknown quantity of items in your List:

'ListCount' will add~sum up the quantity of items in your list each time, so this works great when you're constantly adding~removing items from your list over the duration of the game, hence the list's dynamic~unknown quantity of items in the list, hence the 'magic' of using 'ListCount', hehe

however, this is where the confusion comes in between 'quantity' and 'index number', as we got to do:

ListCount (List) - 1 ====> index number

we're finding the highest item quantity:

if there's 3 items in a list, then the max items in a list is 3 too, and thus the highest (last) item itself (via its index number) in the list is: 2 (3-1=2)

as remember the above example:

0. red (1st item)
1. blue (2nd item)
2. yellow (3rd item)

Index # vs Item Quantity:
0 vs 1
1 vs 2
2 vs 3

game.primary_pigment_colors_stringlist = split ("red;blue;yellow", ";")
game.primary_pigment_colors_stringlist = StringListItem (game.primary_pigment_colors_stringlist, GetRandomInt (0, ListCount (game.primary_pigment_colors_stringlist) - 1 ) )
// 'GetRandomInt' will randomly select '0', '1', or '2'
// game.primary_pigment_colors_stringlist = red (0)
// OR
// game.primary_pigment_colors_stringlist = blue (1)
// OR
// game.primary_pigment_colors_stringlist = yellow (2)

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

About Dictionaries:

they're essentially (think of them as) 'conversions' or 'inputs~outputs'

(and most~all of the stuff about lists, applies to Dictionaries too, in terms of the referencing)

examples:

<attr name="day_stringdictionary" type="simplestringdictionary">1=sunday;2=monday;3=tuesday;4=wednesday;5=thursday;6=friday;7=saturday;sunday=1;monday=2;tuesday=3;wednesday=4;thursday=5;friday=6;saturday=7</attr>

<attr name="month_to_season_stringdictionary" type="simplestringdictionary">january=winter;february=winter;march=spring;april=spring;may=spring;june=summer;july=summer;august=summer;september=autumn;october=autumn;november=autumn;december=winter</attr>

<attr name="opposing_magic_elementals_stringdictionary" type="simplestringdictionary">fire=water;water=fire;air=earth;earth=air</attr>

examples in~of application:

game.day_integer_stringlist = split ("1;2;3;4;5;6;7", ";")
show menu ("What day is it?", game.day_integer_stringlist, false) {
game.day_string = StringdictionaryItem (game.day_stringdictionary, result)
}

game.day_stringlist = split ("sunday;monday;tuesday;wednesday;thursday;friday;saturday", ";")
show menu ("What day is it?", game.day_stringlist, false) {
game.day_string = StringdictionaryItem (game.day_stringdictionary, result)
}

// let's see if I can remember how to do this, lol ~ its been a while ... Credit goes to Pixie's Spell Library for this ingenius usage of Dictionaries:

<attr name="opposing_magic_elementals_stringdictionary" type="simplestringdictionary">fire=water;water=fire;air=earth;earth=air</attr>

ice_dragon.elemental = "water"
fireball_spell.elemental = "fire"

'Cast' Verb on your 'spell' Objects (specific, non-global, non-dynamic, example):
spell = GetObject (fireball_spell)
enemy = GetObject (ice_dragon)
if (spell.elemental = StringDictionaryItem (opposing_magic_elementals_stringdictionary, enemy.elemental) ) {
enemy.life = enemy.life - (spell.damage * 2)
msg ("You do double the damage to the enemy, using the correct~opposing spell for its elemental vulnerability~weakness!")
} else if (spell.elemental = enemy.elemental) {
enemy.life = enemy.life + spell.damage
msg ("Doh!, You used the same elemental spell as the enemy's elemental, healing it instead of damaging it! You idiot!")
} else {
enemy.life = enemy.life - spell.damage
msg ("Your elemental spell, being neither the same nor opposite of the enemy's elemental, thus does its normal damage to the enemy.")
}


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

anyways, conceptually:

StringDictionaries:

the 'conversion' or 'input-output', only goes 1 way: left to right, so that's (if you need) why you need:
(I'm not sure if this also applies to Objectdictionaries and Scriptdictionaries, or not)

String1A (input) ---> String1B (output)
~OR~
String1A ---> (conversion) ---> String1B

example: fire=water

~ (if need) AND ~

String1B (input) ---> String1A (output)
~OR~
String1B ---> (conversion) ---> String1A

example: water=fire

ObjectDictionaries:

String1 (input) ---> Object1 (output)
~OR~
String1 ---> (conversion) ---> Object1

ScriptDictionaries:

String1 (input) ---> Script1 (output)
~OR~
String1 ---> (conversion) ---> Script1

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

lastly, note that there's the 'List~DictionaryContains' Function too, you can check if a List~Dictionary has a specific item in it. And all of the other Functions~Scripts that I give as the links above (at the top of my post).

'DisplayList' is useful too:

DisplayList (List, true_or_false)

colors = split ("red;blue;yellow", ";")
DisplayList (colors, true)
outputs:
1. red
2. blue
3. yellow

not sure what false does, haven't tried it yet, lol... a guess ONLY:
colors = split ("red;blue;yellow", ";")
DisplayList (colors, false)
outputs:
red
blue
yellow

and there's the 'Sort' Functions too. and etc... whatever else I'm missing...

the 'Scopes', 'Gets', and 'Alls' are very useful too...

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

oops, I forgot...

to make a new List~Dictionary (using a Stringlist for example):

VARIABLE = NewStringList ()

game.colors = NewStringList ()
list add (game.colors, "red")
list add (game.colors, "blue")
list add (game.colors, "yellow")

and etc... again see all of my links at the top of this post, and ask if you got any questions, and~or want to know what applications there are with using Lists~Dictionaries~the various links (at the top of the post), hope this helps anyone wanting to learn to using lists~dictionaries....

----------

ach... I forgot the 'Iteration' stuff (I'm tired now, so this will be brief, ask and I'll explain~help in more detail):

http://docs.textadventures.co.uk/quest/ ... lists.html (this shows better how to use 'for' properly, than the 'for' link itself below, lol)
http://docs.textadventures.co.uk/quest/ ... reach.html
http://docs.textadventures.co.uk/quest/scripts/for.html

'foreach' and 'for'

'foreach' is for iterating through EVERY~ALL~EACH (for*EACH*) item in your list, applying the scripting to each of those items. This is generally used most often by people. In 'foreach' you reference the List directly in its 'foreach' syntax line, and (depending) also in your scripting

'for' is for specific~targetted iteration of items in your list, applying the scripting to each of those items. This is generally not used as often by people, as it is (probably~assumingly) used for advanced RPG equipment+item system usages. You do NOT reference the List within the 'for' syntax line itself, instead you reference the List in the scriptings.

foreach (placeholder_variable, List) { scripts }

for (placeholder_variable, integer number min range value, integer number max range value, optionally: skip-count number value) { scripts }

with 'for', you reference your actual List within the scripting itself, not in the 'for' syntax line, this always confuses me (causing me to have to go look up on how to use 'for' over and over again, lol ~ I can never remember this)

examples:

'foreach' Function:

game.team = split ("joe;jim;john", ";")
foreach (team_member, game.team) {
do (team_member,"run_laps_script_attribute")
// output result conceptually:
// joe.runs_laps_script_attribute -> joe runs laps
// jim.runs_laps_script_attribute -> jim runs laps
// john.runs_laps_script_attribute -> john runs laps
}

// and the exact same thing:

game.team = split ("joe;jim;john", ";")
foreach (x, game.team) {
do (x,"run_laps")
// output result conceptually:
// joe.runs_laps -> joe runs laps
// jim.runs_laps -> jim runs laps
// john.runs_laps -> john runs laps
}

// and the exact same thing:

game.team = split ("joe;jim;john", ";")
foreach (item, game.team) {
do (item,"run_laps")
// output result conceptually:
// joe.runs_laps -> joe runs laps
// jim.runs -> jim runs laps
// john.runs -> john runs laps
}

// and the exact same thing:

game.team = split ("joe;jim;john", ";")
foreach (blahblahblah, game.team) {
do (blahblahblah,"run_laps")
// output result conceptually:
// joe.runs_laps -> joe runs laps
// jim.runs -> jim runs laps
// john.runs -> john runs laps
}


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

extra links (used below in my examples, well, just 'invoke', meh):

http://docs.textadventures.co.uk/quest/ ... nvoke.html
~OR~
http://docs.textadventures.co.uk/quest/scripts/do.html

'for' Function:

// Objectlist:
game.team = split ("joe;jim;john;jeff;jake;job;jab", ";")

for (team_member,0,0) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
}

for (team_member,6,6) {
do (ObjectListItem(game.team,team_member),"run_laps")
// jab.run_laps
}

for (team_member,2,2) {
do (ObjectListItem(game.team,team_member),"run_laps")
// john.run_laps
}

for (team_member,3,3) {
do (ObjectListItem(game.team,team_member),"run_laps")
// jeff.run_laps
}

for (team_member,0,2) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// jim.run_laps
// john.run_laps
}

for (team_member,3,6) {
do (ObjectListItem(game.team,team_member),"run_laps")
// jeff.run_laps
// jake.run_laps
// job.run_laps
// jab.run_laps
}

for (team_member,0,6) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// jim.run_laps
// john.run_laps
// jeff.run_laps
// jake.run_laps
// job.run_laps
// jab.run_laps
}

for (team_member,0,6,1) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// jim.run_laps
// john.run_laps
// jeff.run_laps
// jake.run_laps
// job.run_laps
// jab.run_laps
}

for (team_member,0,6,2) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// john.run_laps
// jake.run_laps
// jab.run_laps
}

for (team_member,0,6,3) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// jeff.run_laps
// jab.run_laps
}

for (team_member,0,6,4) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// jake.run_laps
}

for (team_member,0,6,5) {
do (ObjectListItem(game.team,team_member),"run_laps")
// joe.run_laps
// job.run_laps
}

for (team_member,2,6,1) {
do (ObjectListItem(game.team,team_member),"run_laps")
// john.run_laps
// jeff.run_laps
// jake.run_laps
// job.run_laps
// jab.run_laps
}

for (team_member,2,6,4) {
do (ObjectListItem(game.team,team_member),"run_laps")
// john.run_laps
// jab.run_laps
}

// I think you get the idea now... lol


-----------

P.S.

you can also take a look here at another application of Lists+Dictionaries:

viewtopic.php?f=18&t=5138 (HK's 'Explore' and 'Travel' Code)

ask if you got any questions!

jaynabonne
I'm a bit confused... if the code is wrong, why not just delete it from the post? As opposed to leaving an incorrect code sample with a caveat way at the end that someone might not get to (having to wade through all the volume that precedes it)?

(Is someone paying you by the character? lol)

HegemonKhan
let me rest... then I'll go and fix it (NOT remove it: bad idea, read near end for why it is in my opinion a bad idea to remove it)... I'm exhuasted... that WAS A LOT OF WORK (~ 4+ hrs!)... YOU KNOW... lol. I'm really too tired... and right now, in my opinion, it is better to leave in, as they can (are still) seeing how it works generally (and it shows how the aspects of using 'for' works) even if it specifically doesn't function correctly, due to only one part of it. Aka, if only one part~gear of a clock~car doesn't work, you don't get rid of the entire clock~car, lol, as the rest of the clock's~car's parts are useful, as well as the clock~car itself.

----------

Jay wrote:Is anyone paying you by the character?, lol


I wish! I'd be richer than Bill Gates (the richest person in the world again, as the Mexican guy dropped back to 2nd place), if I was, lol :D

http://www.forbes.com/billionaires/

Bill Gates and that Mexican guy, they keep switching places between 1st and 2nd richest, lol.

'that Mexican guy' is: Carlos Slim Helu (I don't have his name known~memorized~recognitiion, like 'Bill Gates' name is, lol)

--------

This is an inaccurate statement:

Jay wrote:As opposed to leaving an incorrect code sample with a caveat way at the end that someone might not get to (having to wade through all the volume that precedes it)?


because:

lol.... my 'for' examples in the code box is only a few inches away from the bottom where my 'P.S.S. caveat' is (its literally only separated by my 'P.S.' tiny section between them)... oh well... now people will be well aware that my 'for' examples are currently with an error in them, and will be fixed up soonish... lol.

The 'caveat' is actually NOT: "way at the end (Jay)"

Forgewright
Ok, I created the stringlist in an objects attributes.
now I want to call the random string from the stringlist.

i use:
n = GetRandomInt(0, ListCount(stringlist) - 1)
but I name the (stringlist by it's real name (thingstosay) it being the actual name of the stringlist

getting:
n = GetRandomInt(0, ListCount(thingstosay) - 1)
then I use:

msg("The NPC says, '" + StringListItem(thingstosay), n) + ".'")

I get error message( unkknown object or variable; things to say)
so I add

Orc_Guard1.thingstosay

now it does not recognise the Orc_guard.thingstosay.

Here is what I have:
n = GetRandomInt (0, ListCount(Orc_Guard1.thingstosay) - 1)
msg ("Org says, '" + StringListItem(Orc_Guard1.thingstosay, n) + "."



thingstosay is
Split ("Why do dwarves have such big nostrils?.......Because they have big fingers.; An Ogre walks into a bar with flint and steel. The bartender lets him in but says, "Don't start anything."; “Lord Talbert sent for his daughter, Vivian, North of here in Carn by the foothills of Shankspur Mountains but we stopped her coach and kidnapped her, she in being held in the prison hall.", ";")

Object is Orc Guard1 should I use alias? it's (an orc named Org)
or maybe I need to identify the stringlist in the code at first as
stringlist = thingstosay


I'm a mess.....

HegemonKhan
here's a minor mistake:

an incorrect+extra ' ) ' character in it, hehe

msg("The NPC says, '" + StringListItem(thingstosay), n) + ".'")

correct syntax:

StringListItem (List, Value:index number~variable)

change it to this:

msg("The NPC says, '" + StringListItem(thingstosay, n) + ".'")

and see if it works now...

if you added the 'thingstosay' Stringlist Attribute to an Object, then yes, you need to do this:

n = GetRandomInt (0, ListCount(Orc_Guard1.thingstosay) - 1)
msg ("Org says, '" + StringListItem(Orc_Guard1.thingstosay, n) + "."

don't know if you left off the ' ) ' and a single quote too, in your game code, or just from pasting it here, but it needs it (if it's not in your game code):

(I'm using the adding double quotes, along with spaces, just so you can see it better, rather than using the added single quotes)

(the forward slash goes on the LEFT SIDE of the double quote you want to add~show in your message's contents, like with how other languages to it with their symbol codes, $P$G ~ whatever the command line's 'prompt' symbol-code is for ' C:\> ' ~ I forgot, which I have trouble with remembering all of them, lol ~ why I like quest's XML better at the moment, hehe)

n = GetRandomInt (0, ListCount(Orc_Guard1.thingstosay) - 1)
msg ("Org says, /" " + StringListItem(Orc_Guard1.thingstosay, n) + "./" ")

---------

this will only return~output the 'string~text' as it is a Stringlist, if you want a long sentence~phrase~message to be returned, you need to use a Stringdictionary (or a Scriptdictionary), instead.

------

there may also an issue with using periods~dots in your 'thingstosay' stringlist itself (the actual List's syntax)... not sure though (the periods~dots are the symbols to end~break code lines, but I'm not sure if that's occuring here causing an error):

Split ("Why do dwarves have such big nostrils?.......Because they have big fingers.; An Ogre walks into a bar with flint and steel. The bartender lets him in but says, "Don't start anything."; “Lord Talbert sent for his daughter, Vivian, North of here in Carn by the foothills of Shankspur Mountains but we stopped her coach and kidnapped her, she in being held in the prison hall.", ";")

HegemonKhan
also...

for your stringlist, ya it needs to be 'defined' (unless you're doing a local variable usage instead: your entire related code is all in the same script block), using any of these methods:

<object name="Orc_Guard1">
<attr name="thingstosay" type="simplestringlist">xxx1;xxx2;xx3;etc4</attr>
</object>


<object name="Orc_Guard1">
<attr name="thingstosay" type="stringlist">
// whatever the syntax~format is its vertical form (which I really don't like... who+why use+uses this form???), I don't have it memorized~learned yet, I get a bit confused as to whether it needs 'key+item+value' or 'key~item + value', or just 'key~item~value', lol
</attr>
</object>


<function name="xxx">
Orc_Guard1.thingstosay = split ("xxx1;xxx2;xxx3;etc4", ";")
</function>


<function name="xxx">
Orc_Guard1.thingstosay = NewStringList ()
list add (Orc_Guard1.thingstosay, "xxx1")
list add (Orc_Guard1.thingstosay, "xxx2")
list add (Orc_Guard1.thingstosay, "xxx3")
list add (Orc_Guard1.thingstosay, "etc4")
</function>

jaynabonne
The stringlist format looks like this:

    <names type="stringlist">
<value>String one</value>
<value>String two</value>
<value>String three</value>
</names>

and it comes in really handy if your strings have semicolons in them. (You can't use simplestringlist in that case.) It's also more legible and less insanity inducing with longer strings.

HegemonKhan
Ah, that makes sense, (I haven't been in such a scenario yet), but the length it stretches it out (vertically) in code... I personally hate it (and then if I accidentally~forget, and save the game file while in the GUI~Editor or its code view mode... the engine converts my horizontal format to the vertical one... and I got to go back and manually undo it, as I can't stand it... ARGHHHH !!!, laughs). It is nicely organized... but not enough for the 'unsightly' vertical length it becomes... this bad (cons) organization~ergonomics overrides its good (pros) organization~ergonomics that you mention, my me, anyways.

Though, if I need to use the semicolons and etc characters, then obviously, as you informed me (good to know, when it comes up for me, hehe), must be done this way, as it can't be done via the 'split' or 'simplestringlist' ways.

--------

I am realizing its usefulness more now, as my mind is thinking of making dialogue systems (which I've yet to attempt), where you got long and~or complex messages for your Values, instead of just the single words I've been using thus far. (I still don't like the vertical stretching though, I never will !, laughs)

Forgewright
Just got home from work. It's 11:00 pm here in Ohio, USA. Anyway, I''l see if I can figure this out. With all the help I ought to, but then again I might over think it.

The Pixie
jaynabonne wrote:The stringlist format looks like this:

    <names type="stringlist">
<value>String one</value>
<value>String two</value>
<value>String three</value>
</names>

and it comes in really handy if your strings have semicolons in them. (You can't use the split or simplestringlist method in that case.) It's also more legible and less insanity inducing with longer strings.

You can still use Split, you just use a different character to split on. I often use the vertical pipe, |, as it is not used in prose.
string_list = Split("Blab blab|Blah; then blah", "|")

Your way is perhaps better practice, but using Split way is less typing and is easier to show/explain on the forum as part of the code.

Forgewright
Sweet! I got it to work. I even added a remove from list function and he wont repeat himself.
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, '" + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))

The problem now is I need to add a way to end the script. It errors when the 3 strings are gone. I tried :
if (StringListItem(Orc Guard.thingstosay, n) = null) {
msg ("Thats all I got for now.")
but null is the wrong variable. How is this done?
Oh I'll want to add more strings to his stringlist as the player progresses in the game. so nothing too destructive.....

and no Split used in thingtosay. just added each item to the stringlist

I'll try to figure it out before anyone replies.....

By the way... It only took me 3 1/2 hours to get this far.
Nyuck, nyuck

The Pixie
I will give you a hint: Use ListCount

HegemonKhan
@Forgewright:

if you're interested in some example test games on 'for' in action, take a look at this link:

viewtopic.php?f=18&p=35594#p35594

you can just study the code, or play out the test~sample games to see it in action.

Forgewright
I've been listcounting my ass off. I'm sure listcount must = something.....

The test function games wouldn't load in Gui for me.

n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, '" + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))

I've added a if (every single item in the script) = 0 with no luck

Maybe listcount should be made with it's own variable in attributes?
then referenced in the script.

somehow I have to ask if listcount = 0 items
but Items is not valid
maybe 0 stringlistitems
if (ListCount(Orc Guard.thingstosay)) = (StringListItem = 0)

I know I'm in over my head but at 50 I feel compelled to swim in the deep end......

The Pixie
You are over thinking it.
if (ListCount(Orc Guard.thingstosay) = 0) {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, '" + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}
else {
msg ("The Orc has nothing to say.")
}

But then I am not 50 until September, so it is easy for me.

jaynabonne
The Pixie wrote:

"jaynabonne"

The stringlist format looks like this:

    <names type="stringlist">
<value>String one</value>
<value>String two</value>
<value>String three</value>
</names>

and it comes in really handy if your strings have semicolons in them. (You can't use the split or simplestringlist method in that case.) It's also more legible and less insanity inducing with longer strings.

You can still use Split, you just use a different character to split on. I often use the vertical pipe, |, as it is not used in prose.
string_list = Split("Blab blab|Blah; then blah", "|")

Your way is perhaps better practice, but using Split way is less typing and is easier to show/explain on the forum as part of the code.



You are correct - I was wrong about Split.Not sure where my head was. :) "simplestringlist" must have gone to my brain... I've amended the original post.

jaynabonne
The Pixie wrote:
But then I am not 50 until September, so it is easy for me.

I turned 50 last month. All downhill from here. :lol:

Forgewright
That's funny. I don't turn 50 till July.

First thing Pixie. I copy pasted your scrit and it prints "The Orc has nothing to say" everytime. nothing else. This would go under the orcs verb attributes right? things to say under orcs attributes.

I realize I have so much to learn here and am thankful for guidance from folks my own age. I have a book written and I want to publish it in a different kind of media. Text adventures were a big deal in the 80's and maybe there would be a following that would enjoy it. I realize there isn't any money in it but the advantage of learning to code seems interesting.

finding more downloadable games would answer a lot of questions for me. if anyone has some let me know. I don't expect you guys to do everything for me and lead me around by the hand.....

oh heres whats up
orc attribute string list:

<thingstosay type="stringlist">
<value>" An Ogre walks into a bar with flint and steel. The bartender lets him in but says, Don't start anything"</value>
<value>"Why do dwarves have such big nostrils?.......Because they have big fingers"</value>
<value>“Lord Talbert sent for his daughter, Vivian, North of here in Carn by the foothills of Shankspur Mountains but we stopped her coach and kidnapped her, she is being held in the prison hall."</value>
</thingstosay>

orc verb script:

<speak type="script">
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, '" + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
(listcount(Orc Guard.thingstosay))
if (listcount = 0) {
}
msg (Thats all I have for now.....)
</speak>

I notice this adds the script to the orcs attributes under "speak" when I add it to the to the orcs verbs attribute.

Truly+thankful = much

Forgewright
oh, I just remembered a discussion about stringlists. I have them stacked. I bet I need to put them in horizonally. Bout to find out.....

Forgewright
nope no change

HegemonKhan
I don't think you need the quotes when putting it in the tag blocks, edited out them below:

<thingstosay type="stringlist">
<value>An Ogre walks into a bar with flint and steel. The bartender lets him in but says, Don't start anything</value>
<value>Why do dwarves have such big nostrils?.......Because they have big fingers</value>
<value>Lord Talbert sent for his daughter, Vivian, North of here in Carn by the foothills of Shankspur Mountains but we stopped her coach and kidnapped her, she is being held in the prison hall.</value>
</thingstosay>


and here's how you do the 'ListCount=0' in this part:

<speak type="script">
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, " + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
if (ListCount (Orc Guard.thingstosay) = 0) {
// scripts
}
msg (Thats all I have for now.....)
</speak>

Forgewright
And here's the working copy:

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, " + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}

Please, no need for applause...just throw money.

Forgewright
Hegemon, the listcount Example you gave will error out before it can run the:

if (ListCount (Orc Guard.thingstosay) = 0) {
// scripts
}
msg (Thats all I have for now.....)
</speak>

it just goes first is all.

By the way, how do you get those cool code boxes in you posts

Forgewright
this in code

<thingstosay type="stringlist">
<value>An Ogre walks into a bar with flint and steel. The bartender lets him in but says, Don't start anything</value>
<value>Why do dwarves have such big nostrils?.......Because they have big fingers</value>
<value>Lord Talbert sent for his daughter, Vivian, North of here in Carn by the foothills of Shankspur Mountains but we stopped her coach and kidnapped her, she is being held in the prison hall.</value>
</thingstosay>
<speak type="script">
if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, " + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}
</speak>

The Pixie
Forgewright wrote:By the way, how do you get those cool code boxes in you posts

Either go to the full editor (button below the text area), select the text and click on thr "Code" button, or type the tags yourself.

Tags are surrounded by square brackets, and the end tag also has a slash before the name, like this.

[tag]Some text[/tag]

For code, the tag is "code", for a quote, use "quote", for bold or italics use "b" or "i".

Forgewright
Thanks,
Right in the middle of adding lines to the beginning of the "speak script" to stop a player from trying to speak to Orc Guard after beginning a fight.

Forgewright
I freaking did it!!!

Here's the coding for speaking to the orc and not being able to speak to the orc after begining a fight.

 <thingstosay type="stringlist">
<value>"An Ogre walks into a bar with a flint and steel. The bartender lets him in but says, "Don't start anything."</value>
<value>"Why do dwarves have such big nostrils?.......Because they have big fingers."</value>
<value>"In the town of Carn, Lord Talbert sent for his daughter, Vivian, but we stopped her coach and kidnapped her just north of here by the foothills of Shankspur Mountains, she is being held in the prison hall."</value>
</thingstosay>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Speak to</value>
<value>Attack</value>
</displayverbs>
<speak type="script">
if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, " + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}
</speak>
<attack type="script">
list remove (Orc Guard.displayverbs, "Look at")
list remove (Orc Guard.displayverbs, "Speak to")
this.temp_db = 0
this.temp_ob_now = 0
this.temp_ob_next = 0
this.temp_damage = 0
do (this, "doattack")
</attack>

HegemonKhan
Congrats, Forgewright, well done! HK throws pretend money at him, hehe.

you can use 'this' for your Object also in the 'list remove', and don't forget, at the end of the fight (or whatever the action~event) to add back in your display~inventory Verbs, well maybe not for this scenario, as the Object will be dead... (well, you can still look at it... but not speak to it, lol)

if things are used over and over again, and static (unchanged), then you might want to add the scripts to a Function, and then put that Function (via 'call function' Script or in code, via directly writing in its name) to where ever you want (Verbs, Game's 'start' Script, Commands, and etc), and also take a look at Object Types (Types) too:

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

these are baskets for Attributes, which can be added to the Objects as 'inherit' Attributes, which provides that Object with all of the Attributes within the Object Type that you added to an Object via as an 'inherit' Attribute. When using Object Types, this is where the 'this' is useful, as it 'Gets' the Object of the scriptings, which is perfect for Object Types being applied to many (different) Objects, via as 'inherit' Attributes.

for example, the built-in Object Types 'editor_room', editor_object', and 'editor_player', apply its group of Attributes, which are a bunch of Editor 'controls', giving you the functionality of the Tabs and etc options~stuff for that Object within the GUI~Editor, but they then disappear when you play the game, as they're only focused upon the Editor. This is a bit of an annoyance, as people often want to use them to check~get these ('room', 'player', 'object') different object types. Instead, you got to make~ad your own such Attributes, for doing this, as again they (editor_room, editor_player, editor_object) are just for the GUI~Editor only.

Forgewright
Well I screwed up my aslx. I cant find the reference the error is telling me about. I am going to have to always make a copy of the master ato change codes in then when I know it works I can save it over the old one.FIXED and/or SOLVED. I was missing an object element

If anyone wants to take a 2d5 stab at it, help yourself.



or here's the code

<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Eanatas">
<gameid>2b34a9e4-2f5d-4b03-b679-e3dbd5bf912b</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<gridmap />
<appendobjectdescription />
<multiplecommands />
<defaultfontsize type="int">14</defaultfontsize>
<menufontsize type="int">10</menufontsize>
<attr name="autodescription_description" type="int">2</attr>
<attr name="autodescription_youcansee" type="int">4</attr>
<defaultbackground>WhiteSmoke</defaultbackground>
<pov type="object">player</pov>
<start type="script">
</start>
</game>
<command name="fly">
<script>
if (not IsSwitchedOn(player)) {
SwitchOn (player)
msg ("You spread your wings and take flight.")
}
else {
msg ("You are already flying.....")
}
</script>
</command>
<object name="Bristol">
<inherit name="editor_room" />
<object name="Mount Mormont">
<inherit name="editor_room" />
<object name="Karnuke Lair">
<inherit name="editor_room" />
<exit alias="south" to="Lair Ledge">
<inherit name="southdirection" />
</exit>
<exit alias="east" to="Stone Stairs">
<inherit name="eastdirection" />
</exit>
</object>
<object name="Stone Stairs">
<inherit name="editor_room" />
<exit alias="west" to="Karnuke Lair">
<inherit name="westdirection" />
</exit>
<exit alias="out" to="Forest Clearing">
<inherit name="outdirection" />
</exit>
</object>
<object name="Huge Cavern">
<inherit name="editor_room" />
<exit alias="west" to="Tunnel Ledge">
<inherit name="westdirection" />
</exit>
<exit alias="east" to="Lair Ledge">
<inherit name="eastdirection" />
</exit>
</object>
<object name="Lair Ledge">
<inherit name="editor_room" />
<exit alias="west" to="Huge Cavern">
<inherit name="westdirection" />
</exit>
<exit alias="north" to="Karnuke Lair">
<inherit name="northdirection" />
</exit>
</object>
<object name="Tunnel Ledge">
<inherit name="editor_room" />
<exit alias="west" to="Tunnel">
<inherit name="westdirection" />
</exit>
<exit alias="northwest" to="Prision Hall">
<inherit name="northwestdirection" />
</exit>
<object name="Lava Lake">
<inherit name="editor_object" />
</object>
<exit alias="east" to="Huge Cavern">
<inherit name="eastdirection" />
</exit>
</object>
<object name="Hags Den">
<inherit name="editor_room" />
<exit alias="north" to="Cave">
<inherit name="northdirection" />
</exit>
</object>
<object name="Cell 3">
<inherit name="editor_room" />
<exit alias="southwest" to="Prision Hall">
<inherit name="southwestdirection" />
</exit>
</object>
<object name="Cell 2">
<inherit name="editor_room" />
<exit alias="south" to="Prision Hall">
<inherit name="southdirection" />
</exit>
</object>
<object name="Cell 1">
<inherit name="editor_room" />
<exit alias="southeast" to="Prision Hall">
<inherit name="southeastdirection" />
</exit>
</object>
<object name="Prision Hall">
<inherit name="editor_room" />
<exit alias="west" to="Barrocks">
<inherit name="westdirection" />
</exit>
<exit alias="northwest" to="Cell 1">
<inherit name="northwestdirection" />
</exit>
<exit alias="north" to="Cell 2">
<inherit name="northdirection" />
</exit>
<exit alias="northeast" to="Cell 3">
<inherit name="northeastdirection" />
</exit>
<exit alias="southeast" to="Tunnel Ledge">
<inherit name="southeastdirection" />
</exit>
</object>
<object name="Supply">
<inherit name="editor_room" />
<exit alias="east" to="Barrocks">
<inherit name="eastdirection" />
</exit>
</object>
<object name="Tunnel">
<inherit name="editor_room" />
<alias>Tunnel</alias>
<exit alias="west" to="Cave">
<inherit name="westdirection" />
</exit>
<exit alias="east" to="Tunnel Ledge">
<inherit name="eastdirection" />
</exit>
<object name="Barrocks">
<inherit name="editor_room" />
<exit alias="south" to="Cave">
<inherit name="southdirection" />
</exit>
<exit alias="west" to="Supply">
<inherit name="westdirection" />
</exit>
<exit alias="east" to="Prision Hall">
<inherit name="eastdirection" />
</exit>
<object name="Orc Guard2">
<inherit name="editor_object" />
<inherit name="monster" />
<alias>Orc Guard</alias>
<attackasgroup />
<hurtbyweapon>A quit shot with your claws rips into the Guard.</hurtbyweapon>
<death>The Guard falls back and crashes to the floor.</death>
<lookwhendead>The guard didn't seem to want to fight. His face shows a certain puzzlement.</lookwhendead>
<level type="int">1</level>
<object name="Leather Helmet1">
<inherit name="editor_object" />
<inherit name="armour" />
<alias>Leather Helmet</alias>
<level type="int">1</level>
<price type="int">1</price>
</object>
<object name="Steel Mace">
<inherit name="editor_object" />
<inherit name="weapon" />
<damagedicesides type="int">6</damagedicesides>
<price type="int">3</price>
</object>
<object name="Woven Shirt">
<inherit name="editor_object" />
<inherit name="armour" />
</object>
<object name="Leather Boots">
<inherit name="editor_object" />
<inherit name="armour" />
<level type="int">1</level>
<price type="int">1</price>
</object>
</object>
</object>
<object name="Cave">
<inherit name="editor_room" />
<alias>Cave</alias>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="west" to="Mountain Path">
<inherit name="westdirection" />
<look>The cave is fairly large. Carved out of brown stone and mixed with black volcanic rock which shines from the sunlight coming in from the entrance to the outside to the west of you. The air is hot and blows passed you as it escapes outside. </look>
</exit>
<exit alias="north" to="Barrocks">
<inherit name="northdirection" />
</exit>
<exit alias="east" to="Tunnel">
<inherit name="eastdirection" />
</exit>
<exit alias="south" to="Hags Den">
<inherit name="southdirection" />
</exit>
<object name="Orc Guard">
<inherit name="editor_object" />
<inherit name="monster" />
<inherit name="namedmale" />
<hurtbyweapon>You slash into the guard with your claws. He begins to reel back but stands firm. Blood is pouring out of him.</hurtbyweapon>
<death>The guard clutches his chest and falls to the ground.</death>
<lookwhendead>Yep...He's dead. Laying lifeless on the cave floor. You notice a puzzled look on his face.</lookwhendead>
<attackasgroup />
<level type="int">1</level>
<inroomdescription>Standing Guard at the entrance to Mount Mormont is an orc.</inroomdescription>
<look>You've known this Orc for a while now. His name is Org. A bulky orc with huge muscles and attitude to go with it. The look on his face reads," I may be stupid, but I'm sure if you attack me, I'll stomp you anus into the rocks". </look>
<thingstosay type="stringlist">
<value>"An Ogre walks into a bar with a flint and steel. The bartender lets him in but says, "Don't start anything."</value>
<value>"Why do dwarves have such big nostrils?.......Because they have big fingers."</value>
<value>"In the town of Carn, Lord Talbert sent for his daughter, Vivian, but we stopped her coach and kidnapped her just north of here by the foothills of Shankspur Mountains, she is being held in the prison hall."</value>
</thingstosay>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Speak to</value>
<value>Attack</value>
</displayverbs>
<speak type="script">
if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, " + StringListItem(Orc Guard.thingstosay, n))
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}
</speak>
<attack type="script">
list remove (Orc Guard.displayverbs, "Look at")
list remove (Orc Guard.displayverbs, "Speak to")
this.temp_db = 0
this.temp_ob_now = 0
this.temp_ob_next = 0
this.temp_damage = 0
this.temp_desc = 0
do (this, "doattack")
</attack>
<object name="Short Sword">
<inherit name="editor_object" />
</object>
<object name="Leather Armour">
<inherit name="editor_object" />
</object>
<object name="Leather Helmet">
<inherit name="editor_object" />
</object>
</object>
</object>
</object>
<object name="Swindon">
<inherit name="editor_room" />
<object name="Sowers Mill">
<inherit name="editor_room" />
</object>
</object>
<object name="Mountain Path">
<inherit name="editor_room" />
<exit alias="east" to="Cave">
<inherit name="eastdirection" />
</exit>
</object>
<object name="Bridgewater">
<inherit name="editor_room" />
</object>
<object name="Forest Clearing">
<inherit name="editor_room" />
<exit alias="in" to="Stone Stairs">
<inherit name="indirection" />
</exit>
</object>
<object name="Redditch">
<inherit name="editor_room" />
</object>
<object name="Minehead">
<inherit name="editor_room" />
</object>
<object name="Triverton">
<inherit name="editor_room" />
</object>
<object name="Ringwood">
<inherit name="editor_room" />
</object>
<object name="Banbury">
<inherit name="editor_room" />
</object>
<object name="Wells">
<inherit name="editor_room" />
</object>
<object name="Woking">
<inherit name="editor_room" />
</object>
<object name="Newbury">
<inherit name="editor_room" />
</object>
</object>
</asl >

The Pixie
This line:
          <object name="Barrocks">

Should be replaced by these two (and you need some libraries includes, but I guess you know that).
      </object>
<object name="Barrocks">

The Pixie
By the way, I would avoid using the full code view as much as possible. It is too easy to make mistakes like this, and typing those XML tags is much better handled by Quest. Use code view for scripts (the seventh icon near where it says Add new script), not for XML.

If you do get this error, the way I approach it is to make a copy (very important!), and then go though and remove all the exits, and then see if that works. Exits look like this in XML:
        <exit alias="north" to="Barrocks">
<inherit name="northdirection" />
</exit>

If it now will go to GUI view, it was a problem with exits. If not, some remove rooms, and try again. At some point it will go to GUI view (or give a different error), and you will know the fault was in the bit you just deleted.

You have to delete the exits first because the points to rooms you will be deleting; deleting a room but not an exit to that room will generate a new error.

Forgewright
Greetings folks. I have been adding and changing my Quest game daily. Playing others and learning what I can. finding examples of the coding I need is tough. I made a stringlist of random dialogue for a character to respond with when spoken to. I want to change another character's alias when a certain item of this stringlist is used. This will give the character a name when the player is given information about them. If they run across this character before this information the game will refer to her a "a woman" and after the info her name.
I try StringListItem(Orc Guard.thingstosay, 2) but this refers to the number of items in the stringlist and not the 0, 1, 2, order of the stringlist. Lets say the number 2 item is randomly selected from the stringlist with the info needed about the woman. I now want to have this change the woman's alias to Vivian. I can't figure out the expression. How do I code ( If stringlist item chosen = the number two list item then change woman.alias to Vivian.alias)?
My ass is dun searching and trying. Thanks

I really like the Switch and Case method of scripting over the if and else method but I havent gotten proficient at it yet. Seems much easier.....

jaynabonne
To select a random string from the list, you must generate an index at some point (e.g. the result of GetRandomInt). Just save that in a variable and then compare it to the number 2. In other words, if you have something like:

s = StringListItem(list, GetRandomInt(0, ListCount(list)-1))


then split it into:

index = GetRandomInt(0, ListCount(list)-1)
s = StringListItem(list, index)

if (index = 2) {
// do what you want
}


and then you have the index to compare.

I try StringListItem(Orc Guard.thingstosay, 2) but this refers to the number of items in the stringlist and not the 0, 1, 2, order of the stringlist.


I don't know what you mean by this. It should return the third element in the list.

Forgewright
Thanks Jay. I'll play around with that and see if I can get it working in my script.

HegemonKhan
<object name="npc_1">
<alias>woman</alias>
<chat type="script">
msg ("Hi, my name is " + this.alias + ".")
</chat>
</object>

<object name="npc_2">
<alias>man</alias>
<chat type="script">
invoke (ScriptDictionaryItem (this.chat_scriptdictionary_attribute, StringListItem (this.chat_stringlist_attribute, GetRandomInt (0, ListCount (this.chat_stringlist_attribute) - 1))))
</chat>
<attr name="chat_stringlist_attribute" type="simplestringlist">woman;man;option3;option4;option5</attr>
<chat_scriptdictionary_attribute type="scriptdictionary">
<item key="woman">
firsttime {
msg ("That other npc, the woman, is known as 'Sarah'.)
npc_1.alias = "Sarah"
} otherwise {
msg ("Have you talked to Sarah yet?")
}
</item>
<item key="man">
msg ("Hi, my name is " + this.alias + ".")
if (this.alias = "man") {
this.alias = "Sam"
}
</item>
<item key="option3">
msg ("you chose option3")
</item>
<item key="option4">
msg ("you chose option4")
</item>
<item key="option5">
msg ("you chose option5")
</item>
</chat_scriptdictionary_attribute>
</object>

<verb>
<property>chat</property>
<pattern>chat</pattern>
<defaultexpression>"You can't chat with it."</defaultexpression>
</verb>


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

explanation of this (as it's quite confusing, especially as a single code line, lol):

invoke (ScriptDictionaryItem (this.chat_scriptdictionary_attribute, StringListItem (this.chat_stringlist_attribute, GetRandomInt (0, ListCount (this.chat_stringlist_attribute) - 1))))

the 'this' in 'this.Attribute_name' is a special command that will GET its parent Object for you (I'm too lazy to type in 'npc_1' or 'npc_2', laughs. Though using 'this' is useful for global~dynamic usage, obviously, aside from my laziness)

invoke:

this activates~runs~executes script(s)

ScriptDictionaryItem:

this returns the selected Variable's Value:Script(s)

Script Dictionary:

Variable_string_name = Value:Script(s)

example (in pseudo-code):

(I'm using numbers for my Variables in this quick example for simplicity, but they can be Strings~text~words too, such as 'red', 'blue', and 'yellow' )

1 = msg ("Hi")
msg ("My name is HK")
msg ("I'm still learning to code.")

2 = msg ("What is your name?)
msg ("Nice to meet you, XXX.")
msg ("Do you know how to code (well)?")

3 = msg ("Well, I got to get back to learning to code.")
msg ("We should talk again.")
msg ("Bye XXX, and have a good day.")


if the Variable '1' is selected (via):

ScriptDictionaryItem (Object_name.Attribute_name, 1)

then it'll return these scripts:

msg ("Hi")
msg ("My name is HK")
msg ("I'm still learning to code.")

and the 'invoke' will then execute~activate~run them

(you only use 'invoke' with 'ScriptDictionaryItem' ~ Script Dictionaries, as its Values are Type:Script)

// (the below other Dictionaries and Lists, return Strings and Objects, so these you often want to set them to something or whatever, as they're NOT Scripts):
//
// String Dictionary:
//
// Variable_string_name = Value:String
//
// Object Dictionary:
//
// Variable_string_name = Value:Object
//
// String List:
//
// Index_Number = Value:String
//
// Object LIst:
//
// Index_Number = Value:Object

anyways, back to explaining the rest of it...

instead of directly typing in the desired Variable for~of our Script Dictionary for the 'ScriptDictionaryItem' to use, we're instead going to get (select) that Variable from a String List (via):

ScriptDictionaryItem (this.chat_scriptdictionary_attribute, StringListItem (this.chat_stringlist_attribute, Index_Number) )

and again, instead of directly typing in the desired Index_Number for~of our String List for the 'StringListIitem' to use, we're instead going to get (select) that Index_Number randomly (via):

StringListItem (this.chat_stringlist_attribute, GetRandomInt (0, ListCount (this.chat_stringlist_attribute) - 1) )

---------

let me know if this is confusing and you need help with understanding~following it (I'm a very poor explain'er, sighs).

--------

P.S.

Jay created a really ingenius advanced dialogue~conversation system, which I think I kinda get the basic gist of but aside from this it's way beyond my ability+comprehension lol, which you may be interested in:

viewtopic.php?f=18&t=3909

and Jay's game's source code, which uses his dialogue system:

viewtopic.php?f=18&t=4889

and Jay's actual game itself:

viewtopic.php?f=5&t=4883

ask Jay though if you need any help or got questions, as it's far beyond my ability+comprehension, laughs.

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

P.S.S.

forgewright wrote:I try StringListItem(Orc Guard.thingstosay, 2) but this refers to the number of items in the stringlist and not the 0, 1, 2, order of the stringlist.


Lists:

game.primary_pigment_colors_stringlist_attribute = split ("red;blue;yellow", ";")

String Lists, conceptually:

Variable (Index_Number) ~ "Value" ~ (quantity of items in the List)

0 = "red" (1/3)
1 = "blue" (2/3)
2 = "yellow" (3/3)

the Index_Numbers (0, 1, and 2) is what the 'StringListItem' uses to get (return) what Value:

StringListItem (game.primary_pigment_colors_stringlist_attribute, 0) ====> "red"
StringListItem (game.primary_pigment_colors_stringlist_attribute, 1) ====> "blue"
StringListItem (game.primary_pigment_colors_stringlist_attribute, 2) ====> "yellow"
StringListItem (game.primary_pigment_colors_stringlist_attribute, 3) ====> ERROR, as there is no 4th item: (4/3 ... HUH?)

However, the 'ListCount (game.primary_pigment_colors_stringlist_attribute)' DOES return the quantity of items in the list: 3

so, this is why you need to do:

ListCount (List) - 1

in the 'max' for:

GetRandomInt (min,max)

player.color = StringListItem (game.primary_pigment_colors_stringlist_attribute, GetRandomInt (0, ListCount (game.primary_pigment_colors_stringlist_attribute) -1) )

conceptually:

StringListItem (game.primary_pigment_colors_stringlist_attribute, 1-1=0) ====> "red"
StringListItem (game.primary_pigment_colors_stringlist_attribute, 2-1=1) ====> "blue"
StringListItem (game.primary_pigment_colors_stringlist_attribute, 3-1=2) ====> "yellow"
StringListItem (game.primary_pigment_colors_stringlist_attribute, 3-0=3) ====> ERROR, as there is no 4th item: (4/3 ... HUH?)

Forgewright
This is my first attempt at the script.
if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
if (IsSwitchedOn(Orc Guard)) {
msg ("\" No talking. Only killing.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
msg ("The Orc says, " + StringListItem(Orc Guard.thingstosay, n))
index = GetRandomInt(0, ListCount(Orc Guard.thingstosay)-1)
s = StringListItem(Orc Guard.thingstosay, index)
if (index = 2) {
set (Woman, "alias", Vivian)
}
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}
}


this shows no errors but does not change the woman's name to Vivian

TinFoilMkIV
I have spotted a flaw with that code involving why its not changing the name, however I'm not sure how to go about resolving it at the moment.

The problem is, your code to change the woman's alias, is tied to the index number, however the string in the list itself is not locked to that index, and since you are removing items from the list, that index may not always exist and therefore can exhaust all the dialogue without ever calling index #2.

The solution I can imagine would be tying the change of alias to that dialogue phrase, but I'm not sure how to go about that.

Forgewright
Try #2
if ((ListCount(Orc Guard.thingstosay) = 0)) {
msg ("\"That's all I have for now.\"")
index = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
n = StringListItem(Orc Guard.thingstosay, index)
if ((index = 2)) {
set (Woman, "alias", Vivian)
msg ("(\"The Orc says, \" + StringListItem(Orc Guard.thingstosay, n)")
}
else {
list remove (Orc Guard.thingstosay, StringListItem(Orc Guard.thingstosay, n))
}
}


Now the orc gives on response....

The Pixie
What TinFoilMkIV says makes sense. How about checking if the string contains the word "Vivian" instead of checking the index?

Also, you have a couple of lines in there that do not really do anything. I have not tested it, but try this:
if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
if (IsSwitchedOn(Orc Guard)) {
msg ("\" No talking. Only killing.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (Instr(s, "Vivian")) {
set (Woman, "alias", Vivian)
}
list remove (Orc Guard.thingstosay, s)
}
}

Forgewright
The "Instr" is new to me. The code retrieves the first random ListItem but gives the error:
Script.PNG

I know Boolean is a true or false statement and I assume the Int32 is Integer. Is S some how returning an Integer?

HegemonKhan
that's what the error message indeed is saying, a mis-match of Attribute Types: int+boolean = ?HUH?, can't compute!

In Pixie's code (not sure about yours):

if (IsSwitchedOn(Orc Guard)) {

shouldn't this be:

if (IsSwitchedOn(Orc Guard.Boolean_Attribute_name)) {

....

actually, just take out this line entirely..., it should look like this:

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
} else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (Instr(s, "Vivian")) {
set (Woman, "alias", "Vivian")
}
list remove (Orc Guard.thingstosay, s)
}


----------

actually... just looked up 'instr', see:

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

indeed, it is returning an 'int', so that's the cause of the error..., code should look like this:

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
} else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (s = "Vivian") {
set (Woman, "alias", "Vivian")
}
list remove (Orc Guard.thingstosay, s)
}


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

IGNORE this below, as in closer reading of 'instr', it's returning the 'int' of the CHARACTER~SYMBOL position (nothing to do with the Index_Number) ... so the 'instr' shouldn't be used at all !!!

you could probably do this (below), but if you're adding~removing items from a list, than the Index_Numbers to Values, are changing, and not constant, and thus it's a bad idea to check the Index Number anyways:

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
} else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (Instr (s, "Vivian") = ToInt (n) ) {
set (Woman, "alias", "Vivian")
}
list remove (Orc Guard.thingstosay, s)
}

Forgewright
The switched on orc guard line refers to whether he is switched on or not. Once he is attacked I switch him on so that line won't allow the player to "Speak to the orc anymore..only fight. That was the only way I could figure out how to do it.

This last script errors for:
Capture.PNG

TinFoilMkIV
I think I may have come up with a solution. The problem being how do we reference the right string and not just an index in the list. Using the 'StartsWith' function you can check if the string starts with a certain string segment. There's other similar functions, but for the purpose of simply confirming we have one of a few strings this should be sufficient.

The next complication would potentially be making sure you're checking for a string that exists in the first place, as one type can cause the entire script to fail. My method would be to set your test against string equal to the list item that you want before any modifications are done to the list. I think it will be something like this.

StartsWith documentation
http://docs.textadventures.co.uk/quest/ ... swith.html

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
if (IsSwitchedOn(Orc Guard)) {
msg ("\" No talking. Only killing.\"")
}
else {
keystring1 = StringListItem(Orc Guard.thingstosay, 2)
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (StartsWith(s, keystring1)) {
set (Woman, "alias", Vivian)
}
list remove (Orc Guard.thingstosay, s)
}


Hopefully I set that up right and if not at least get across what I was trying to do.

HegemonKhan
Forgewright wrote:The switched on orc guard line refers to whether he is switched on or not. Once he is attacked I switch him on so that line won't allow the player to "Speak to the orc anymore..only fight. That was the only way I could figure out how to do it.

This last script errors for: xxx


ah okay, my bad.

as for the error of 'can't compute: change int into an int' (laughs ~ oopsy, my bad, lol), just remove the 'ToInt()', as it's not needed (I wasn't sure if it was needed or not):

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
} else {
if (Orc Guard.IsSwitchedOn) {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (Instr (s, "Vivian") = n) {
set (Woman, "alias", "Vivian")
}
list remove (Orc Guard.thingstosay, s)
} else {
msg ("Don't make me angry...")
}
}


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

but I don't think the 'Instr' will work, as it isn't getting the Index_Number, it's just getting the CHARACTER~SYMBOL position in the String List, joined as a String... as far as I think I am understanding it... lol

so this code will (should, HK crosses his fingers) work:

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
} else {
if (Orc Guard.IsSwitchedOn) {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (s = "Vivian") {
set (Woman, "alias", "Vivian")
}
list remove (Orc Guard.thingstosay, s)
} else {
msg ("Don't make me angry...")
}
}

The Pixie
Forgewright wrote:The "Instr" is new to me. The code retrieves the first random ListItem but gives the error:
Script.PNG
I know Boolean is a true or false statement and I assume the Int32 is Integer. Is S some how returning an Integer?

Oops, should be:

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
if (IsSwitchedOn(Orc Guard)) {
msg ("\" No talking. Only killing.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (not Instr(s, "Vivian") = 0) {
set (Woman, "alias", Vivian)
}
list remove (Orc Guard.thingstosay, s)
}
}

Instr tells you where in a string another string is, so
Instr("Do you know Vivian", "Vivian") returns 13
Instr("Do you know Mary", "Vivian") returns 0 (i.e., not found)

Quest was expecting a Boolean for the if statement, but I gave it the integer returned from Instr.

Forgewright
TIN Foil, your script work after I added a end bracket on the first else script.
Hk, I got an error message on the (Orc Guard.Is SwitchedOn) Don't know why.....but I don't think it was how I was wanting that part to work with switched on anyway.
Pixie, Your script worked as well.

I just had to ad "" around Vivian in second to last line.

Thanks to each of you for you time and excellence in coding.

HegemonKhan
oops... wrong syntax with that code line of mine, my bad

change it from:

if (Orc Guard.IsSwitchedOn) { script }

to:

if (IsSwitchedOn (Orc Guard)) { script }

TinFoilMkIV
Also realized a problem with mine. The 'keystring' is being set inside the conversation, so as you run the guard out of dialoge the keystring will actually change. It needs to just be set once then not be touched unless the entire dialogue is reset. Might be best to set key phrases in an attribute for the character or something like that.


keystring1 = StringListItem(Orc Guard.thingstosay, 2)
//this needs to be outside the conversation block so it is executed only once and happens before any list modification
//running this again later will cause the key to change what text it's looking for.

if (ListCount(Orc Guard.thingstosay) = 0) {
msg ("\"Thats all I have for now.\"")
}
else {
if (IsSwitchedOn(Orc Guard)) {
msg ("\" No talking. Only killing.\"")
}
else {
n = GetRandomInt (0, ListCount(Orc Guard.thingstosay) - 1)
s = StringListItem(Orc Guard.thingstosay, n)
msg ("The Orc says, " + s)
if (StartsWith(s, keystring1)) {
set (Woman, "alias", Vivian)
}
list remove (Orc Guard.thingstosay, s)
}

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

Support

Forums