Multidimensional array issue
Sean Cole (Pi)
sean at pidigital.co.uk
Wed Mar 10 20:10:31 EST 2021
In the message box:
> put "data" into tArray["key1"]["key2"]; answer the value of tArray["key1”]
> - returns EMPTY (so this works)
Correct
put "data" into tArray["key1"]["key2"]; answer tArray["key1”] is empty -
> returns FALSE (it should return true IMHO)
Because it is not empty. It has a nested array in it. If it where empty
(TRUE) then it would be void of all data of all types.
put "data" into tArray["key1"]["key2"]; answer tArray["key1”] is an array -
> returns TRUE (so not helpful)
tArray is an array;
tArray["key1"] is an array (because it has ["key2"] within;
tArray["key1"]["key2"] is not an array (unless you put an array into it)
To make this clearer:
put "hello" into tArray -- tArray is not an array
put tArray; // returns "hello"
tArray contains a value = true
tArray is empty = false -- it contains a value
tArray["key1"] is empty = true -- it does not exist
tArray["key1"]["key2"] is empty = true -- it does not exist
put "hello" into tArray["key1"] -- tArray is an array ; tArray["key1"]
is not an array
put tArray; // returns empty
put tArray["key1"]; // returns "hello"
tArray contains a value = false
tArray["key1"] contains a value = true
tArray is empty = false -- it contains an array
tArray["key1"] is empty = false -- it contains a value
tArray["key1"]["key2"] is empty = true -- it does not exist
put "hello" into tArray["key1"]["key2"] -- ttArray is an array
; tArray["key1"] is an array ; tArray["key1"]["key2"] is not an array
put tArray; // returns empty
put tArray["key1"]; // returns empty
put tArray["key1"]["key2"]; // returns "hello"
tArray contains a value = false
tArray["key1"] contains a value = false
tArray["key1"]["key2"] contains a value = true
tArray is empty = false -- it contains an array
tArray["key1"] is empty = false -- it contains an array
tArray["key1"]["key2"] is empty = false -- it contains a value
put "hello" into tArray -- tArray is not an array; it has been reset to
a value nullifying it's array status and values
put tArray; // returns "hello"
tArray contains a value = true
tArray is empty = false -- it contains a value
tArray["key1"] is empty = true -- it does not exist
tArray["key1"]["key2"] is empty = true -- it does not exist
put "hello" into tArray
put "hello" into tArray["key2"]
put tArray into tArray["key1"]
tArray =
["key1"] > ["key2"] > "hello"
["key2"] > "hello"
That just about covers it. Unless I go into super sub arrays to really blow
your mind (tArray["key1","key1.1"]["key2","key2.1"])
Sean
More information about the use-livecode
mailing list