Function problem
Jonathan O
03 Nov 2020, 15:47I'm trying to write a function that returns the number of items the player is wearing. This is the code:
x = 0
foreach (o, GetDirectChildren(player)) {
if (GetBoolean(o, "worn")) {
x = x + 1
}
}
return (x)
However, when I try to access it I get an error message saying 'Error running script: Error compiling expression 'NumWorn()': Value cannot be null.Parameter name: key'. What am I doing wrong? It seems that no matter what the player is wearing, the result of the function should be an integer - so why is it being seen as null?
mrangel
04 Nov 2020, 11:17It sounds like in the function definition, you've got a parameter named 'key'. If you don't need to pass a parameter, you could try removing it.
Jonathan O
05 Nov 2020, 09:47No, the parameter list is empty.
I've just realised the problem - I'd forgotten to set the return type to Integer.