LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Is it possible to return an Array from a custom function? The reason is that I store my multidimensional array in a custom property. And I want to access that array without having to write
on mouseUp
put cArray(2,"Text") into field 1
end mouseUp
function cArray pKey1, pKey2
put the myArray of this stack into pArray
return pArray[pKey1][pKey2]
end cArray
Is it possible to use this to SET an element in an array with a custom command?
Since the "the paramcount" does not work in a custom command how is it possible to find out how many parameters was passed?
The following code does not work but is more of an example of what i want do to:
on mouseup
setMyArray(1,"a new text")
end mouseup
on setMyArray pKey1,pKey2,pKey3
put the storedArray of this stack into tArray
switch the paramcount
case 1
put pKey1 into tArray[element1]
break
case 2
put pKey2 into tArray[element1][element2]
break
case 3
put pKey3 into tArray[element1][element2][element3]
break
end switch
end setMyArray
on mouseup
setMyArray(1,"a new text")
end mouseup
on setMyArray pValue1,pValue2,pValue3
put the storedArray of this stack into tArray
switch the paramcount
case 1
put pValue1 into tArray[key1]
break
case 2
put pValue2 into tArray[key1][key2]
break
case 3
put pValue3 into tArray[key1][key2][key3]
break
end switch
end setMyArray
on setMyArray pKey1,pKey2,pKey3
put the storedArray of this stack into tArray
set itemdel to comma
put the num of items of replaceText(last word of params(),quote,"") into tParams
switch tParams
case 1
put pKey1 into tArray[element1]
break
case 2
put pKey2 into tArray[element1][element2]
break
case 3
put pKey3 into tArray[element1][element2][element3]
break
end switch
end setMyArray
Sjatplat wrote:Since "the Paramcount" only returns 1 in a custom command - which is strange...(correct me if Im wrong)
Paramcount returns the number of parameters that were passed to the command or function. It doesn't reflect the number of parameters the command expects (the ones in the declaration,) only those it actually receives. For example: