I'm using Julia, and I tried to test out a function that creates an image and assigns Red values based on the string given. Just from hearing that sentence I'm sure you can think of a million things I could have done to receive an error message, but this error:
was generated at line 13.
Here's line 13:
r = (i + 64*rand(0:3) - 1)/255
That's just math! r is a new variable I'm assigning just there. i is the index of each character in an array. This seems to work in the console, so maybe something weird is happening in the code before and it just isn't being caught. Here's the whole function:
function generate(string, width)
img = rand(RGB,width,floor(Int,length(string)/width) + 1)
for n in 1:length(string)
i = indexin(string[n], alphabet)
r = (i + 64*rand(0:3) - 1)/255
g = img[n].g
b = img[n].b
img[n] = RBG(r,g,b)
end
return img
end
Does anyone know what this error message means, or what I did wrong?

Your
ihere isn't an integer, it's an array.indexinis intended for finding positions of each element of an array in another; to find just one element you probably wantfindfirst:Note also that both of these will give
nothingif they cannot find the letter, which you may want to decide how to handle. (Possibly withif else, you can also use the functionsomething.)Finally, note that indexing a string like this isn't very robust, you may want to iterate it: