Data Tables

Dear all,
how do I create and access a data table in TADS? As an example, I want to have a list of topics (strings) and for each topic I want to keep track of if it’s been dealt with or not (int or bool). Example:
list of topics(
“health”: 0,
“job”: 0,
“vacation”: 0,
)
Now I have a string (a topic) and I want to check if the string is in the table and if yes, if the “dealt with” variable is 0 or 1. And of course I want to be able to change the “dealt with” variable. How do I do that?
Thanks and kind regards,
Grues

1 Like

Sounds like you may want to use a LookupTable, for which see LookupTable (tads.org).

4 Likes

That looks exactly like what I need. Thanks Eric!

1 Like

Okay one more question: How do I access the “dealt with” value? if(topics[‘job’]==1) compiles but causes a run-time error “invalid index operation - this type of value cannot be indexed”.

1 Like

Your if statement is correct. The problem must be in the topics table. Here is one way to set up the data. There is no need to create an object to store the data it’s just the method I put together. If the table isn’t local make sure to reference its location.

topic_data: object 
//shortcut to create and initialize a LookupTable
topics = ['health' -> 0, 'job' -> 0,'vacation' -> 0] 
;
...
if(topic_data.topics['job']==1) {
    "Job = 1"; 
}
else {
    "Job = 0"; 
}

Did any of this help?

4 Likes

Worked, thanks!!!

(My mistake was my misunderstanding of basic TADS concepts - I simply threw the table definition into the start of the code instead of sticking it into an object.)

1 Like

exact, grueslayer.
It’s an interesting concept, because one can write “storage container” object.
For example, for ease of editing and navigating the source files, I have put all “wall of text” in a separate file, whose contain one object, called lngtxt (long text) and inside are multiple text strings, called inside the room source with a simple line, e.g.
readDesc = {lngtxt.walltxt;}

same convenience, of course, can be applied to your tables…

Best regards from Italy,
dott. Piergiorgio.