Variable scope question

Hi Chris,

I am having trouble with one of my range replicators and I suspect the issue has to do with variable scope. In my trials, I show 22 images, each of which has a trial made by a range replicator iterating along the variable ImageIndex. The problem is, now, I want to remove some images from the image set. In fact, I want to remove almost all of them. I was planning to do this by putting in a statement that says:

if (imageIndex > 11){
imageIndex = 4}

if ImageIndex <= 11{
imageIndex = 12}

So half the time it would show image 12 and half the time image 4, but I don’t lose the meaning of imageIndex = 4, which has always been a picture of an apple or imageIndex = 12 which has always been a picture of a house. The problem is, this simply doesn’t work. I keep on seeing the full gamut of images and I don’t know why.

The alternative way is to modify the range replicator to be in a range of 0 to 1, and remove all images from my folder except for the two I want. This would be OK but it will break my analysis script because my analysis script uses imageIndex to know which image is being shown. This is fixable but makes a mess.

Anyways, let me know if you have any ideas. If you are able to, before 1 oclock today because I’m going to move forward with the annoying version then unless I figure something out now.

Simon

Actually I figured out a workaround, by making a second variable that is not “locked” by the range replicator and having the value from the replicator transferred to it, and then replacing the replicated variable throughout my code. I would still be interested in why the range replicators act this way, but no rush.

Simon

Hi Simon,

I can’t say why your first attempt didn’t work without seeing your code. It might be that, in some places, you’re referring to the variable as $varname or ${varname}, both of which would substituted (textually) at parse time, whereas in other places you’re just using varname, which would be evaluated at run time. Or it could be a question of scope (e.g. you set the local variable inside a block or list, but then refer to it outside of that block/list).

In any case:

by making a second variable that is not “locked” by the range replicator and having the value from the replicator transferred to it, and then replacing the replicated variable throughout my code.

That’s basically what I would have suggested.

Cheers,
Chris