Ryan, I made some changes to your code. I'll provide the fixed code below, and a short description of changes I made below.
First, quick note again, please read section 12.2 of the User Manual. It covers all of this, and more. It seems you may have followed the part about nimbleFunctions, but not the part about writing custom distributions with nimbleFunctions.
For custom distributions, the name of the density function needs to begin with "d". I changed yours to "dmyDiscreteDist".
The "run" function needs to be defined using "=", not the assignment operator "<-". You're not actually defining "run" inside the nimbleFunction() function, but rather, you're providing a function object as the argument named "run" to the nimbleFunction() function.
The returnType is a scalar (a probability, or a log-probability). So the returnType() statement has to be "returnType(double(0))", to indicate it's returning a scalar.
For a custom distribution, the first argument to the "run" function *must* be called "x" and in the function, this first "x" argument always assumes the value of the LHS (lefthand side) of the stochastic declaration using the custom distribution. (here, the value of "covs[i,j,k]") So I added this first argument "x", and changed the other arguments (and your loop indices int eh model code) to i, j, k.
In your model code, the probabilityArray being passed into the distribution requires full indexing. In model declarations you (almost) always need to provide full indexing on array variables. So, with full indexing on the array, it needs to look more like:
covs[i,j,k] ~ myDiscreteDist(i, j, k, probabilityArray[1:101, 1:1000, 1:5, 1:5])
In practice, the values 101, 1000, 5, and 5 would be better represented as things like "nsites", "ncovariates", and "nyears", but I don't know which is which, so for the indexing, I used the numbers 101, 1000, 5, and 5.
(side note: without a full model code, etc, I can't actually build / test your model, so some things may not be exactly right).
You can't use "as.character", "rownames", or "match" in the (compilable part of) a nimbleFunction). So those need to go, and there's no sense in adding rownames to probArray.
You can, however, use the "which" function inside the run function, which I think will help accomplish what you want.
You also need to add the (necessary) "log" argument. This dictates whether it returns the probability, or the log-probability. I've added this.
The arguments to the "run" function need type declarations, telling what (scalar/vector/array) type they are. I added those, as what seems correct.
See changes in the code below, as well as a placeholder for you to "add logic here", which again, should use "x", "probabilityArray", and also the which() function will be handy.
Keep in touch, let me know what doesn't make sense, and take a look at section 12.2 of the manual.
Cheers,
Daniel
#My original priors.....
for(i in 1:nsites){
for(j in 1:ncovariates){
for(k in 1:nyears) {
####covs[x, y, z] ~ dbeta(shp1[x, y, z], shp2[x, y, z])