Using 'this' in script dictionaries, and counting the number of indices

scrimshaw04

Hey all, I'm setting up a system that will randomise some descriptions in my game. I'm using a script dictionary which has a whole bunch of msgs, but occaisonally needs to refer to this.alias. Unfortunately when I envoke one the scripts in my dictionary it doesn't recognise what 'this' is. I can't use a specific object name, because the library will be applied to a range of objects. For example one of the scripts in my dictionary might look like this:

msg ("The " + this.alias + " is looking fine.")

Secondly, is there any way I can retrieve the number of items in a dictionary as an integer? The reason being is that I'm selecting a random script from the dictionary using code similar to this:

  n = ToString (GetRandomInt(0,x))
  invoke (ScriptDictionaryItem (this.script_library, n))

I'd like x to be the number of items in the dictionary, so that I don't have to manually change it every time I add a new index.


hegemonkhan

I too struggle to understand Script Dictionaries (and a few other things in whether you can pass Parameters/Arguments which has ~ "Dictionary Values" in their syntax or if this is refering to how it works underneath --- the doc is not clear/detailed on some stuff argh, in whether you can pass Parameters/Arguments/inputs for it or not. If not, then you can't use Script Dictionaries obviously if you need to pass Arguments/Parameters/inputs, which means you're going to have to change/craft a design with using Functions or Objects (and thus being able to use Script Attributes and Delegates: this allows you to have Parameters/Arguments and return types for Script Attributes, as you have with Functions), instead of using a Script Dictionary.

If you can pass/use Parameters/Arguments, then you must use 'do' and not 'invoke', as 'do' is able to use Parameters/Arguments (which then if the Script Dictionary can do/use as well, will take those Parameters/Arguments from 'do' and use them for its scripting). 'Invoke' is not able to take Parameters/Arguments. 'Do' (Script Attributes) and 'Set' (Attributes) are the powerful/useful Functions, whereas 'invoke' and using scripting (NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION) for Attributes are limited in their functionality. 'Invoke' can't use Parameters/Arguments, and the scripting can't use VARIABLES nor concatenation for its Object and Attribute, whereas 'set' can.

I don't think Dictionaries use/have index numbers, as you have a string for its key/reference instead*

*(take an actual human language dictionary. let's say you want to look up the definition of 'spulunking -- can't spell lol'. To get to it's definition, you can be given its page number which is what a List's index number essentially is, or, since the human dictionary is ordered alphabetically, you can get to 'spulunking' by using that string 'spulunking' itself too, you keep turning the pages until you get to the 's' section, and then you keep turning pages until you get to all the rest of the letters in 'spulunking', which is what/how quest/programming's Dictionary Attribute works)

You can though get the quantity of items from both Lists and Dictionaries, via: ListCount or DictionaryCount
(note that if you're working with Lists, the last item's index number is 1 less than the ListCount value, as List's index number starts at 0 not 1)

You can also check whether the List and Dictionary has an item or not via: ListContains or DictionaryContains or via your own scripting using 'foreach', but normally you'd just use the built-in ListContains/DictionaryContains, as they're using 'foreach' themselves underneath.

this link has all of the Functions for Dictionaries as hyperlinks:

http://docs.textadventures.co.uk/quest/using_dictionaries.html (you see the very bottom sentence mentions the 'DictionaryContains' and 'DictionaryCount' functions)

VARIABLE = DictionaryCount (DICTIONARY)

you have a problem with this, as Dictionaries don't have index numbers (at least I'm pretty sure of, meh):

n = ToString (GetRandomInt(0,x))
invoke (ScriptDictionaryItem (this.script_library, n))

so, you need to do this:

create a String List Attribute that has all of the strings/keys of your Dictionary
the 'getrandomint' will get the 'string' item from your String List Attribute
that string will get the scripting from the Script Dictionary Attribute
so, it should look like this:

(unfortunately, 'this' can't work with a Script Dictionary, unless you can use Parameters/Arguments, as the scriptings of a Script Dictionaries' items/keys is a different scope/level/layer, and thus 'this' can't traverse those different scopes/levels/layers (this is what Parameters/Arguments allow for / do)

(also, if you can use Parameters/Arguments with Script Dictionaries, you need to use 'do' instead of 'invoke', though good luck on how to code it's syntax correctly... and let me know how its done, lol. As I'm not sure on the syntax for doing it myself)

x = ListCount (STRINGLIST)
n = StringListItem (STRINGLIST, GetRandomInt(0, x - 1))
invoke (ScriptDictionaryItem (SCRIPTDICTIONARY, n))

or, you can put it all on one line (multiple lines is easier to read/understand and to have the syntax right --- getting the correct number of parenthesis right and in the right places on a single line is not easy, lol. But sometimes you just like the conciseness of having it all on one line... meh):

invoke (ScriptDictionaryItem (SCRIPTDICTIONARY, StringListItem (STRINGLIST, GetRandomInt (0, ListCount (STRINGLIST) - 1))))

and here's for Lists' Functions:

http://docs.textadventures.co.uk/quest/guides/using_lists.html

also, you can take a look at this, though it's a bit advance (and has some mess ups --- I was learning how to use Lists and Dictionaries with this coding myself, hehe), but you can at least use it to see how you can use Lists and Dictionaries together and how its syntax is done (I think I've done it as a single line instead of using multiple lines, so I made it harder on myself, meh):

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk

and if you want to take a look at my own guide on using Lists/Dictionaries (if you don't already know of it):

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk


hegemonkhan

oops... my bad... I forgot that if you use numbers for your Dictionaries' keys/strings (to mimic a List's use of index numbers), then you don't need a String List Attribute.

so, this would work fine/perfectly (you had it nearly right, aside from the issue with 'this' not working and a few small details), if your Dictionary uses numbers for its keys/strings, an example for you:

<object name="example_object">
  <attr name="example_scriptdictionary" type="scriptdictionary">
    <item key="1">
      msg ("blah1")
    </item>
    <item key="2">
      msg ("blah2")
    </item>
    <item key="3">
      msg ("blah1")
    </item>
  </attr>
</object>

// scripting:

n = ToString (GetRandomInt(1, DictionaryCount (example_object.example_scriptdictionary)))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

// if you want as single code line:

// invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, ToString (GetRandomInt (1, DictionaryCount (example_object.example_scriptdictionary)))))

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

or (see how it differs, look at the above and the below, based on what numbers you use for the Dictionary's key/string)

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

<object name="example_object">
  <attr name="example_scriptdictionary" type="scriptdictionary">
    <item key="0">
      msg ("blah1")
    </item>
    <item key="1">
      msg ("blah2")
    </item>
    <item key="2">
      msg ("blah1")
    </item>
  </attr>
</object>

// scripting:

n = ToString (GetRandomInt(0, DictionaryCount (example_object.example_scriptdictionary) - 1))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

// if you want as single code line:

// invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, ToString (GetRandomInt(0, DictionaryCount (example_object.example_scriptdictionary) - 1))))

P.S.

hopefully this is obvious, but the numbers used MUST be contigious (the order of the items' numbers don't matter, but you must be able to take all of the numbers and be able to count from the lowest to the highest: contigious-ness)

for example:

(oops, just realized, this was missing something in order for it to work, laughs. See if you can notice it, I'll have the corrected version further below)

works fine:

<object name="example_object">
  <attr name="example_scriptdictionary" type="scriptdictionary">
    <item key="10">
      msg ("blah1")
    </item>
    <item key="8">
      msg ("blah2")
    </item>
    <item key="9">
      msg ("blah1")
    </item>
  </attr>
</object>

n = ToString (GetRandomInt(8, DictionaryCount (example_object.example_scriptdictionary)))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

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

does NOT work:

<object name="example_object">
  <attr name="example_scriptdictionary" type="scriptdictionary">
    <item key="11">
      msg ("blah1")
    </item>
    <item key="8">
      msg ("blah2")
    </item>
    <item key="9">
      msg ("blah1")
    </item>
  </attr>
</object>

n = ToString (GetRandomInt(8, DictionaryCount (example_object.example_scriptdictionary)))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

corrected version:

it's simpliest to use numbers: 1...N, for you Dictionary item's keys/strings, as no need for a 'DictionaryCount(x) -1' (0...N) or 'Dictionarycount(x) - 1 + N' (N...M)

but my example shows if you want to start with a number over/greater-than 1, just so you can see it works (and how if done non-contigiously, does NOT work), but these examples would work for starting with '0' or '1' and adjusted as needed, too.

works fine:

<object name="example_object">
  <attr name="example_scriptdictionary" type="scriptdictionary">
    <item key="10">
      msg ("blah1")
    </item>
    <item key="8">
      msg ("blah2")
    </item>
    <item key="9">
      msg ("blah1")
    </item>
  </attr>
</object>

n = ToString (GetRandomInt(8, DictionaryCount (example_object.example_scriptdictionary) + 7))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

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

does NOT work:

<object name="example_object">
  <attr name="example_scriptdictionary" type="scriptdictionary">
    <item key="11">
      msg ("blah1")
    </item>
    <item key="8">
      msg ("blah2")
    </item>
    <item key="9">
      msg ("blah1")
    </item>
  </attr>
</object>

n = ToString (GetRandomInt(8, DictionaryCount (example_object.example_scriptdictionary) + 7))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

or, also doesn't work:

n = ToString (GetRandomInt(8, DictionaryCount (example_object.example_scriptdictionary) + 8))
invoke (ScriptDictionaryItem (example_object.example_scriptdictionary, n))

scrimshaw04

Wait, I'm confused. Sorry for being dense but I've read your explanation a few times and I still don't understand.

First to clarify. When you refer to parameters and arguments, you mean 'Parameter (Argument)' correct?

So you're saying that you're not sure if I use

do (ScriptDictionaryItem (this.script_library, n))

If I could use a second parameter/argument within the brackets of the first parameter? I think that's fine, because that's not what I'm trying to do.

Also from what I understand I can't reference object.attributes within a script inside a script library unless I use do (including this.attribute).

Unfortunately, when I change 'invoke' to 'do', I get an error saying that the script expected 2 or 3 parameters. I'm not sure why, as far as I can tell the above syntax should be correct.

Also DictionaryCount is exactly what I was looking for, so thank you!


hegemonkhan

no ignorance on your part, I throw a lot of terms at you, and often not with clarity and/or incorrectly, and they're confusing, even without me making them even more confusing because I'm not being precise/clear with them and/or not explaining them.


// this is a bit more technical, deeper into the 'programming weeds' (general programming / non-quest programming):

in programming languages, you can or need-to (depends on your program code structure, using multiple files/libraries and thus linker, and compiler) have 'PROTOTYPES', which tell the compiler and human the Function's HEADER/SIGNATURE ahead of time, pretend example using quest:

// function PROTOTYPE:

// (actually/technically, the names of the options' variables' names don't matter, they do NOT have to match up with the DEFINITION's HEADER/SIGNATURE options' variables' names, but the types and options and the name of the function, do, of course)

<function name="two_string_concatenation_function" parameters="parameter_variable_1, parameter_variable_2" type="string" etc less or more options />

but quest doesn't require or have Prototypes for Functions


however... if you want to use Objects and Script Attributes, quest has 'Delegates', which allow for you to have Arguments/Parameters and return type for your Object's Script Attributes (as normally you can't as Script Attributes don't have Arguments/Parameters and return type). Quest's 'Delegates' are literally the same thing as 'Prototypes' except they're for an Object's Script Attribute, if you want to see a guide on using Delegates (though it's a bit advanced/confusing if you're new to coding --- it actually took me quite a while and only recently to finally understand them myself, lol):

http://docs.textadventures.co.uk/quest/types/using_delegates.html


'Parameters' are the names of special VARIABLES specified and used by a Function's (and Commands and maybe some other stuff too) scripting in its definition (specified within the header/signature and used in the body):

// function DEFINITION (its creation: what it does, how it does it, inputs/Parameters, output:return type, etc etc etc):

<function name="two_string_concatenation_function" parameters="parameter_variable_1, parameter_variable_2" type="string" etc less or more options> // function HEADER/SIGNATURE code line, and beginning function block tag
  // function BODY (contents/scripting):
  return (parameter_variable_1 + parameter_variable_2)
</function> // ending function block tag

the 'Arguments' are the position/slot matching inputs in the function's 'call' (the actual using/doing/activating/executing/invoking/calling of the function) code line / scripting:

x = two_string_concatenation_function ("mama","mia")
msg (x)
// output: mamamia

so '"mama" is Argument position/slot 1 which matches up with the function's DEFINITION's HEADER/SIGNATURE 's Parameter position/slot 1, essentially this is what is going on:

parameter_variable_1 = "mama"

and "mia" is Argument position/slot 2 which matches up with the function's DEFINITION's HEADER/SIGNATURE 's Parameter position/slot 2, essentially this is what is going on:

parameter_variable_2 = "mia"


So the Function call's 'Arguments' are the inputs (either as VARIABLES or LITERALS: direct values) for the Function, which are stored/saved/set to/into the corresponding Parameters' variables, and then which those Parameters' variables are used by the Function's scripting.


VARIABLE usage for Arguments:

Variable VARIABLE:

a = "mama"
b = "mia"

x = two_string_concatenation_function (a,b)
msg (x)
// output: mamamia

Attribute VARIABLE:

game.a = "mama"
game.b = "mia"

x = two_string_concatenation_function (game.a, game.b)
msg (x)
// output: mamamia

LITERALS (direct values) usage for Arguments:

x = two_string_concatenation_function ("mama", "mia")
msg (x)
// output: mamamia


does this help clear up the terms (and their concepts and concepts), or did I just confuse you more?


hegemonkhan

"
Unfortunately, when I change 'invoke' to 'do', I get an error saying that the script expected 2 or 3 parameters. I'm not sure why, as far as I can tell the above syntax should be correct
(scrim)
"


this is because, let's look at 'do' Function's DEFINITION / syntax:

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

// no more than 2 Parameters/inputs:
do (object, string attribute name)

// more than 2 Parameters/inputs (this is an example of me being confused, but I think this means you can give it Parameters, but normally Script Attributes don't/can't use Parameters.... so this would mean you'd have to create a Delegate for this Script Attribute, or indeed I'm not understanding the documentation... see, I'm confused by it myself, laughs):

do (object, string attribute name, dictionary parameters)

compared to what you did:

do (ScriptDictionaryItem (this.script_library, n))

you have only a single input, 'ScriptDictionaryItem (this.script_library, n)', in/for you 'do' Function, but it requires at least 2 inputs (OBJECT/NAME_OF_OBJECT, NAME_OF_SCRIPT_ATTRIBUTE)

hence the error


'do' is more confusing than 'invoke' when you want to use 'ScriptDictionaryItem'

I think... it'd be like this (and you can't use 'this'):

do (NAME_OF_OBJECT, "script_library", ScriptDictionaryItem (NAME_OF_OBJECT.script_library, n))

err... actually... maybe you can NOT use 'do' at all with 'ScriptDictionaryitem'....

I think if you're using 'ScriptDictionaryItem' you got to use 'invoke'...

sorry, this is confusing for me too... I don't really understand this stuff that well myself.

err... again.... I think this might work....

do (NAME_OF_OBJECT, "script_library", n)

I'm trying to understand/learn this along with you, as I try to help you, laughs.


'invoke' is more simple:

http://docs.textadventures.co.uk/quest/scripts/invoke.html

invoke (script)

you can see that it's Argument/input is literally a Script Value, so that's why the 'ScriptDictionaryItem' Function works, as it returns a Script Value

so, 'invoke (ScriptDictionaryItem (this.script_library, n))', works / works fine / no errors

also, another example of using a built-in Script Attribute (though you got to change the 'description' to being a Script Attribute from its default of a String Attribute when using the GUI/Editor, and of course give it contents/scripts):

invoke (room.description)

and this is I think again for if you have a Script that can take Arguments/Parameters/Inputs (which would mean you'd have to create a Delegate for it, if I'm understanding this stuff correctly, lol):

invoke (script, dictionary parameters)


but, 'do' requires a different and confusing-to-get-it-right syntax (and more arguments/parameters/inputs)

actually... now I think I'm understanding it:

you can NOT use 'do' and 'ScriptDictionaryitem', as none of the required inputs/parameters/arguments of 'do' is that of a Script Value, and the 'ScriptDictionaryItem' Function returns a Script Value, hence the error / incompatibility of them used together.


so...

// for what you're doing:
// n = SOME_STRING
// that 'SOME_STRING' must be a key/string of/for/within one of your Script Dictionary Attribute's items' keys, hopefully obviously
// and since you're using the 'GetRandomInt', you need your script dictionary's items' keys' strings to be contigious numbers (easiest is using: 1...N)

I think these are the same thing, and hopefully will both work:

invoke (ScriptDictionaryItem (NAME_OF_OBJECT.NAME_OF_SCRIPT_DICTIONARY_ATTRIBUTE, n)

or

do (NAME_OF_OBJECT, "NAME_OF_SCRIPT_DICTIONARY_ATTRIBUTE", n)


hegemonkhan

by using 'do', you can work with varying ("dynamic") Objects (though I don't know fully your design), so here's an example:

object_variable = ObjectListItem (game.my_objectlist, GetRandomInt (0, ListCount (game.my_objectlist) - 1))
do (object_variable, "NAME_OF_SCRIPT_DICTIONARY_ATTRIBUTE", n)
// if the above 'do' code line doesn't work, then try this (I always get confused on whether and/or when you need the '.name' or not, lol):
// do (object_variable.name, "NAME_OF_SCRIPT_DICTIONARY_ATTRIBUTE", n)

this would require that each of your Objects have the same named Script Dictionary Attribute, and as can be seen, you'll have to create an Object List Attribute, so you can randomly select one of your Objects and thus do its Script Dictionary

but this is my example design, as I don't know what yours is fully.


I think Jay (Jaynabonne) has some really clever/ingenious ways to do what you want possibly involving using a Script Dictionary with/within a Script Dictionary... I still need to go back and try to understand it myself... (I don't even know if I favorited the page/post... argh, or if I did... were that favorited link is... lol)

so, you might want to try to get his help on this stuff... (and he's, and Pixie and everyone lol is, much more clear and better at explaining stuff and knowledgeable)


hegemonkhan

just to recap or explain/clarify further with Arguments/Parameters:

function_call_:_name_of_function (argument_position_1_:_input_1, argument_2_position_2_:_input_2, etc etc etc less or more arguments --- must match up with parameters)

parameter_variable_1_position_1 = argument_1_position_1_:_input_1
parameter_variable_2_position_2 = argument_2_position_2_:_input_2
etc etc etc parameter = etc etc etc argument

<function name="blah" parameters="parameter_variable_1_position_1;parameter_variable_2_position_2, etc etc etc less or more parameter --- must match up with arguments">
   // scripting which uses your parameters' variables
</function>

we can even transfer our inputs to more functions (basically Arguments/Parameters are ways of transfering inputs into functions, including from one function to another):

// 'P' for parameter
// 'F' for function
// 'AI' for argument/input

<function name="F1" parameters="P1_F1, P2_F1">
  msg ("F1: " + P1_F1 + " " + P2_F1)
  F2 (P1_F1, P2_F1)
</function>

<function name="F2" parameters="P1_F2, P2_F2">
  msg ("F2: " + P1_F2 + " " + P2_F2)
  F3 (P1_F2, P2_F2)
</function>

<function name="F3" parameters="P1_F3, P2_F3">
  msg ("F3: " + P1_F3 + " " + P2_F3) 
</function>

AI_1 = "mama"
AI_2 = "mia"
F1 (AI_1, AI_2)

// output:

F1: mama mia
F2: mama mia
F3: mama mia

so, we can change the names of the parameters' variables' names between function, it doesn't matter, as it's the positions that are used to match them up.

or, we can leave the names of the parameters' variables' names between functions the same too (whichever is best for you or the design/situation, or preferred by you):

<function name="F1" parameters="P1, P2">
  msg ("F1: " + P1 + " " + P2)
  F2 (P1, P2)
</function>

<function name="F2" parameters="P1, P2">
  msg ("F2: " + P1 + " " + P2)
  F3 (P1, P2)
</function>

<function name="F3" parameters="P1, P2">
  msg ("F3: " + P1 + " " + P2) 
</function>

AI_1 = "mama"
AI_2 = "mia"
F1 (AI_1, AI_2)

// output:

F1: mama mia
F2: mama mia
F3: mama mia

The Pixie

Getting the number of items is easy, use DictionaryCount. However, if you count from zero, you need to go up to the count minus 1.

If I was doing this, I would create a new type, and add the scripts to that, rather than to a script dictionary. Make your objects of that type, and they will get all those scripts, and if you use do to invoke the scripts, you can use this inside them. The names of the scripts can then be stored in a string list, and randomly selected from there.

If you are dead set on using a script dictionary, use script0, script1, etc. as the keys. When you want to run a script, first assign it to an object.

n = ToString (GetRandomInt(0, DictionaryCount(game.scripts) - 1)
myobject.scripttorun = ScriptDictionaryItem(game.scripts, "" + n)
do(myobject, "scripttorun")

hegemonkhan

@ pixie:

do you know if the Script Dictionary can be given/take Parameters (be able to work dynamically) ???

or, is there another/more (as you just gave one ingenious method design in your post, awesome!) alternative/cleaver methods/designs of being able to work dynamically (needing various Parameters/inputs) with a Script Dictionary ???

or, is there jsut no way with the Script dictionary to work dynamically with it?


P.S.

I think maybe somehow you can with having a Script dictionary be nested in a Script Dictionary or something like that (a script dictionary having script dictionary items or whatever meh), Jay was trying to show/explain it to me, but at the time it was over my head and probably still is over my head meh... if I could fine the post/thread... again...


The Pixie

I have never used a script dictionary, but I see no reason why a script in one would not take parametetrs when used with invoke. I cannot imagine why Quest would care.


Jay Nabonne

Both "do" and "invoke" have variants that take a dictionary of parameters. "this" is just a default parameter added in by "do". So to use "invoke" and have it look like a "do", create a parameter dictionary and add a "this" parameter. Or call it "object" or "target" or whatever you want. :) If you're not using "do", then you're not limited to just calling it "this".

      parameters = NewDictionary()
      dictionary add (parameters, "this", some_object_i_care_about)
      dictionary add(parameters, "param1", some_param_i_want_to_pass_in)
      invoke (ScriptDictionaryItem(script_dictionary, which), parameters)

Whatever parameters you add will be available in the script by those names.


TinFoilMkIV

Alternatively you can transfer the dictionary script onto the object in question by creating a script attribute to act as the local storage, then run it from the object itself so all local references work correctly
ie:

//in the object
this.script = ScriptDictionaryItem (storage.dictionary, "script1")
do (this, "script")


scrimshaw04

Thanks for your help everyone! Clearly I have a lot more to learn, but the system I have seems to be working perfectly now.

I have one last syntax-related question. The keys I've been using for my dictionary are "1, 2, 3, etc...". This is fine so far because I'm still in the early stages, and none of the dictionaries have a large number of scripts yet. However using a script similar to this...

n = ToString (GetRandomInt(0, DictionaryCount(game.scripts) - 1)
myobject.scripttorun = ScriptDictionaryItem(game.scripts, "" + n)
do(myobject, "scripttorun")

What would happen if the number of items in my dictionary was to exceed 10? Because the keys are actually strings, I'm not sure how quest interprets them. 0-9 should be fine because they're single digits, but 10 might break it because it contains more than one character. Is there a better naming convention I could use for my keys?


TinFoilMkIV

I'm not entirely sure where you're seeing the potential problem with double digits in your script, the way you have it setup should be fine as long as the keys within the dictionary contain all the correct integers, ie: not accidentally skipping a number or such.

Also due to the fact that 'n' is a string variable you shouldn't need the "" + n' and should be able to just use 'n' in the key section of your ScriptDictionaryItem.

Actually when looking that over you could actually store 'n' as an integer and keep the dictionary call the same since you can do 'string = "" + 'integer' to add a non-string value into a string.

So in other words whichever way is easier to keep track of for you, right now you doubled up on converting your dictionary count into a string, which won't actually hurt but isn't necessary.


hegemonkhan

With programming/coding, the Attribute/Value/Data Types are very important (mis-matching these usually causes an error: 4 + "4" = ERROR!, "4" + 4 = ERROR!, "4" + "4" = "44", 4 + 4 = 8). This means that you could be using the converting Functions a lot in your scriptings.


A String (aka-also: text) is just a collection of characters/symbols/letters/numbers (but some symbols might not be allowed):

(the names of anything can NOT start with a number and probably most symbols too, so to be safe, start with a letter)

(also note that quest's strings ARE case sensitive: "a" is NOT equal to "A", and vice versa: "A" is NOT equal to "a" --- http://www.asciitable.com/ )

(there's many string manipulation functions, such as converting a string to all upper case letters, and many more: http://docs.textadventures.co.uk/quest/functions/ -- scroll down to the very bottom to the 'string functions' )

(having double quotes encasing something tells quest that what is within the double quotes, is to be seen/recognized/identified as a string value by quest)

(though the GUI/Editor sometimes handle this for you, so you don't need the double quotes: [MESSAGE] script option for example, but if you do anything directly in code or use the GUI/Editor's [EXPRESSION] script option, then you need to put in the double quotes yourself for your strings)

"0"
"1"
"9"
"10"
"312897312731286984"
"a"
"abc"
"abc_abc_abc_zzz_zzz_zzz_9877654231_32686326"

"hi, how are you? my name is hk, what is your name? ah, bob, well, nice to meet you bob. do you play any sports? yes? what sports? ah basketball, that's cool. I like soccer. blah blah blah blah blah"


if you want double quotes to be displayed, you need to use the 'escape' character, the '\' --- backslash character, remember that two forwardslash characters is for comments: // your_comments, and also for block comments you do this: /* your_comments */, and then the double quote (no space between them --- the escape character is on the left side of the symbol: double quote --- there might be a few more symbols or whatever to use with the escape character, but I've just used the double quote for it): \"

for example:

string_variable = "HK says, \"hi\", to you."
msg (string_variable)
// output:
HK says, "hi", to you.

Quest can convert any string (that is just numbers) into an integer or double (that is a valid syntax/form/written decimal number):

http://docs.textadventures.co.uk/quest/functions/toint.html
http://docs.textadventures.co.uk/quest/functions/todouble.html

string_variable = "123456789"
integer_variable = ToInt (string_variable)
// integer_variable = 123456789

string_variable = "12345.6789"
double_variable = ToDouble (string_variable)
// double_variable = 12345.6789

and it can do the reverse (integer/double to string) too:

integer_variable = 123456789
string_variable = ToString (integer_variable)
// string_variable = "123456789"

double_variable = 12345.6789
string_variable = ToString (double_variable)
// string_variable = "12345.6789"


you can also check first if the string is 'numeric' (it is either an integer:true or double:true or neither:false):

string_variable = "123"
boolean_variable = IsNumeric (string_variable)
// boolean_variable = true

string_variable = "12.3"
boolean_variable = IsNumeric (string_variable)
// boolean_variable = true

string_variable = "abc"
boolean_variable = IsNumeric (string_variable)
// boolean_variable = false

and you can check if a string is an integer: IsInt

and you can check if a string is a double: IsDouble


also you can check if the Object has an Attribute:

(they return true/false like the 'IsXXX' Functions)

HasAttribute
HasString
HasInt
HasDouble
HasBoolean
HasObject
HasScript

lastly, you can check the Object both has an Attribute and the Value of it:

(returns the Object's Attribute's Value or 'null' if it fails: the Object doesn't have that Attribute or if using it with 'if' string matching/comparison, the Object's Attribute's Value doesn't match with your specified Value)

GetAttribute
GetString
GetInt
GetDouble
GetObject
GetScript
GetBoolean


Log in to post a reply.

Support

Forums