DEdit – Database Editor

Documentation version 1.0 , 2009-12-19


Command examples

Manipulating array variables: $Dim{}, $AddItem{}, $DeleteItem{}, $IsElement{}, $ItemPos{}, $SortItem{}, $ForEach{}, $Swap{}

Array variables can be seen as lists of variables. There is a separate tutorial explaining how to generally used arrays. This tutorial
shows some advanced techniques to manipulate arrays. Let us first demonstrate how to change the size of arrays, by building a

totally random singing game:

Example 1:

SCRIPT

PREVIEW-RESULT

$NewVar{dore,string,7,[< do>,< re>,< mi>, < fa>, < so>,< la>, < di>]}

$NewVar{verse,string}

$NewVar{count,integer}

10 children sit around the table and play a singing game. They sing a line each going clockwise.

The first child sings: 'Can you sing, can you sing, then sing$Var{dore}!'

$ForEach{count,[1..10],

<$AddItem{verse,<$Var{dore[$Random{1,7}]}>}

'$Var{verse}'

>}

10 children sit around the table and play a singing game. They sing a line each going clockwise.

The first child sings: 'Can you sing, can you sing, then sing do,  re,  mi,  fa,  so,  la,  di!'

'so'

'so, fa'

'so, fa, la'

'so, fa, la, la'

'so, fa, la, la, so'

'so, fa, la, la, so, do'

'so, fa, la, la, so, do, la'

'so, fa, la, la, so, do, la, fa'

'so, fa, la, la, so, do, la, fa, fa'

'so, fa, la, la, so, do, la, fa, fa, do'

 

In this example we’ve used the $AddItem{variableArray, value} command to append a new syllable at the end of the list with each line.

We have use the $ForEach{} command (see tutorial) to iterate 10 times.

Now let us reverse the game by removing syllables.

 

Example 2:

SCRIPT

PREVIEW-RESULT

$NewVar{dore,string,7,[< do>,< re>,< mi>, < fa>, < so>,< la>, < di>]}

$NewVar{verse,string}

$NewVar{count,integer}

10 children sit around the table and play a singing game. They sing a line each going clockwise.

The first child sings: 'Can you sing, can you sing, then sing$Var{dore}!'

$ForEach{count,[1..10],

<$AddItem{verse,<$Var{dore[$Random{1,7}]}>}

'$Var{verse}'

>}$ForEach{count,[1..7],

< ' $Var{verse} - now remove the$Var{dore[count]}!'

$DeleteItem{verse,$Var{dore[count]}}

>}

After this, the game ends and all laugh.

10 children sit around the table and play a singing game. They sing a line each going clockwise.

The first child sings: 'Can you sing, can you sing, then sing do,  re,  mi,  fa,  so,  la,  di!'

'di'

'di, la'

'di, la, la'

'di, la, la, re'

'di, la, la, re, fa'

'di, la, la, re, fa, la'

'di, la, la, re, fa, la, fa'

'di, la, la, re, fa, la, fa, di'

'di, la, la, re, fa, la, fa, di, do'

'di, la, la, re, fa, la, fa, di, do, do'

' di, la, la, re, fa, la, fa, di, do, do - now remove the do!'

' di, la, la, re, fa, la, fa, di - now remove the re!'

' di, la, la, fa, la, fa, di - now remove the mi!'

' di, la, la, fa, la, fa, di - now remove the fa!'

' di, la, la, la, di - now remove the so!'

' di, la, la, la, di - now remove the la!'

' di, di - now remove the di!'

 

After this, the game ends and all laugh.

 

As you can see the $DeleteItem{variableArray, value} command remove all occurrences of the given value from the array.
There is also a possibility to remove all duplicate values from an array. Let us use this to create another game:

 

Example 3:

SCRIPT

PREVIEW-RESULT

$NewVar{num,integer}

$NewVar{count,integer}

Two mages play a game of memory. The first one explain the rules:

'It is simple. I will quickly tell you several numbers, and afterwards you give me a complete list of the numbers I've told you, but to make it harder, you must never say a number twice whereas I might! Okay?'

'Okay. You can begin'

$ForEach{count,[1..20],<$AddItem{num,<$Random{1,9}>}>}

The first mage very quickly says: '$Var{num}'

$DeleteItem{num,duplicate}

Without hesitation, the other mage says: '$Var{num}'

Two mages play a game of memory. The first one explain the rules:

'It is simple. I will quickly tell you several numbers, and afterwards you give me a complete list of the numbers I've told you, but to make it harder, you must never say a number twice whereas I might! Okay?'

'Okay. You can begin'

The first mage very quickly says: '0, 3, 1, 8, 8, 7, 6, 8, 8, 4, 7, 6, 3, 2, 4, 6, 6, 3, 2, 9, 3'

Without hesitation, the other mage says: '0, 3, 1, 8, 7, 6, 4, 2, 9'

 

We can make the output a little nicer by sorting the numbers using the $SortItem{} command:

 

Example 4:

SCRIPT

PREVIEW-RESULT

$NewVar{num,integer}

$NewVar{count,integer}

Two mages play a game of memory. The frist one explain the rules:

'It is simple. I will quickly tell you several numbers, and afterwards you give me a complete list of the numbers I've told you, but to make it harder, you must never say a number twice whereas I might! And you must list the numbers in descending order. Okay?'

'Okay. You can begin'

$ForEach{count,[1..20],<$AddItem{num,<$Random{1,9}>}>}

The first mage very quickly says: '$Var{num}'

$DeleteItem{num,duplicate}

$SortItem{num,invers}

Without hesitation, the other mage says: '$Var{num}'

Two mages play a game of memory. The frist one explain the rules:

'It is simple. I will quickly tell you several numbers, and afterwards you give me a complete list of the numbers I've told you, but to make it harder, you must never say a number twice whereas I might! And you must list the numbers in descending order. Okay?'

'Okay. You can begin'

The first mage very quickly says: '0, 9, 5, 4, 3, 5, 2, 7, 1, 6, 4, 2, 2, 4, 1, 7, 3, 9, 9, 2, 6'

Without hesitation, the other mage says: '9, 7, 6, 5, 4, 3, 2, 1, 0'

 

We could have used the $SortItem{} command without the optional parameter invers for ascending order. The command can also
sort strings alphabetically. After a while, our two wizards decide on another game to demonstrate us the $IsElement{} command:

 

Example 5:

SCRIPT

PREVIEW-RESULT

$NewVar{num,integer}

$NewVar{count,integer}

'Okay, this time I tell you even more numbers between 1 and 100, and then I ask you if a particular number was named. Okay?'

'No problem at all.'

$ForEach{count,[1..50],<$AddItem{num,<$Random{1,99}>}>}

'Pah, we will see. I say:

$Var{num} - Now what about $SetVar{count,$Random{1,99}}$Var{count}?'

Again without hesitation the other mage replies:

'$If{$IsElement{count,num},<Yes it was there.>,<No, it was not there.>}'

'Okay, this time I tell you even more numbers between 1 and 100, and then I ask you if a particular number was named. Okay?'

'No problem at all.'

'Pah, we will see. I say:

0, 87, 81, 60, 62, 7, 62, 74, 69, 47, 42, 26, 57, 9, 46, 6, 13, 20, 70, 70, 23, 51, 39, 7, 78, 64, 28, 89, 84, 20, 40, 77, 42, 45, 85, 73, 35, 74, 41, 49, 27, 25, 46, 95, 58, 54, 59, 51, 51, 43, 97 - Now what about 98?'

Again without hesitation the other mage replies:

'No, it was not there.'

 

We could use the $IsElement{} command also for string arrays. By default, this comparison will be case-insensitive, but one can
use the optional parameters case to make it case-sensitive. It should also be pointed out, that the command allows the search for more
than one element. If the first parameter is an array by itself, the command returns true only if all those elements are a subset of the
other array.

Our clever mages have decided to make the game even more difficult to demonstrate us the $ItemPos{} command:

 

Example 6:

SCRIPT

PREVIEW-RESULT

$NewVar{num,integer}

$NewVar{pos,integer}

$NewVar{count,integer}

'Okay, this time I tell you even more numbers between 1 and 100, and then I ask you if a particular number was named. Okay?'

'That is too easy, but go ahead. I will even say you the number before it, if it was named!'

$ForEach{count,[1..50],<$AddItem{num,<$Random{1,99}>}>}

'Pah, we will see. I say:

$Var{num} - Now what about $SetVar{count,$Random{1,99}}$Var{count}?'

Again without hesitation

'$If{$IsElement{count,num},

<Yes it was there, at position: $ItemPos{num,count}

Right after $Var{num[$Sum{$ItemPos{num,count},-1}]} and before $Var{num[$Sum{$ItemPos{num,count},1}]} >,

<No, it was not there.>}'

'Okay, this time I tell you even more numbers between 1 and 100, and then I ask you if a particular number was named. Okay?'

'That is too easy, but go ahead. I will even say you the number before it, if it was named!'

'Pah, we will see. I say:

0, 52, 29, 37, 59, 43, 98, 53, 15, 94, 8, 8, 1, 84, 14, 94, 33, 11, 77, 67, 79, 62, 30, 83, 5, 6, 22, 91, 76, 88, 30, 9, 3, 85, 26, 54, 1, 96, 39, 78, 71, 25, 50, 60, 5, 60, 81, 94, 54, 96, 83 - Now what about 59?'

Again without hesitation

'Yes it was there, at position: 5

Right after 37 and before 43 '

 

And a final example demonstrates the use of the $Swap{} command:

 

Example 7:

SCRIPT

PREVIEW-RESULT

$NewVar{num,integer}

$NewVar{count,integer}

'Okay, this time I tell you even more numbers between 1 and 100, and then I ask you if a particular number was named. Okay?'

'No problem at all.'

$ForEach{count,[1..25],<$AddItem{num,<$Random{1,99}>}>}

'The list is:

$Var{num}'

'Now switch the 9th with the 21st number!'

$Swap{num[9],num[21]}

' That is far too easy:

$Var{num}'

'Okay, this time I tell you even more numbers between 1 and 100, and then I ask you if a particular number was named. Okay?'

'No problem at all.'

'The list is:

0, 32, 8, 91, 3, 63, 11, 30, 91, 48, 75, 67, 37, 54, 51, 48, 94, 32, 49, 82, 83, 58, 66, 19, 72, 22'

'Now switch the 9th with the 21st number!'

' That is far too easy:

0, 32, 8, 91, 3, 63, 11, 30, 83, 48, 75, 67, 37, 54, 51, 48, 94, 32, 49, 82, 91, 58, 66, 19, 72, 22'